Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions __tests__/utils/ledgerSigner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ describe('starknet/ledger', () => {
);
});

test('getLedgerPathBuffer111 returns 24 bytes when the application hash starts with a zero byte', () => {
expect(getLedgerPathBuffer111(0, 'App135')).toEqual(
new Uint8Array([
128, 0, 10, 85, 71, 65, 233, 201, 0, 40, 206, 181, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
])
);
});

test('getLedgerPathBuffer221 returns the EIP2645 path of the APPs from v2.2.1 to v2.4.3', () => {
expect(getLedgerPathBuffer221(0)).toEqual(
new Uint8Array([
Expand Down
5 changes: 5 additions & 0 deletions __tests__/utils/num.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ describe('stringToSha256ToArrayBuff4', () => {
const buff = num.stringToSha256ToArrayBuff4('LedgerW');
expect(buff).toEqual(new Uint8Array([43, 206, 231, 219]));
});

test('should keep 4 bytes when the leading byte is zero', () => {
const buff = num.stringToSha256ToArrayBuff4('App135');
expect(buff).toEqual(new Uint8Array([0, 40, 206, 181]));
});
});

describe('isBigNumberish', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/num.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export function stringToSha256ToArrayBuff4(str: string): Uint8Array {
// eslint-disable-next-line no-bitwise
const int31 = (n: bigint) => Number(n & MASK_31);
const result: number = int31(BigInt(addHexPrefix(buf2hex(sha256(utf8ToBytes(str))))));
return hexToBytes(toHex(result));
return hexToBytes(addHexPrefix(removeHexPrefix(toHex(result)).padStart(8, '0')));
}

/**
Expand Down