Skip to content

Commit

Permalink
1.15.2
Browse files Browse the repository at this point in the history
  • Loading branch information
rosmcmahon committed Sep 29, 2024
1 parent 2645382 commit 0a087f4
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 31 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "arweave",
"version": "1.15.1",
"version": "1.15.2",
"description": "Arweave JS client library",
"main": "./node/index.js",
"react-native": "./node/index.js",
Expand Down
15 changes: 10 additions & 5 deletions src/common/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ export default class Api {
} else if (responseType === "text") {
await decodeText();
} else if (responseType === "webstream") {
response.data = addAsyncIterator(res.body as AsyncIterableReadableStream) as T;
response.data = addAsyncIterator(
res.body as AsyncIterableReadableStream
) as T;
} else {
/** axios defaults to JSON, and then text, we mimic the behaviour */
try {
Expand All @@ -158,12 +160,15 @@ export default class Api {
* [Symbol.AsyncIterator] is needed to use `for-await` on the returned ReadableStream (web stream).
* Feature is available in nodejs, and should be available in browsers eventually.
*/
type AsyncIterableReadableStream =
(ReadableStream<Uint8Array> & AsyncIterable<Uint8Array>)
type AsyncIterableReadableStream = ReadableStream<Uint8Array> &
AsyncIterable<Uint8Array>;
// | ReadableStream<Uint8Array>

const addAsyncIterator = (body: ReadableStream<Uint8Array>): AsyncIterableReadableStream => {
const bodyWithIter = body as ReadableStream<Uint8Array> & AsyncIterable<Uint8Array>;
const addAsyncIterator = (
body: ReadableStream<Uint8Array>
): AsyncIterableReadableStream => {
const bodyWithIter = body as ReadableStream<Uint8Array> &
AsyncIterable<Uint8Array>;
if (typeof bodyWithIter[Symbol.asyncIterator] === "undefined") {
bodyWithIter[Symbol.asyncIterator] = webIiterator<Uint8Array>(body);
}
Expand Down
24 changes: 11 additions & 13 deletions src/common/lib/crypto/node-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,32 @@ export default class NodeCryptoDriver implements CryptoInterface {
const pem = this.jwkToPem(publicJwk); //?
const keyObject = crypto.createPublicKey({
key: pem,
format: 'pem',
})
format: "pem",
});

const verify = crypto.createVerify(this.hashAlgorithm)
verify.update(data)
const verify = crypto.createVerify(this.hashAlgorithm);
verify.update(data);
const verifyResult = verify.verify(
{
key: keyObject,
padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
},
signature,
)
signature
);

if (!verifyResult) {
const details = {
asymmetricKeyType: keyObject.asymmetricKeyType,
modulusLength: keyObject.asymmetricKeyDetails?.modulusLength,
}
};
console.warn(
"Transaction Verification Failed! \n" +
`Details: ${JSON.stringify(details, null, 2)} \n` +
"N.B. ArweaveJS is only guaranteed to verify txs created using ArweaveJS."
)
`Details: ${JSON.stringify(details, null, 2)} \n` +
"N.B. ArweaveJS is only guaranteed to verify txs created using ArweaveJS."
);
}

resolve(
verifyResult
);
resolve(verifyResult);
});
}

Expand Down
19 changes: 11 additions & 8 deletions src/common/lib/crypto/webcrypto-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,12 @@ export default class WebCryptoDriver implements CryptoInterface {

// saltN's salt-length is derived from a formula described here
// https://developer.mozilla.org/en-US/docs/Web/API/RsaPssParams
const saltLengthN = Math.ceil(
((key.algorithm as RsaHashedKeyGenParams).modulusLength - 1) / 8
) - digest.byteLength - 2;
const saltLengthN =
Math.ceil(
((key.algorithm as RsaHashedKeyGenParams).modulusLength - 1) / 8
) -
digest.byteLength -
2;

const saltN = await this.driver.verify(
{
Expand All @@ -128,16 +131,16 @@ export default class WebCryptoDriver implements CryptoInterface {
algorithm: key.algorithm.name,
modulusLength: (key.algorithm as RsaHashedKeyAlgorithm).modulusLength,
keyUsages: key.usages,
saltLengthsAttempted: `0, 32, ${saltLengthN}`
}
saltLengthsAttempted: `0, 32, ${saltLengthN}`,
};
console.warn(
"Transaction Verification Failed! \n",
`Details: ${JSON.stringify(details, null, 2)} \n`,
"N.B. ArweaveJS is only guaranteed to verify txs created using ArweaveJS.",
)
"N.B. ArweaveJS is only guaranteed to verify txs created using ArweaveJS."
);
}

return result
return result;
}

private async jwkToCryptoKey(jwk: JWKInterface): Promise<CryptoKey> {
Expand Down
4 changes: 2 additions & 2 deletions test/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ describe("Wallets and keys", function () {
expect(addressB).to.match(digestRegex);
expect(addressA).to.not.equal(addressB);

expect(arweave.utils.b64UrlToBuffer(walletA.n).byteLength).eq(4096 / 8)
expect(arweave.utils.b64UrlToBuffer(walletB.n).byteLength).eq(4096 / 8)
expect(arweave.utils.b64UrlToBuffer(walletA.n).byteLength).eq(4096 / 8);
expect(arweave.utils.b64UrlToBuffer(walletB.n).byteLength).eq(4096 / 8);
});

it("should get wallet info", async function () {
Expand Down

0 comments on commit 0a087f4

Please sign in to comment.