Skip to content

Commit a3bb3ce

Browse files
Merge pull request #5500 from BitGo/coin-3052-fix-apt-withdrawal-bugs
fix(sdk-coin-apt): stip hex prefix
2 parents 8169f4e + 2a1e789 commit a3bb3ce

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

modules/sdk-coin-apt/src/lib/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class Utils implements BaseUtils {
4343

4444
/** @inheritdoc */
4545
isValidPublicKey(key: string): boolean {
46+
key = this.stripHexPrefix(key);
4647
return isValidEd25519PublicKey(key);
4748
}
4849

@@ -102,6 +103,15 @@ export class Utils implements BaseUtils {
102103
castToNumber(value: bigint): number {
103104
return new BigNumber(value.toString()).toNumber();
104105
}
106+
107+
/**
108+
* Strip hex prefix
109+
* @param str
110+
* @returns hex string without 0x prefix
111+
*/
112+
stripHexPrefix(str: string): string {
113+
return str.replace(/^0x/i, '');
114+
}
105115
}
106116

107117
const utils = new Utils();

modules/sdk-coin-apt/test/unit/apt.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ describe('APT:', function () {
6464
tapt.getBaseFactor().should.equal(1e8);
6565
});
6666

67+
it('is valid pub', function () {
68+
// with 0x prefix
69+
basecoin.isValidPub('0x9b4e96086d111500259f9b38680b0509a405c1904da18976455a20c691d3bb07').should.equal(true);
70+
// without 0x prefix
71+
basecoin.isValidPub('9b4e96086d111500259f9b38680b0509a405c1904da18976455a20c691d3bb07').should.equal(true);
72+
});
73+
6774
describe('Verify transaction: ', () => {
6875
it('should succeed to verify transaction', async function () {
6976
const txPrebuild = newTxPrebuild();

modules/sdk-coin-apt/test/unit/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,16 @@ describe('Aptos util library', function () {
3636
should.throws(() => utils.deserializeSignedTransaction(testData.INVALID_TRANSFER));
3737
});
3838
});
39+
40+
it('strip hex prefix', function () {
41+
const s = utils.stripHexPrefix('0x9b4e96086d111500259f9b38680b0509a405c1904da18976455a20c691d3bb07');
42+
should.equal(s, '9b4e96086d111500259f9b38680b0509a405c1904da18976455a20c691d3bb07');
43+
});
44+
45+
it('is valid public key', function () {
46+
// with 0x prefix
47+
should.equal(true, utils.isValidPublicKey('0x9b4e96086d111500259f9b38680b0509a405c1904da18976455a20c691d3bb07'));
48+
// without 0x prefix
49+
should.equal(true, utils.isValidPublicKey('9b4e96086d111500259f9b38680b0509a405c1904da18976455a20c691d3bb07'));
50+
});
3951
});

0 commit comments

Comments
 (0)