From 0a087f44c8785ba8af36b9e772fcabce40d396d9 Mon Sep 17 00:00:00 2001 From: Ros McMahon Date: Sun, 29 Sep 2024 12:31:02 +0700 Subject: [PATCH] 1.15.2 --- package-lock.json | 4 ++-- package.json | 2 +- src/common/lib/api.ts | 15 +++++++++----- src/common/lib/crypto/node-driver.ts | 24 +++++++++++------------ src/common/lib/crypto/webcrypto-driver.ts | 19 ++++++++++-------- test/wallets.ts | 4 ++-- 6 files changed, 37 insertions(+), 31 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8e05130..9df1681 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "arweave", - "version": "1.15.1", + "version": "1.15.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "arweave", - "version": "1.15.1", + "version": "1.15.2", "license": "MIT", "dependencies": { "arconnect": "^0.4.2", diff --git a/package.json b/package.json index 8680f19..1614c1d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/common/lib/api.ts b/src/common/lib/api.ts index 3e83cd2..ee05ab7 100755 --- a/src/common/lib/api.ts +++ b/src/common/lib/api.ts @@ -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 { @@ -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 & AsyncIterable) +type AsyncIterableReadableStream = ReadableStream & + AsyncIterable; // | ReadableStream -const addAsyncIterator = (body: ReadableStream): AsyncIterableReadableStream => { - const bodyWithIter = body as ReadableStream & AsyncIterable; +const addAsyncIterator = ( + body: ReadableStream +): AsyncIterableReadableStream => { + const bodyWithIter = body as ReadableStream & + AsyncIterable; if (typeof bodyWithIter[Symbol.asyncIterator] === "undefined") { bodyWithIter[Symbol.asyncIterator] = webIiterator(body); } diff --git a/src/common/lib/crypto/node-driver.ts b/src/common/lib/crypto/node-driver.ts index 8211b0c..4ceec77 100644 --- a/src/common/lib/crypto/node-driver.ts +++ b/src/common/lib/crypto/node-driver.ts @@ -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); }); } diff --git a/src/common/lib/crypto/webcrypto-driver.ts b/src/common/lib/crypto/webcrypto-driver.ts index 7efc015..0b736c5 100644 --- a/src/common/lib/crypto/webcrypto-driver.ts +++ b/src/common/lib/crypto/webcrypto-driver.ts @@ -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( { @@ -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 { diff --git a/test/wallets.ts b/test/wallets.ts index 54f3d7e..880d614 100644 --- a/test/wallets.ts +++ b/test/wallets.ts @@ -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 () {