Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/micropayment-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class MicropaymentEngine {
name: 'PayBot',
version: '1',
chainId: 8453,
verifyingContract: '0x50b0f7224fFc5f4f7685DbcE1B8b7E7B8B8A4A23' as Address,
verifyingContract: '0x50b0f7224fFC5F4F7685DbcE1B8b7e7B8b8A4A23' as Address,
};

const nonce = this.generateNonce() as `0x${string}`;
Expand Down Expand Up @@ -338,11 +338,12 @@ export class MicropaymentEngine {
return `${whole}${fraction}`.replace(/^0+/, '') || '0';
}

private generateNonce(): string {
private generateNonce(): `0x${string}` {
const buf = new Uint8Array(32);
webcrypto.getRandomValues(buf);
return Array.from(buf)
const hex = Array.from(buf)
.map(b => b.toString(16).padStart(2, '0'))
.join('');
return `0x${hex}`;
Comment on lines +344 to +347
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current method of converting the Uint8Array to a hex string is inefficient as it involves multiple array allocations and iterations. Since this is a Node.js environment, using Buffer is significantly more performant and concise. Alternatively, you could consider importing and using the existing generateEIP3009Nonce utility from src/crypto.ts to avoid code duplication.

    const hex = Buffer.from(buf).toString('hex');
    return `0x${hex}`;

}
}
Loading