@ledgerhq/coin-internet_computer 1.9.0 → 1.9.1-nightly.1
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +16 -0
- package/lib/api/api.d.ts +6 -11
- package/lib/api/api.d.ts.map +1 -1
- package/lib/api/api.js +84 -64
- package/lib/api/api.js.map +1 -1
- package/lib/bridge/bridgeHelpers/account.d.ts.map +1 -1
- package/lib/bridge/bridgeHelpers/account.js +52 -33
- package/lib/bridge/bridgeHelpers/account.js.map +1 -1
- package/lib/bridge/bridgeHelpers/addresses.d.ts +0 -6
- package/lib/bridge/bridgeHelpers/addresses.d.ts.map +1 -1
- package/lib/bridge/bridgeHelpers/addresses.js +1 -29
- package/lib/bridge/bridgeHelpers/addresses.js.map +1 -1
- package/lib/bridge/broadcast.d.ts.map +1 -1
- package/lib/bridge/broadcast.js +22 -6
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +4 -3
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +2 -1
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.d.ts +2 -2
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +44 -13
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/consts.d.ts +2 -0
- package/lib/consts.d.ts.map +1 -1
- package/lib/consts.js +8 -1
- package/lib/consts.js.map +1 -1
- package/lib/hw-signMessage.d.ts.map +1 -1
- package/lib/hw-signMessage.js +1 -2
- package/lib/hw-signMessage.js.map +1 -1
- package/lib/types/signer.d.ts +1 -1
- package/lib/types/signer.d.ts.map +1 -1
- package/lib-es/api/api.d.ts +6 -11
- package/lib-es/api/api.d.ts.map +1 -1
- package/lib-es/api/api.js +81 -60
- package/lib-es/api/api.js.map +1 -1
- package/lib-es/bridge/bridgeHelpers/account.d.ts.map +1 -1
- package/lib-es/bridge/bridgeHelpers/account.js +52 -33
- package/lib-es/bridge/bridgeHelpers/account.js.map +1 -1
- package/lib-es/bridge/bridgeHelpers/addresses.d.ts +0 -6
- package/lib-es/bridge/bridgeHelpers/addresses.d.ts.map +1 -1
- package/lib-es/bridge/bridgeHelpers/addresses.js +0 -23
- package/lib-es/bridge/bridgeHelpers/addresses.js.map +1 -1
- package/lib-es/bridge/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.js +19 -6
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +2 -1
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +2 -1
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/signOperation.d.ts +2 -2
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +41 -13
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/consts.d.ts +2 -0
- package/lib-es/consts.d.ts.map +1 -1
- package/lib-es/consts.js +3 -0
- package/lib-es/consts.js.map +1 -1
- package/lib-es/hw-signMessage.d.ts.map +1 -1
- package/lib-es/hw-signMessage.js +1 -2
- package/lib-es/hw-signMessage.js.map +1 -1
- package/lib-es/types/signer.d.ts +1 -1
- package/lib-es/types/signer.d.ts.map +1 -1
- package/package.json +7 -13
- package/src/api/api.ts +126 -71
- package/src/bridge/bridgeHelpers/account.ts +70 -43
- package/src/bridge/bridgeHelpers/addresses.ts +0 -25
- package/src/bridge/broadcast.ts +31 -6
- package/src/bridge/getTransactionStatus.ts +2 -1
- package/src/bridge/prepareTransaction.ts +2 -1
- package/src/bridge/signOperation.ts +68 -18
- package/src/consts.ts +10 -0
- package/src/hw-signMessage.ts +1 -6
- package/src/types/signer.ts +1 -1
- package/lib/bridge/bridgeHelpers/icpRosetta/index.d.ts +0 -30
- package/lib/bridge/bridgeHelpers/icpRosetta/index.d.ts.map +0 -1
- package/lib/bridge/bridgeHelpers/icpRosetta/index.js +0 -88
- package/lib/bridge/bridgeHelpers/icpRosetta/index.js.map +0 -1
- package/lib/bridge/bridgeHelpers/icpRosetta/types.d.ts +0 -145
- package/lib/bridge/bridgeHelpers/icpRosetta/types.d.ts.map +0 -1
- package/lib/bridge/bridgeHelpers/icpRosetta/types.js +0 -3
- package/lib/bridge/bridgeHelpers/icpRosetta/types.js.map +0 -1
- package/lib/bridge/bridgeHelpers/icpRosetta/utils.d.ts +0 -17
- package/lib/bridge/bridgeHelpers/icpRosetta/utils.d.ts.map +0 -1
- package/lib/bridge/bridgeHelpers/icpRosetta/utils.js +0 -155
- package/lib/bridge/bridgeHelpers/icpRosetta/utils.js.map +0 -1
- package/lib-es/bridge/bridgeHelpers/icpRosetta/index.d.ts +0 -30
- package/lib-es/bridge/bridgeHelpers/icpRosetta/index.d.ts.map +0 -1
- package/lib-es/bridge/bridgeHelpers/icpRosetta/index.js +0 -76
- package/lib-es/bridge/bridgeHelpers/icpRosetta/index.js.map +0 -1
- package/lib-es/bridge/bridgeHelpers/icpRosetta/types.d.ts +0 -145
- package/lib-es/bridge/bridgeHelpers/icpRosetta/types.d.ts.map +0 -1
- package/lib-es/bridge/bridgeHelpers/icpRosetta/types.js +0 -2
- package/lib-es/bridge/bridgeHelpers/icpRosetta/types.js.map +0 -1
- package/lib-es/bridge/bridgeHelpers/icpRosetta/utils.d.ts +0 -17
- package/lib-es/bridge/bridgeHelpers/icpRosetta/utils.d.ts.map +0 -1
- package/lib-es/bridge/bridgeHelpers/icpRosetta/utils.js +0 -123
- package/lib-es/bridge/bridgeHelpers/icpRosetta/utils.js.map +0 -1
- package/src/bridge/bridgeHelpers/icpRosetta/index.ts +0 -154
- package/src/bridge/bridgeHelpers/icpRosetta/types.ts +0 -166
- package/src/bridge/bridgeHelpers/icpRosetta/utils.ts +0 -151
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import * as cbor from "simple-cbor";
|
|
2
|
-
import { PipeArrayBuffer } from "@dfinity/candid";
|
|
3
|
-
import BigInteger from "big-integer";
|
|
4
|
-
import { getAddress } from "../addresses";
|
|
5
|
-
export const generateOperations = (tr, a) => {
|
|
6
|
-
const { address } = getAddress(a);
|
|
7
|
-
const currency = {
|
|
8
|
-
symbol: "ICP",
|
|
9
|
-
decimals: 8,
|
|
10
|
-
};
|
|
11
|
-
const type = "TRANSACTION";
|
|
12
|
-
const operations = [];
|
|
13
|
-
operations.push({
|
|
14
|
-
operation_identifier: {
|
|
15
|
-
index: 0,
|
|
16
|
-
},
|
|
17
|
-
type,
|
|
18
|
-
account: {
|
|
19
|
-
address,
|
|
20
|
-
},
|
|
21
|
-
amount: {
|
|
22
|
-
value: `-${tr.amount}`,
|
|
23
|
-
currency,
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
operations.push({
|
|
27
|
-
operation_identifier: {
|
|
28
|
-
index: 1,
|
|
29
|
-
},
|
|
30
|
-
type,
|
|
31
|
-
account: {
|
|
32
|
-
address: tr.recipient,
|
|
33
|
-
},
|
|
34
|
-
amount: {
|
|
35
|
-
value: `${tr.amount}`,
|
|
36
|
-
currency,
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
operations.push({
|
|
40
|
-
operation_identifier: {
|
|
41
|
-
index: 2,
|
|
42
|
-
},
|
|
43
|
-
type: "FEE",
|
|
44
|
-
account: {
|
|
45
|
-
address,
|
|
46
|
-
},
|
|
47
|
-
amount: {
|
|
48
|
-
value: `-${tr.fees}`,
|
|
49
|
-
currency,
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
return operations;
|
|
53
|
-
};
|
|
54
|
-
function expiryEncode(val) {
|
|
55
|
-
let value = BigInteger(val.toString());
|
|
56
|
-
if (value < BigInteger(0)) {
|
|
57
|
-
throw new Error("Cannot leb encode negative values.");
|
|
58
|
-
}
|
|
59
|
-
const byteLength = (value === BigInteger(0) ? 0 : Math.ceil(Math.log2(Number(value)))) + 1;
|
|
60
|
-
const pipe = new PipeArrayBuffer(new ArrayBuffer(byteLength), 0);
|
|
61
|
-
// eslint-disable-next-line no-constant-condition
|
|
62
|
-
while (true) {
|
|
63
|
-
const i = Number(value.and(BigInteger(0x7f)));
|
|
64
|
-
value = value.divide(BigInteger(0x80));
|
|
65
|
-
if (value.eq(BigInteger(0))) {
|
|
66
|
-
pipe.write(new Uint8Array([i]));
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
pipe.write(new Uint8Array([i | 0x80]));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return pipe.buffer;
|
|
74
|
-
}
|
|
75
|
-
export class ingressExpiry {
|
|
76
|
-
value;
|
|
77
|
-
constructor(value) {
|
|
78
|
-
// Use bigint because it can overflow the maximum number allowed in a double float.
|
|
79
|
-
this.value = value;
|
|
80
|
-
}
|
|
81
|
-
toCBOR() {
|
|
82
|
-
return cbor.value.u64(this.value.toString(16), 16);
|
|
83
|
-
}
|
|
84
|
-
toHash() {
|
|
85
|
-
return expiryEncode(this.value);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
export const generateSignaturesPayload = (signs, payloads, pubkey) => {
|
|
89
|
-
const signatures = [];
|
|
90
|
-
const [txnPayload, readStatePayload] = payloads;
|
|
91
|
-
signatures.push({
|
|
92
|
-
signing_payload: {
|
|
93
|
-
account_identifier: {
|
|
94
|
-
address: txnPayload.account_identifier.address,
|
|
95
|
-
},
|
|
96
|
-
hex_bytes: txnPayload.hex_bytes,
|
|
97
|
-
signature_type: txnPayload.signature_type,
|
|
98
|
-
},
|
|
99
|
-
public_key: {
|
|
100
|
-
hex_bytes: pubkey,
|
|
101
|
-
curve_type: "secp256k1",
|
|
102
|
-
},
|
|
103
|
-
signature_type: "ecdsa",
|
|
104
|
-
hex_bytes: signs.txnSig,
|
|
105
|
-
});
|
|
106
|
-
signatures.push({
|
|
107
|
-
signing_payload: {
|
|
108
|
-
account_identifier: {
|
|
109
|
-
address: readStatePayload.account_identifier.address,
|
|
110
|
-
},
|
|
111
|
-
hex_bytes: readStatePayload.hex_bytes,
|
|
112
|
-
signature_type: readStatePayload.signature_type,
|
|
113
|
-
},
|
|
114
|
-
public_key: {
|
|
115
|
-
hex_bytes: pubkey,
|
|
116
|
-
curve_type: "secp256k1",
|
|
117
|
-
},
|
|
118
|
-
signature_type: "ecdsa",
|
|
119
|
-
hex_bytes: signs.readSig,
|
|
120
|
-
});
|
|
121
|
-
return signatures;
|
|
122
|
-
};
|
|
123
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/bridge/bridgeHelpers/icpRosetta/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAMpC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,UAAU,MAAM,aAAa,CAAC;AAGrC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,EAAe,EACf,CAAU,EACuB,EAAE;IACnC,MAAM,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,QAAQ,GAAG;QACf,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,CAAC;KACZ,CAAC;IACF,MAAM,IAAI,GAAG,aAAa,CAAC;IAC3B,MAAM,UAAU,GAAoC,EAAE,CAAC;IACvD,UAAU,CAAC,IAAI,CAAC;QACd,oBAAoB,EAAE;YACpB,KAAK,EAAE,CAAC;SACT;QACD,IAAI;QACJ,OAAO,EAAE;YACP,OAAO;SACR;QACD,MAAM,EAAE;YACN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,CAAC,cAAc;SAC1C;QACD,UAAU,EAAE;YACV,SAAS,EAAE,MAAM;YACjB,UAAU,EAAE,WAAW;SACxB;QACD,cAAc,EAAE,OAAO;QACvB,SAAS,EAAE,KAAK,CAAC,MAAM;KACxB,CAAC,CAAC;IAEH,UAAU,CAAC,IAAI,CAAC;QACd,eAAe,EAAE;YACf,kBAAkB,EAAE;gBAClB,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,OAAO;aACrD;YACD,SAAS,EAAE,gBAAgB,CAAC,SAAS;YACrC,cAAc,EAAE,gBAAgB,CAAC,cAAc;SAChD;QACD,UAAU,EAAE;YACV,SAAS,EAAE,MAAM;YACjB,UAAU,EAAE,WAAW;SACxB;QACD,cAAc,EAAE,OAAO;QACvB,SAAS,EAAE,KAAK,CAAC,OAAO;KACzB,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC"}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { Account } from "@ledgerhq/types-live";
|
|
2
|
-
import { Transaction } from "../../../types";
|
|
3
|
-
import { constructionInvoke, getICPRosettaNetworkIdentifier } from "../../../api";
|
|
4
|
-
import {
|
|
5
|
-
ICPRosettaConstructionCombineRequest,
|
|
6
|
-
ICPRosettaConstructionCombineResponse,
|
|
7
|
-
ICPRosettaConstructionHashRequest,
|
|
8
|
-
ICPRosettaConstructionHashResponse,
|
|
9
|
-
ICPRosettaConstructionPayloadsRequest,
|
|
10
|
-
ICPRosettaConstructionPayloadsResponse,
|
|
11
|
-
ICPRosettaConstructionSubmitRequest,
|
|
12
|
-
ICPRosettaConstructionSubmitResponse,
|
|
13
|
-
ICPRosettaConstructionDeriveRequest,
|
|
14
|
-
ICPRosettaConstructionDeriveResponse,
|
|
15
|
-
} from "./types";
|
|
16
|
-
import { ingressExpiry, generateOperations, generateSignaturesPayload } from "./utils";
|
|
17
|
-
import { Cbor } from "@dfinity/agent";
|
|
18
|
-
import { Principal } from "@dfinity/principal";
|
|
19
|
-
import BigNumber from "bignumber.js";
|
|
20
|
-
import { ICP_SEND_TXN_TYPE } from "../../../consts";
|
|
21
|
-
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
22
|
-
import { ICPSigner } from "../../../types";
|
|
23
|
-
|
|
24
|
-
export const getUnsignedTransaction = async (
|
|
25
|
-
transaction: Transaction,
|
|
26
|
-
account: Account,
|
|
27
|
-
): Promise<{
|
|
28
|
-
unsignedTxn: string;
|
|
29
|
-
payloads: ICPRosettaConstructionPayloadsResponse["payloads"];
|
|
30
|
-
}> => {
|
|
31
|
-
const ops = generateOperations(transaction, account);
|
|
32
|
-
const pubkeys = [
|
|
33
|
-
{
|
|
34
|
-
hex_bytes: account.xpub ?? "",
|
|
35
|
-
curve_type: "secp256k1",
|
|
36
|
-
},
|
|
37
|
-
];
|
|
38
|
-
|
|
39
|
-
const reqOpts: ICPRosettaConstructionPayloadsRequest = {
|
|
40
|
-
...getICPRosettaNetworkIdentifier(),
|
|
41
|
-
operations: ops,
|
|
42
|
-
public_keys: pubkeys,
|
|
43
|
-
metadata: {
|
|
44
|
-
memo: parseInt(transaction.memo ?? "0"),
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
const { payloads, unsigned_transaction } = await constructionInvoke<
|
|
48
|
-
ICPRosettaConstructionPayloadsRequest,
|
|
49
|
-
ICPRosettaConstructionPayloadsResponse
|
|
50
|
-
>(reqOpts, "payloads");
|
|
51
|
-
|
|
52
|
-
return { unsignedTxn: unsigned_transaction, payloads };
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const signICPTransaction = async ({
|
|
56
|
-
signerContext,
|
|
57
|
-
deviceId,
|
|
58
|
-
unsignedTxn,
|
|
59
|
-
path,
|
|
60
|
-
payloads,
|
|
61
|
-
pubkey,
|
|
62
|
-
}: {
|
|
63
|
-
signerContext: SignerContext<ICPSigner>;
|
|
64
|
-
deviceId: string;
|
|
65
|
-
unsignedTxn: string;
|
|
66
|
-
path: string;
|
|
67
|
-
payloads: ICPRosettaConstructionPayloadsResponse["payloads"];
|
|
68
|
-
pubkey: string;
|
|
69
|
-
}): Promise<{
|
|
70
|
-
signatures: { txnSig: string; readSig: string };
|
|
71
|
-
signedTxn: string;
|
|
72
|
-
}> => {
|
|
73
|
-
const decodedTxn: any = Cbor.decode(Buffer.from(unsignedTxn, "hex"));
|
|
74
|
-
const txnReqFromCbor = decodedTxn.updates[0][1];
|
|
75
|
-
const expiry = new ingressExpiry(BigNumber(decodedTxn.ingress_expiries[0].toString()));
|
|
76
|
-
|
|
77
|
-
const submitReq = {
|
|
78
|
-
request_type: "call",
|
|
79
|
-
canister_id: Principal.fromUint8Array(txnReqFromCbor.canister_id),
|
|
80
|
-
method_name: txnReqFromCbor.method_name,
|
|
81
|
-
arg: txnReqFromCbor.arg,
|
|
82
|
-
sender: Principal.fromUint8Array(txnReqFromCbor.sender),
|
|
83
|
-
ingress_expiry: expiry,
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const txnBlobToSign = Cbor.encode({
|
|
87
|
-
content: submitReq,
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const { r } = await signerContext(deviceId, async signer => {
|
|
91
|
-
const r = await signer.sign(path, Buffer.from(txnBlobToSign), ICP_SEND_TXN_TYPE);
|
|
92
|
-
return { r };
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
const result = {
|
|
96
|
-
signatures: {
|
|
97
|
-
readSig: "",
|
|
98
|
-
txnSig: Buffer.from(r.signatureRS ?? "").toString("hex"),
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const signaturesPayload = generateSignaturesPayload(result.signatures, payloads, pubkey);
|
|
103
|
-
|
|
104
|
-
const { signed_transaction: signedTxn } = await constructionInvoke<
|
|
105
|
-
ICPRosettaConstructionCombineRequest,
|
|
106
|
-
ICPRosettaConstructionCombineResponse
|
|
107
|
-
>(
|
|
108
|
-
{
|
|
109
|
-
...getICPRosettaNetworkIdentifier(),
|
|
110
|
-
signatures: signaturesPayload,
|
|
111
|
-
unsigned_transaction: unsignedTxn,
|
|
112
|
-
},
|
|
113
|
-
"combine",
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
return { ...result, signedTxn };
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export const getTxnMetadata = async (signedTxn: string): Promise<{ hash: string }> => {
|
|
120
|
-
const {
|
|
121
|
-
transaction_identifier: { hash },
|
|
122
|
-
} = await constructionInvoke<
|
|
123
|
-
ICPRosettaConstructionHashRequest,
|
|
124
|
-
ICPRosettaConstructionHashResponse
|
|
125
|
-
>({ ...getICPRosettaNetworkIdentifier(), signed_transaction: signedTxn }, "hash");
|
|
126
|
-
|
|
127
|
-
return { hash };
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
export const getTxnExpirationDate = (_unsignedTxn: string): Date => {
|
|
131
|
-
return new Date();
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
export const broadcastTxn = async (signedTxn: string) => {
|
|
135
|
-
await constructionInvoke<
|
|
136
|
-
ICPRosettaConstructionSubmitRequest,
|
|
137
|
-
ICPRosettaConstructionSubmitResponse
|
|
138
|
-
>({ ...getICPRosettaNetworkIdentifier(), signed_transaction: signedTxn }, "submit");
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
export const deriveAddressFromPubkey = async (pubkey: string) => {
|
|
142
|
-
const res = await constructionInvoke<
|
|
143
|
-
ICPRosettaConstructionDeriveRequest,
|
|
144
|
-
ICPRosettaConstructionDeriveResponse
|
|
145
|
-
>(
|
|
146
|
-
{
|
|
147
|
-
...getICPRosettaNetworkIdentifier(),
|
|
148
|
-
public_key: { curve_type: "secp256k1", hex_bytes: pubkey },
|
|
149
|
-
},
|
|
150
|
-
"derive",
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
return res.account_identifier.address;
|
|
154
|
-
};
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { SubmitResponse } from "@dfinity/agent";
|
|
2
|
-
|
|
3
|
-
export interface ICPRosettaBlockHeightResponse {
|
|
4
|
-
current_block_identifier: ICPRosettaBlockIdentifier;
|
|
5
|
-
current_block_timestamp: number;
|
|
6
|
-
genesis_block_identifier: ICPRosettaBlockIdentifier;
|
|
7
|
-
sync_status: ICPRosettaSyncstatus;
|
|
8
|
-
peers: any[];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface ICPRosettaBlockIdentifier {
|
|
12
|
-
index: number;
|
|
13
|
-
hash: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface ICPRosettaGetBalancesResponse {
|
|
17
|
-
block_identifier: ICPRosettaBlockIdentifier;
|
|
18
|
-
balances: ICPRosettaBalance[];
|
|
19
|
-
details?: { error_message: string };
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface ICPRosettaBalance {
|
|
23
|
-
value: string;
|
|
24
|
-
currency: ICPRosettaCurrency;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface ICPRosettaCurrency {
|
|
28
|
-
symbol: string;
|
|
29
|
-
decimals: number;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface ICPRosettaSyncstatus {
|
|
33
|
-
current_index: number;
|
|
34
|
-
target_index: number;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface ICPRosettaGetTxnsHistoryResponse {
|
|
38
|
-
transactions: {
|
|
39
|
-
block_identifier: ICPRosettaBlockIdentifier;
|
|
40
|
-
transaction: {
|
|
41
|
-
transaction_identifier: ICPRosettaTransactionidentifier;
|
|
42
|
-
operations: ICPRosettaICPRosettaOperation[];
|
|
43
|
-
metadata: {
|
|
44
|
-
block_height: number;
|
|
45
|
-
memo: number;
|
|
46
|
-
timestamp: number;
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
}[];
|
|
50
|
-
total_count: number;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface ICPRosettaICPRosettaOperation {
|
|
54
|
-
operation_identifier: {
|
|
55
|
-
index: number;
|
|
56
|
-
};
|
|
57
|
-
type: string;
|
|
58
|
-
status?: string;
|
|
59
|
-
account: ICPRosettaAccountIdentifier;
|
|
60
|
-
amount: ICPRosettaBalance;
|
|
61
|
-
metadata?: {
|
|
62
|
-
block_index: number;
|
|
63
|
-
transaction_identifier: ICPRosettaTransactionidentifier;
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export interface ICPRosettaConstructionPayloadsRequest {
|
|
68
|
-
network_identifier: ICPRosettaNetworkIdentifier;
|
|
69
|
-
operations: ICPRosettaICPRosettaOperation[];
|
|
70
|
-
metadata?: ICPRosettaMetadata;
|
|
71
|
-
public_keys: ICPRosettaPublickey[];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface ICPRosettaPublickey {
|
|
75
|
-
hex_bytes: string;
|
|
76
|
-
curve_type: string;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export interface ICPRosettaMetadata {
|
|
80
|
-
memo?: number;
|
|
81
|
-
created_at?: number;
|
|
82
|
-
ingress_end?: number;
|
|
83
|
-
ingress_start?: number;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
interface ICPRosettaCurrency {
|
|
87
|
-
symbol: string;
|
|
88
|
-
decimals: number;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
interface ICPRosettaNetworkIdentifier {
|
|
92
|
-
blockchain: string;
|
|
93
|
-
network: string;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export interface ICPRosettaConstructionPayloadsResponse {
|
|
97
|
-
unsigned_transaction: string;
|
|
98
|
-
payloads: {
|
|
99
|
-
account_identifier: ICPRosettaAccountIdentifier;
|
|
100
|
-
hex_bytes: string;
|
|
101
|
-
signature_type: string;
|
|
102
|
-
}[];
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
interface ICPRosettaAccountIdentifier {
|
|
106
|
-
address: string;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export interface ICPRosettaConstructionCombineRequest {
|
|
110
|
-
network_identifier: ICPRosettaNetworkIdentifier;
|
|
111
|
-
unsigned_transaction: string; // cbor
|
|
112
|
-
signatures: ICPRosettaSignature[];
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export interface ICPRosettaSignature {
|
|
116
|
-
signing_payload: {
|
|
117
|
-
account_identifier: ICPRosettaAccountIdentifier;
|
|
118
|
-
hex_bytes: string;
|
|
119
|
-
signature_type: string;
|
|
120
|
-
};
|
|
121
|
-
public_key: ICPRosettaPublickey;
|
|
122
|
-
signature_type: string;
|
|
123
|
-
hex_bytes: string;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export interface ICPRosettaConstructionCombineResponse {
|
|
127
|
-
signed_transaction: string;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export interface ICPRosettaConstructionSubmitRequest {
|
|
131
|
-
network_identifier: ICPRosettaNetworkIdentifier;
|
|
132
|
-
signed_transaction: string;
|
|
133
|
-
}
|
|
134
|
-
export interface ICPRosettaConstructionSubmitResponse {
|
|
135
|
-
transaction_identifier: ICPRosettaTransactionidentifier;
|
|
136
|
-
metadata: {
|
|
137
|
-
operations: ICPRosettaICPRosettaOperation[];
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
interface ICPRosettaTransactionidentifier {
|
|
142
|
-
hash: string;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export interface ICPRosettaConstructionHashRequest {
|
|
146
|
-
network_identifier: ICPRosettaNetworkIdentifier;
|
|
147
|
-
signed_transaction: string;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export interface ICPRosettaConstructionHashResponse {
|
|
151
|
-
transaction_identifier: ICPRosettaTransactionidentifier;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export interface ICPRosettaBroadcastResult extends SubmitResponse {
|
|
155
|
-
txnHash?: string;
|
|
156
|
-
blockHeight?: string;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export interface ICPRosettaConstructionDeriveRequest {
|
|
160
|
-
network_identifier: ICPRosettaNetworkIdentifier;
|
|
161
|
-
public_key: ICPRosettaPublickey;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export interface ICPRosettaConstructionDeriveResponse {
|
|
165
|
-
account_identifier: ICPRosettaAccountIdentifier;
|
|
166
|
-
}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import * as cbor from "simple-cbor";
|
|
2
|
-
import {
|
|
3
|
-
ICPRosettaConstructionCombineRequest,
|
|
4
|
-
ICPRosettaConstructionPayloadsResponse,
|
|
5
|
-
ICPRosettaICPRosettaOperation,
|
|
6
|
-
} from "./types";
|
|
7
|
-
import { PipeArrayBuffer } from "@dfinity/candid";
|
|
8
|
-
import BigInteger from "big-integer";
|
|
9
|
-
import { Transaction } from "../../../types";
|
|
10
|
-
import { Account } from "@ledgerhq/types-live";
|
|
11
|
-
import { getAddress } from "../addresses";
|
|
12
|
-
import BigNumber from "bignumber.js";
|
|
13
|
-
|
|
14
|
-
export const generateOperations = (
|
|
15
|
-
tr: Transaction,
|
|
16
|
-
a: Account,
|
|
17
|
-
): ICPRosettaICPRosettaOperation[] => {
|
|
18
|
-
const { address } = getAddress(a);
|
|
19
|
-
const currency = {
|
|
20
|
-
symbol: "ICP",
|
|
21
|
-
decimals: 8,
|
|
22
|
-
};
|
|
23
|
-
const type = "TRANSACTION";
|
|
24
|
-
const operations: ICPRosettaICPRosettaOperation[] = [];
|
|
25
|
-
operations.push({
|
|
26
|
-
operation_identifier: {
|
|
27
|
-
index: 0,
|
|
28
|
-
},
|
|
29
|
-
type,
|
|
30
|
-
account: {
|
|
31
|
-
address,
|
|
32
|
-
},
|
|
33
|
-
amount: {
|
|
34
|
-
value: `-${tr.amount}`,
|
|
35
|
-
currency,
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
operations.push({
|
|
40
|
-
operation_identifier: {
|
|
41
|
-
index: 1,
|
|
42
|
-
},
|
|
43
|
-
type,
|
|
44
|
-
account: {
|
|
45
|
-
address: tr.recipient,
|
|
46
|
-
},
|
|
47
|
-
amount: {
|
|
48
|
-
value: `${tr.amount}`,
|
|
49
|
-
currency,
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
operations.push({
|
|
54
|
-
operation_identifier: {
|
|
55
|
-
index: 2,
|
|
56
|
-
},
|
|
57
|
-
type: "FEE",
|
|
58
|
-
account: {
|
|
59
|
-
address,
|
|
60
|
-
},
|
|
61
|
-
amount: {
|
|
62
|
-
value: `-${tr.fees}`,
|
|
63
|
-
currency,
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
return operations;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
function expiryEncode(val: BigNumber): ArrayBuffer {
|
|
71
|
-
let value = BigInteger(val.toString());
|
|
72
|
-
|
|
73
|
-
if (value < BigInteger(0)) {
|
|
74
|
-
throw new Error("Cannot leb encode negative values.");
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const byteLength = (value === BigInteger(0) ? 0 : Math.ceil(Math.log2(Number(value)))) + 1;
|
|
78
|
-
const pipe = new PipeArrayBuffer(new ArrayBuffer(byteLength), 0);
|
|
79
|
-
// eslint-disable-next-line no-constant-condition
|
|
80
|
-
while (true) {
|
|
81
|
-
const i = Number(value.and(BigInteger(0x7f)));
|
|
82
|
-
value = value.divide(BigInteger(0x80));
|
|
83
|
-
if (value.eq(BigInteger(0))) {
|
|
84
|
-
pipe.write(new Uint8Array([i]));
|
|
85
|
-
break;
|
|
86
|
-
} else {
|
|
87
|
-
pipe.write(new Uint8Array([i | 0x80]));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return pipe.buffer;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export class ingressExpiry {
|
|
95
|
-
value: BigNumber;
|
|
96
|
-
|
|
97
|
-
constructor(value: BigNumber) {
|
|
98
|
-
// Use bigint because it can overflow the maximum number allowed in a double float.
|
|
99
|
-
this.value = value;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
public toCBOR(): cbor.CborValue {
|
|
103
|
-
return cbor.value.u64(this.value.toString(16), 16);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
public toHash(): ArrayBuffer {
|
|
107
|
-
return expiryEncode(this.value);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export const generateSignaturesPayload = (
|
|
112
|
-
signs: { txnSig: string; readSig: string },
|
|
113
|
-
payloads: ICPRosettaConstructionPayloadsResponse["payloads"],
|
|
114
|
-
pubkey: string,
|
|
115
|
-
): ICPRosettaConstructionCombineRequest["signatures"] => {
|
|
116
|
-
const signatures: ICPRosettaConstructionCombineRequest["signatures"] = [];
|
|
117
|
-
const [txnPayload, readStatePayload] = payloads;
|
|
118
|
-
signatures.push({
|
|
119
|
-
signing_payload: {
|
|
120
|
-
account_identifier: {
|
|
121
|
-
address: txnPayload.account_identifier.address,
|
|
122
|
-
},
|
|
123
|
-
hex_bytes: txnPayload.hex_bytes,
|
|
124
|
-
signature_type: txnPayload.signature_type,
|
|
125
|
-
},
|
|
126
|
-
public_key: {
|
|
127
|
-
hex_bytes: pubkey,
|
|
128
|
-
curve_type: "secp256k1",
|
|
129
|
-
},
|
|
130
|
-
signature_type: "ecdsa",
|
|
131
|
-
hex_bytes: signs.txnSig,
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
signatures.push({
|
|
135
|
-
signing_payload: {
|
|
136
|
-
account_identifier: {
|
|
137
|
-
address: readStatePayload.account_identifier.address,
|
|
138
|
-
},
|
|
139
|
-
hex_bytes: readStatePayload.hex_bytes,
|
|
140
|
-
signature_type: readStatePayload.signature_type,
|
|
141
|
-
},
|
|
142
|
-
public_key: {
|
|
143
|
-
hex_bytes: pubkey,
|
|
144
|
-
curve_type: "secp256k1",
|
|
145
|
-
},
|
|
146
|
-
signature_type: "ecdsa",
|
|
147
|
-
hex_bytes: signs.readSig,
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
return signatures;
|
|
151
|
-
};
|