Skip to content

Commit

Permalink
fix(signer): use web signer if .window exists PE-6055
Browse files Browse the repository at this point in the history
  • Loading branch information
fedellen committed Apr 25, 2024
1 parent 96686c9 commit 90cbd56
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions bundle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const bundle = () => {
polyfillNode({
polyfills: {
crypto: true,
buffer: true,
},
}),
],
Expand Down
6 changes: 5 additions & 1 deletion src/common/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
17 changes: 13 additions & 4 deletions src/node/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
})

Check warning on line 61 in src/node/factory.ts

View check run for this annotation

Codecov / codecov/patch

src/node/factory.ts#L59-L61

Added lines #L59 - L61 were not covered by tests
: new TurboNodeSigner({
signer,
logger: this.logger,
});

const paymentService = new TurboAuthenticatedPaymentService({
...paymentServiceConfig,
signer: turboSigner,
Expand Down

0 comments on commit 90cbd56

Please sign in to comment.