@snapshot-labs/snapshot.js 0.12.0-beta.1 → 0.12.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/snapshot.cjs.js +3 -3
- package/dist/snapshot.esm.js +3 -3
- package/dist/snapshot.min.js +1 -1
- package/dist/src/utils.d.ts +1 -1
- package/package.json +1 -1
- package/src/utils.spec.js +5 -5
- package/src/utils.ts +3 -3
package/dist/src/utils.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export declare function sleep(time: any): Promise<unknown>;
|
|
|
37
37
|
export declare function getNumberWithOrdinal(n: any): string;
|
|
38
38
|
export declare function isStarknetAddress(address: string): boolean;
|
|
39
39
|
export declare function isEvmAddress(address: string): boolean;
|
|
40
|
-
export declare function getFormattedAddress(address: string, format
|
|
40
|
+
export declare function getFormattedAddress(address: string, format: 'evm' | 'starknet'): string;
|
|
41
41
|
export { getDelegatesBySpace, SNAPSHOT_SUBGRAPH_URL };
|
|
42
42
|
declare const _default: {
|
|
43
43
|
call: typeof call;
|
package/package.json
CHANGED
package/src/utils.spec.js
CHANGED
|
@@ -496,7 +496,7 @@ describe('utils', () => {
|
|
|
496
496
|
describe('getFormattedAddress', () => {
|
|
497
497
|
test('returns a checksummed EVM address', () => {
|
|
498
498
|
const address = '0x91fd2c8d24767db4ece7069aa27832ffaf8590f3';
|
|
499
|
-
expect(getFormattedAddress(address,
|
|
499
|
+
expect(getFormattedAddress(address, 'evm')).toEqual(
|
|
500
500
|
'0x91FD2c8d24767db4Ece7069AA27832ffaf8590f3'
|
|
501
501
|
);
|
|
502
502
|
});
|
|
@@ -504,27 +504,27 @@ describe('utils', () => {
|
|
|
504
504
|
test('returns a padded and lowercased starknet address', () => {
|
|
505
505
|
const address =
|
|
506
506
|
'0x2a0a8f3b6097e7a6bd7649deb30715323072a159c0e6b71b689bd245c146cc0';
|
|
507
|
-
expect(getFormattedAddress(address,
|
|
507
|
+
expect(getFormattedAddress(address, 'starknet')).toEqual(
|
|
508
508
|
'0x02a0a8f3b6097e7a6bd7649deb30715323072a159c0e6b71b689bd245c146cc0'
|
|
509
509
|
);
|
|
510
510
|
});
|
|
511
511
|
|
|
512
512
|
test('returns an EVM address as starknet address', () => {
|
|
513
513
|
const address = '0x91FD2c8d24767db4Ece7069AA27832ffaf8590f3';
|
|
514
|
-
expect(getFormattedAddress(address,
|
|
514
|
+
expect(getFormattedAddress(address, 'starknet')).toEqual(
|
|
515
515
|
'0x00000000000000000000000091fd2c8d24767db4ece7069aa27832ffaf8590f3'
|
|
516
516
|
);
|
|
517
517
|
});
|
|
518
518
|
|
|
519
519
|
test('throws an error when the address is not a starknet address', () => {
|
|
520
520
|
const address = 'hello';
|
|
521
|
-
expect(() => getFormattedAddress(address,
|
|
521
|
+
expect(() => getFormattedAddress(address, 'starknet')).toThrow();
|
|
522
522
|
});
|
|
523
523
|
|
|
524
524
|
test('throws an error when the address is not an EVM address', () => {
|
|
525
525
|
const address =
|
|
526
526
|
'0x2a0a8f3b6097e7a6bd7649deb30715323072a159c0e6b71b689bd245c146cc0';
|
|
527
|
-
expect(() => getFormattedAddress(address,
|
|
527
|
+
expect(() => getFormattedAddress(address, 'evm')).toThrow();
|
|
528
528
|
});
|
|
529
529
|
});
|
|
530
530
|
});
|
package/src/utils.ts
CHANGED
|
@@ -665,10 +665,10 @@ export function isEvmAddress(address: string): boolean {
|
|
|
665
665
|
|
|
666
666
|
export function getFormattedAddress(
|
|
667
667
|
address: string,
|
|
668
|
-
format:
|
|
668
|
+
format: 'evm' | 'starknet'
|
|
669
669
|
): string {
|
|
670
|
-
if (format
|
|
671
|
-
if (format
|
|
670
|
+
if (format === 'evm' && isEvmAddress(address)) return getAddress(address);
|
|
671
|
+
if (format === 'starknet' && isStarknetAddress(address))
|
|
672
672
|
return validateAndParseAddress(address);
|
|
673
673
|
|
|
674
674
|
throw new Error(`Invalid address: ${address}`);
|