Skip to content

Commit d4e2321

Browse files
ranga-r2hitansh-madan
authored andcommitted
Merge pull request #7627 from BitGo/rel/latest
chore(root): publish modules TICKET: WIN-7912
1 parent 2959566 commit d4e2321

File tree

8 files changed

+55
-25
lines changed

8 files changed

+55
-25
lines changed

modules/sdk-coin-icp/src/icp.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
TssVerifyAddressOptions,
2121
VerifyTransactionOptions,
2222
} from '@bitgo/sdk-core';
23-
import { coins, BaseCoin as StaticsBaseCoin } from '@bitgo/statics';
23+
import { coins, NetworkType, BaseCoin as StaticsBaseCoin } from '@bitgo/statics';
2424
import { Principal } from '@dfinity/principal';
2525
import axios from 'axios';
2626
import BigNumber from 'bignumber.js';
@@ -30,6 +30,7 @@ import * as mpc from '@bitgo/sdk-lib-mpc';
3030
import {
3131
CurveType,
3232
LEDGER_CANISTER_ID,
33+
TESTNET_LEDGER_CANISTER_ID,
3334
PayloadsData,
3435
PUBLIC_NODE_REQUEST_ENDPOINT,
3536
PublicNodeSubmitResponse,
@@ -249,7 +250,9 @@ export class Icp extends BaseCoin {
249250

250251
private getPublicNodeBroadcastEndpoint(): string {
251252
const nodeUrl = this.getPublicNodeUrl();
252-
const principal = Principal.fromUint8Array(LEDGER_CANISTER_ID);
253+
const ledgerCanisterId =
254+
this._staticsCoin.network.type === NetworkType.TESTNET ? TESTNET_LEDGER_CANISTER_ID : LEDGER_CANISTER_ID;
255+
const principal = Principal.fromUint8Array(ledgerCanisterId);
253256
const canisterIdHex = principal.toText();
254257
const endpoint = `${nodeUrl}${PUBLIC_NODE_REQUEST_ENDPOINT}${canisterIdHex}/call`;
255258
return endpoint;
@@ -263,7 +266,7 @@ export class Icp extends BaseCoin {
263266
*/
264267
protected async getAccountBalance(publicKeyHex: string): Promise<BigNumber> {
265268
const principalId = utils.getPrincipalIdFromPublicKey(publicKeyHex).toText();
266-
const agent = new IcpAgent(this.getPublicNodeUrl());
269+
const agent = new IcpAgent(this.getPublicNodeUrl(), this._staticsCoin);
267270
return agent.getBalance(principalId);
268271
}
269272

@@ -277,7 +280,7 @@ export class Icp extends BaseCoin {
277280
* @throws Will propagate any errors encountered while communicating with the ICP node.
278281
*/
279282
protected async getFeeData(): Promise<BigNumber> {
280-
const agent = new IcpAgent(this.getPublicNodeUrl());
283+
const agent = new IcpAgent(this.getPublicNodeUrl(), this._staticsCoin);
281284
return await agent.getFee();
282285
}
283286

modules/sdk-coin-icp/src/lib/icpAgent.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
import { Principal } from '@dfinity/principal';
22
import { HttpAgent, replica, AgentCanister } from 'ic0';
33
import utils from './utils';
4-
import { ACCOUNT_BALANCE_CALL, LEDGER_CANISTER_ID, ICRC1_FEE_KEY, METADATA_CALL, DEFAULT_SUBACCOUNT } from './iface';
4+
import {
5+
ACCOUNT_BALANCE_CALL,
6+
LEDGER_CANISTER_ID,
7+
TESTNET_LEDGER_CANISTER_ID,
8+
ICRC1_FEE_KEY,
9+
METADATA_CALL,
10+
DEFAULT_SUBACCOUNT,
11+
} from './iface';
512
import BigNumber from 'bignumber.js';
13+
import { NetworkType, BaseCoin as StaticsBaseCoin } from '@bitgo/statics';
614

715
export class IcpAgent {
816
private readonly host: string;
17+
private readonly staticsCoin: Readonly<StaticsBaseCoin>;
918

10-
constructor(host: string) {
19+
constructor(host: string, staticsCoin: Readonly<StaticsBaseCoin>) {
1120
this.host = host;
21+
this.staticsCoin = staticsCoin;
1222
}
1323

1424
/**
@@ -35,7 +45,9 @@ export class IcpAgent {
3545
private getLedger(): AgentCanister {
3646
const agent = this.createAgent();
3747
const ic = replica(agent, { local: true });
38-
return ic(Principal.fromUint8Array(LEDGER_CANISTER_ID).toText());
48+
const ledgerCanisterId =
49+
this.staticsCoin.network.type === NetworkType.TESTNET ? TESTNET_LEDGER_CANISTER_ID : LEDGER_CANISTER_ID;
50+
return ic(Principal.fromUint8Array(ledgerCanisterId).toText());
3951
}
4052

4153
/**

modules/sdk-coin-icp/src/lib/iface.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
export const MAX_INGRESS_TTL = 5 * 60 * 1000_000_000; // 5 minutes in nanoseconds
77
export const PERMITTED_DRIFT = 60 * 1000_000_000; // 60 seconds in nanoseconds
88
export const LEDGER_CANISTER_ID = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 2, 1, 1]); // Uint8Array value for "00000000000000020101" and the string value is "ryjl3-tyaaa-aaaaa-aaaba-cai"
9+
export const TESTNET_LEDGER_CANISTER_ID = new Uint8Array([0, 0, 0, 0, 1, 0, 130, 251, 1, 1]); // Uint8Array value for "00000000010082fb0101" and the string value is "xafvr-biaaa-aaaai-aql5q-cai"
910
export const ROOT_PATH = 'm/0';
1011
export const ACCOUNT_BALANCE_CALL = 'icrc1_balance_of';
1112
export const PUBLIC_NODE_REQUEST_ENDPOINT = '/api/v3/canister/';
@@ -36,7 +37,11 @@ export enum MethodName {
3637
}
3738

3839
export enum Network {
39-
ID = '00000000000000020101', // ICP does not have different network IDs for mainnet and testnet
40+
ID = '00000000000000020101',
41+
}
42+
43+
export enum TestNetwork {
44+
ID = '00000000000000020101',
4045
}
4146

4247
export interface IcpTransactionData {

modules/sdk-coin-icp/src/lib/transferBuilder.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ export class TransferBuilder extends TransactionBuilder {
3838
}
3939
this.validateTransaction(this._transaction);
4040
this.buildIcpTransactionData();
41-
const unsignedTransactionBuilder = new UnsignedTransactionBuilder(this._transaction.icpTransaction);
41+
const unsignedTransactionBuilder = new UnsignedTransactionBuilder(
42+
this._transaction.icpTransaction,
43+
this._coinConfig
44+
);
4245
const payloadsData = await unsignedTransactionBuilder.getUnsignedTransaction();
4346
this._transaction.payloadsData = payloadsData;
4447
return this._transaction;

modules/sdk-coin-icp/src/lib/unsignedTransactionBuilder.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ import {
1010
MAX_INGRESS_TTL,
1111
PERMITTED_DRIFT,
1212
LEDGER_CANISTER_ID,
13+
TESTNET_LEDGER_CANISTER_ID,
1314
} from './iface';
1415
import utils from './utils';
16+
import { NetworkType, BaseCoin as StaticsBaseCoin } from '@bitgo/statics';
1517

1618
export class UnsignedTransactionBuilder {
1719
private _icpTransactionPayload: IcpTransaction;
18-
constructor(icpTransactionPayload: IcpTransaction) {
20+
private readonly _staticsCoin: Readonly<StaticsBaseCoin>;
21+
22+
constructor(icpTransactionPayload: IcpTransaction, staticsCoin: Readonly<StaticsBaseCoin>) {
1923
this._icpTransactionPayload = icpTransactionPayload;
24+
this._staticsCoin = staticsCoin;
2025
}
2126

2227
async getUnsignedTransaction(): Promise<PayloadsData> {
@@ -104,7 +109,9 @@ export class UnsignedTransactionBuilder {
104109
async getUpdate(sendArgs: SendArgs, publicKeyHex: string): Promise<HttpCanisterUpdate> {
105110
const principalId = utils.getPrincipalIdFromPublicKey(publicKeyHex).toUint8Array();
106111
const senderBlob = Buffer.from(principalId);
107-
const canisterIdBuffer = Buffer.from(LEDGER_CANISTER_ID);
112+
const ledgerCanisterId =
113+
this._staticsCoin.network.type === NetworkType.TESTNET ? TESTNET_LEDGER_CANISTER_ID : LEDGER_CANISTER_ID;
114+
const canisterIdBuffer = Buffer.from(ledgerCanisterId);
108115
const args = await utils.toArg(sendArgs);
109116
const update: HttpCanisterUpdate = {
110117
canister_id: canisterIdBuffer,

modules/sdk-coin-icp/test/resources/icp.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,35 +192,35 @@ export const PayloadsData = {
192192
payloads: [
193193
{
194194
account_identifier: { address: '0af815da8259ba8bb3d34fbfb2ac730f07a1adc81438d40d667d91b408b25f2f' },
195-
hex_bytes: '0a69632d72657175657374523de3c7c5b4613155b74ede2e54493f6acbe8bf6d910154fbbb3a98ba3e0098',
195+
hex_bytes: '0a69632d726571756573745f47cbcfe8333d5bf3806a121a6d17b0a71f895f311664cb476a18b166a0e867',
196196
signature_type: 'ecdsa',
197197
},
198198
],
199199
unsigned_transaction:
200-
'b90002677570646174657381826b5452414e53414354494f4eb900056b63616e69737465725f69644a000000000000000201016b6d6574686f645f6e616d656773656e645f70626361726758400a0308d20912040a02080a1a0308904e2a220a20c3d30f404955975adaba89f2e1ebc75c1f44a6a204578afce8f3780d64fe252e3a0a0880a48596eb92b599186673656e646572581dd5fc1dc4d74d4aa35d81cf345533d20548113412d32fffdcece2f68a026e696e67726573735f6578706972791b000000000000000070696e67726573735f6578706972696573811b1832d4ce93deb200',
200+
'b90002677570646174657381826b5452414e53414354494f4eb900056b63616e69737465725f69644a00000000010082fb01016b6d6574686f645f6e616d656773656e645f70626361726758400a0308d20912040a02080a1a0308904e2a220a20c3d30f404955975adaba89f2e1ebc75c1f44a6a204578afce8f3780d64fe252e3a0a0880a48596eb92b599186673656e646572581dd5fc1dc4d74d4aa35d81cf345533d20548113412d32fffdcece2f68a026e696e67726573735f6578706972791b000000000000000070696e67726573735f6578706972696573811b1832d4ce93deb200',
201201
};
202202

203203
export const OnChainTransactionHash = '87f2e7ca80961bdc3a1fe761553a8a7f8ac5bf28b71f4e1fba807cf352a27f52';
204204

205205
export const PayloadsDataWithDefaultMemo = {
206206
payloads: [
207207
{
208-
hex_bytes: '0a69632d726571756573747c1aff6d0edea47545315bb0be0230b5908e94aa5fcb8040e0680f30da5d4359',
208+
hex_bytes: '0a69632d726571756573746a1eaf27e1b00fafe135ba095d0a1f9cdbd91d36babb7d3e5884a773e516843d',
209209
account_identifier: {
210210
address: '0af815da8259ba8bb3d34fbfb2ac730f07a1adc81438d40d667d91b408b25f2f',
211211
},
212212
signature_type: 'ecdsa',
213213
},
214214
],
215215
unsigned_transaction:
216-
'b90002677570646174657381826b5452414e53414354494f4eb900056b63616e69737465725f69644a000000000000000201016b6d6574686f645f6e616d656773656e645f706263617267583f0a02080012040a02080a1a0308904e2a220a20c3d30f404955975adaba89f2e1ebc75c1f44a6a204578afce8f3780d64fe252e3a0a0880a48596eb92b599186673656e646572581dd5fc1dc4d74d4aa35d81cf345533d20548113412d32fffdcece2f68a026e696e67726573735f6578706972791b000000000000000070696e67726573735f6578706972696573811b1832d4ce93deb200',
216+
'b90002677570646174657381826b5452414e53414354494f4eb900056b63616e69737465725f69644a00000000010082fb01016b6d6574686f645f6e616d656773656e645f706263617267583f0a02080012040a02080a1a0308904e2a220a20c3d30f404955975adaba89f2e1ebc75c1f44a6a204578afce8f3780d64fe252e3a0a0880a48596eb92b599186673656e646572581dd5fc1dc4d74d4aa35d81cf345533d20548113412d32fffdcece2f68a026e696e67726573735f6578706972791b000000000000000070696e67726573735f6578706972696573811b1832d4ce93deb200',
217217
};
218218

219219
export const Signatures = [
220220
{
221221
signing_payload: {
222222
account_identifier: { address: '0af815da8259ba8bb3d34fbfb2ac730f07a1adc81438d40d667d91b408b25f2f' },
223-
hex_bytes: '0a69632d72657175657374523de3c7c5b4613155b74ede2e54493f6acbe8bf6d910154fbbb3a98ba3e0098',
223+
hex_bytes: '0a69632d726571756573745f47cbcfe8333d5bf3806a121a6d17b0a71f895f311664cb476a18b166a0e867',
224224
signature_type: 'ecdsa',
225225
},
226226
signature_type: 'ecdsa',
@@ -230,7 +230,7 @@ export const Signatures = [
230230
curve_type: 'secp256k1',
231231
},
232232
hex_bytes:
233-
'dee0c728fc06d2140ad84e2be5f983626114d49f51216d4070bfccbfba79041d77648bad917428a8adb9908828458488562f0d159571382b1ac50fb81d5165c9',
233+
'f2b4cd71e3399e3859fd89f675a0cb6a6a4227fb5cf089e88b627c1168f8ef430d9bb49deed0c30f36b3032d917912d5fcbbb67b05b9a4af743c83b151b15a3b',
234234
},
235235
];
236236

@@ -240,7 +240,7 @@ export const SignaturesWithDefaultMemo = [
240240
account_identifier: {
241241
address: '0af815da8259ba8bb3d34fbfb2ac730f07a1adc81438d40d667d91b408b25f2f',
242242
},
243-
hex_bytes: '0a69632d726571756573747c1aff6d0edea47545315bb0be0230b5908e94aa5fcb8040e0680f30da5d4359',
243+
hex_bytes: '0a69632d726571756573746a1eaf27e1b00fafe135ba095d0a1f9cdbd91d36babb7d3e5884a773e516843d',
244244
signature_type: 'ecdsa',
245245
},
246246
signature_type: 'ecdsa',
@@ -250,15 +250,15 @@ export const SignaturesWithDefaultMemo = [
250250
curve_type: 'secp256k1',
251251
},
252252
hex_bytes:
253-
'32f3f90cbf76f81a4ffcba7819dad2b483afe1515d87711475d4af2e993a444b7f22ef303273d40fc18c7b4ffa3295c5cb58886a9e8cf252cedd1cdb8be5a399',
253+
'fb5346def1d12b2cc246ff807447b95b4202af7f430f24d9de14ad7035b92c1621bef73f82221e00df12552958f27736e73f550e6aa5768dfac931945ff2d41a',
254254
},
255255
];
256256

257257
export const SignedTransaction =
258-
'b9000367636f6e74656e74b900066c726571756573745f747970656463616c6c6b63616e69737465725f69644a000000000000000201016b6d6574686f645f6e616d656773656e645f70626361726758400a0308d20912040a02080a1a0308904e2a220a20c3d30f404955975adaba89f2e1ebc75c1f44a6a204578afce8f3780d64fe252e3a0a0880a48596eb92b599186673656e646572581dd5fc1dc4d74d4aa35d81cf345533d20548113412d32fffdcece2f68a026e696e67726573735f6578706972791b1832d4ce93deb2006d73656e6465725f7075626b6579d84058583056301006072a8648ce3d020106052b8104000a034200042ab77b959e28c4fa47fa8fb9e57cec3d66df5684d076ac2e4c5f28fd69a23dd31a59f908c8add51eab3530b4ac5d015166eaf2198c52fa9a8df7cfaeb8fdb7d46a73656e6465725f7369675840dee0c728fc06d2140ad84e2be5f983626114d49f51216d4070bfccbfba79041d77648bad917428a8adb9908828458488562f0d159571382b1ac50fb81d5165c9';
258+
'b9000367636f6e74656e74b900066c726571756573745f747970656463616c6c6b63616e69737465725f69644a00000000010082fb01016b6d6574686f645f6e616d656773656e645f70626361726758400a0308d20912040a02080a1a0308904e2a220a20c3d30f404955975adaba89f2e1ebc75c1f44a6a204578afce8f3780d64fe252e3a0a0880a48596eb92b599186673656e646572581dd5fc1dc4d74d4aa35d81cf345533d20548113412d32fffdcece2f68a026e696e67726573735f6578706972791b1832d4ce93deb2006d73656e6465725f7075626b6579d84058583056301006072a8648ce3d020106052b8104000a034200042ab77b959e28c4fa47fa8fb9e57cec3d66df5684d076ac2e4c5f28fd69a23dd31a59f908c8add51eab3530b4ac5d015166eaf2198c52fa9a8df7cfaeb8fdb7d46a73656e6465725f7369675840f2b4cd71e3399e3859fd89f675a0cb6a6a4227fb5cf089e88b627c1168f8ef430d9bb49deed0c30f36b3032d917912d5fcbbb67b05b9a4af743c83b151b15a3b';
259259

260260
export const SignedTransactionWithDefaultMemo =
261-
'b9000367636f6e74656e74b900066c726571756573745f747970656463616c6c6b63616e69737465725f69644a000000000000000201016b6d6574686f645f6e616d656773656e645f706263617267583f0a02080012040a02080a1a0308904e2a220a20c3d30f404955975adaba89f2e1ebc75c1f44a6a204578afce8f3780d64fe252e3a0a0880a48596eb92b599186673656e646572581dd5fc1dc4d74d4aa35d81cf345533d20548113412d32fffdcece2f68a026e696e67726573735f6578706972791b1832d4ce93deb2006d73656e6465725f7075626b6579d84058583056301006072a8648ce3d020106052b8104000a034200042ab77b959e28c4fa47fa8fb9e57cec3d66df5684d076ac2e4c5f28fd69a23dd31a59f908c8add51eab3530b4ac5d015166eaf2198c52fa9a8df7cfaeb8fdb7d46a73656e6465725f736967584032f3f90cbf76f81a4ffcba7819dad2b483afe1515d87711475d4af2e993a444b7f22ef303273d40fc18c7b4ffa3295c5cb58886a9e8cf252cedd1cdb8be5a399';
261+
'b9000367636f6e74656e74b900066c726571756573745f747970656463616c6c6b63616e69737465725f69644a00000000010082fb01016b6d6574686f645f6e616d656773656e645f706263617267583f0a02080012040a02080a1a0308904e2a220a20c3d30f404955975adaba89f2e1ebc75c1f44a6a204578afce8f3780d64fe252e3a0a0880a48596eb92b599186673656e646572581dd5fc1dc4d74d4aa35d81cf345533d20548113412d32fffdcece2f68a026e696e67726573735f6578706972791b1832d4ce93deb2006d73656e6465725f7075626b6579d84058583056301006072a8648ce3d020106052b8104000a034200042ab77b959e28c4fa47fa8fb9e57cec3d66df5684d076ac2e4c5f28fd69a23dd31a59f908c8add51eab3530b4ac5d015166eaf2198c52fa9a8df7cfaeb8fdb7d46a73656e6465725f7369675840fb5346def1d12b2cc246ff807447b95b4202af7f430f24d9de14ad7035b92c1621bef73f82221e00df12552958f27736e73f550e6aa5768dfac931945ff2d41a';
262262

263263
export const ParsedUnsignedTransaction = {
264264
operations: [

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ import should from 'should';
1111
nock.enableNetConnect();
1212

1313
const bitgo: TestBitGoAPI = TestBitGo.decorate(BitGoAPI, { env: 'test' });
14-
bitgo.safeRegister('ticp', Ticp.createInstance);
14+
bitgo.safeRegister('icp', Icp.createInstance);
1515

1616
describe('Internet computer', function () {
1717
let bitgo;
1818
let basecoin;
19-
const factory = getBuilderFactory('ticp');
19+
const factory = getBuilderFactory('icp');
2020
let txBuilder: any;
2121

2222
before(async function () {
2323
bitgo = TestBitGo.decorate(BitGoAPI, { env: 'test' });
2424
bitgo.safeRegister('icp', Icp.createInstance);
2525
bitgo.safeRegister('ticp', Ticp.createInstance);
2626
bitgo.initializeTestVars();
27-
basecoin = bitgo.coin('ticp');
27+
basecoin = bitgo.coin('icp');
2828

2929
txBuilder = factory.getTransferBuilder();
3030
txBuilder.sender(testData.Accounts.account1.address, testData.Accounts.account1.publicKey);

modules/sdk-core/src/bitgo/environments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ const testnetBase: EnvironmentTemplate = {
363363
flrExplorerBaseUrl: 'https://coston2-explorer.flare.network',
364364
xdcExplorerBaseUrl: 'https://api.etherscan.io/v2',
365365
sgbExplorerBaseUrl: 'https://coston-explorer.flare.network',
366-
icpNodeUrl: 'https://exchanges.testnet.dfinity.network',
366+
icpNodeUrl: 'https://ic0.app',
367367
monExplorerBaseUrl: 'https://api.etherscan.io/v2',
368368
worldExplorerBaseUrl: 'https://sepolia.worldscan.org/',
369369
somniaExplorerBaseUrl: 'https://shannon-explorer.somnia.network/',

0 commit comments

Comments
 (0)