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,