diff --git a/CHANGELOG.md b/CHANGELOG.md index 544ba4ed..37b08c50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# [1.7.0-alpha.2](https://github.com/ardriveapp/turbo-sdk/compare/v1.7.0-alpha.1...v1.7.0-alpha.2) (2024-04-25) + + +### Bug Fixes + +* **signer:** use web signer if .window exists PE-6055 ([90cbd56](https://github.com/ardriveapp/turbo-sdk/commit/90cbd5624da8c63ab56a4ef516120df4a8831b65)) # [1.7.0](https://github.com/ardriveapp/turbo-sdk/compare/v1.6.0...v1.7.0) (2024-04-25) diff --git a/bundle.mjs b/bundle.mjs index 16892871..9895061d 100644 --- a/bundle.mjs +++ b/bundle.mjs @@ -14,6 +14,7 @@ const bundle = () => { polyfillNode({ polyfills: { crypto: true, + buffer: true, }, }), ], diff --git a/src/common/token.ts b/src/common/token.ts index 9c3192f7..7ca5b738 100644 --- a/src/common/token.ts +++ b/src/common/token.ts @@ -92,7 +92,11 @@ export class ArweaveToken implements TokenTools { tx.setOwner(publicKeyB64Url); const dataToSign = await tx.getSignatureData(); - const signatureBuffer = Buffer.from(await signer.signData(dataToSign)); + + const signatureUint8Array = await signer.signData(dataToSign); + + const signatureBuffer = Buffer.from(signatureUint8Array); + const id = sha256B64Url(signatureBuffer); tx.setSignature({ diff --git a/src/node/factory.ts b/src/node/factory.ts index c842d96e..12deb1f2 100644 --- a/src/node/factory.ts +++ b/src/node/factory.ts @@ -23,6 +23,7 @@ import { TurboAuthenticatedUploadService, } from '../common/index.js'; import { TurboAuthenticatedConfiguration, TurboSigner } from '../types.js'; +import { TurboWebArweaveSigner } from '../web/signer.js'; import { TurboNodeSigner } from './signer.js'; export class TurboFactory extends TurboBaseFactory { @@ -51,10 +52,18 @@ export class TurboFactory extends TurboBaseFactory { throw new Error('A privateKey or signer must be provided.'); } - const turboSigner = new TurboNodeSigner({ - signer, - logger: this.logger, - }); + // when in browser, we use TurboWebArweaveSigner + const turboSigner = + typeof window !== 'undefined' + ? new TurboWebArweaveSigner({ + signer, + logger: this.logger, + }) + : new TurboNodeSigner({ + signer, + logger: this.logger, + }); + const paymentService = new TurboAuthenticatedPaymentService({ ...paymentServiceConfig, signer: turboSigner,