Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ledger Signer #1185

Merged
merged 2 commits into from
Jul 26, 2024
Merged
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
10 changes: 10 additions & 0 deletions __tests__/utils/encode.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { encode } from '../../src';
import { atobUniversal, btoaUniversal } from '../../src/utils/encode';

describe('atobUniversal and btoaUniversal functions', () => {
Expand Down Expand Up @@ -32,3 +33,12 @@ describe('atobUniversal and btoaUniversal functions', () => {
expect(decoded).toEqual(new Uint8Array([]));
});
});

describe('concatenateArrayBuffer', () => {
test('should concatenate uint8Arrays', () => {
const path0buff = new Uint8Array([128, 0, 10, 85]);
const path1buff = new Uint8Array([71, 65, 233, 201]);
const result = encode.concatenateArrayBuffer([path0buff, path1buff]);
expect(result).toEqual(new Uint8Array([128, 0, 10, 85, 71, 65, 233, 201]));
});
});
14 changes: 14 additions & 0 deletions __tests__/utils/ethSigner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
encode,
eth,
extractContractHashes,
getLedgerPathBuffer,
hash,
num,
stark,
Expand Down Expand Up @@ -353,3 +354,16 @@ describe('Ethereum signer', () => {
});
});
});

describe('Ledger Signer', () => {
// signature of Ledger can't be tested automatically.
// So, just the test of the path encoding.
test('getLedgerPathBuffer', () => {
const path = getLedgerPathBuffer(3, 'AstroAPP');
expect(path).toEqual(
new Uint8Array([
128, 0, 10, 85, 71, 65, 233, 201, 95, 192, 123, 107, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0,
])
);
});
});
8 changes: 8 additions & 0 deletions __tests__/utils/num.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
isNumber,
isBoolean,
} from '../../src/utils/num';
import { num } from '../../src';

describe('isHex', () => {
test('should return true for valid hex strings', () => {
Expand Down Expand Up @@ -208,3 +209,10 @@ describe('isBoolean', () => {
expect(isBoolean({})).toBe(false);
});
});

describe('stringToSha256ToArrayBuff4', () => {
test('should correctly hash&encode an utf8 string', () => {
const buff = num.stringToSha256ToArrayBuff4('LedgerW');
expect(buff).toEqual(new Uint8Array([43, 206, 231, 219]));
});
});
61 changes: 60 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"typescript-coverage-report": "npm:@penovicp/typescript-coverage-report@^1.0.0-beta.2"
},
"dependencies": {
"@ledgerhq/hw-transport": "^6.31.1",
"@noble/curves": "~1.4.0",
"@noble/hashes": "^1.4.0",
"@scure/base": "~1.1.3",
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export { ETransactionVersion as TRANSACTION_VERSION };

export const ZERO = 0n;
export const MASK_250 = 2n ** 250n - 1n; // 2 ** 250 - 1
export const MASK_31 = 2n ** 31n - 1n; // 2 ** 31 - 1
export const API_VERSION = ZERO;
export const PRIME = 2n ** 251n + 17n * 2n ** 192n + 1n;

Expand Down
1 change: 1 addition & 0 deletions src/signer/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './interface';
export * from './default';
export * from './ethSigner';
export * from './ledgerSigner';
Loading