@airgap/icp 0.13.15-beta.0 → 0.13.15-beta.10

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.
Files changed (90) hide show
  1. package/package.json +8 -6
  2. package/v1/block-explorer/ICPBlockExplorer.js +16 -51
  3. package/v1/block-explorer/ICPBlockExplorer.js.map +1 -1
  4. package/v1/index.d.ts +3 -2
  5. package/v1/index.js +9 -5
  6. package/v1/index.js.map +1 -1
  7. package/v1/module/ICPModule.js +53 -94
  8. package/v1/module/ICPModule.js.map +1 -1
  9. package/v1/module.js +1 -1
  10. package/v1/module.js.map +1 -1
  11. package/v1/protocol/ICPGovernance.d.ts +39 -0
  12. package/v1/protocol/ICPGovernance.js +1177 -0
  13. package/v1/protocol/ICPGovernance.js.map +1 -0
  14. package/v1/protocol/ICPImplementation.d.ts +30 -5
  15. package/v1/protocol/ICPImplementation.js +317 -252
  16. package/v1/protocol/ICPImplementation.js.map +1 -1
  17. package/v1/protocol/ICPProtocol.d.ts +58 -6
  18. package/v1/protocol/ICPProtocol.js +764 -318
  19. package/v1/protocol/ICPProtocol.js.map +1 -1
  20. package/v1/protocol/icrc/CkBTCProtocol.js +137 -223
  21. package/v1/protocol/icrc/CkBTCProtocol.js.map +1 -1
  22. package/v1/protocol/icrc/ICRC1Protocol.js +338 -553
  23. package/v1/protocol/icrc/ICRC1Protocol.js.map +1 -1
  24. package/v1/serializer/v3/schemas/converter/transaction-converter.js +48 -5
  25. package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
  26. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.d.ts +8 -2
  27. package/v1/serializer/v3/schemas/generated/transaction-sign-request-icp.json +31 -1
  28. package/v1/serializer/v3/serializer-companion.js +85 -144
  29. package/v1/serializer/v3/serializer-companion.js.map +1 -1
  30. package/v1/serializer/v3/validators/transaction-validator.js +22 -60
  31. package/v1/serializer/v3/validators/transaction-validator.js.map +1 -1
  32. package/v1/serializer/v3/validators/validators.js +19 -58
  33. package/v1/serializer/v3/validators/validators.js.map +1 -1
  34. package/v1/types/governance.d.ts +29 -0
  35. package/v1/types/governance.js +279 -210
  36. package/v1/types/governance.js.map +1 -1
  37. package/v1/types/icrc/ledger.js +22 -23
  38. package/v1/types/icrc/ledger.js.map +1 -1
  39. package/v1/types/ledger.d.ts +1 -0
  40. package/v1/types/ledger.js +37 -38
  41. package/v1/types/ledger.js.map +1 -1
  42. package/v1/types/management_idl.js +6 -7
  43. package/v1/types/management_idl.js.map +1 -1
  44. package/v1/types/protocol.d.ts +1 -0
  45. package/v1/types/transaction.d.ts +22 -3
  46. package/v1/types/transaction.js +38 -0
  47. package/v1/types/transaction.js.map +1 -1
  48. package/v1/utils/account.js +42 -70
  49. package/v1/utils/account.js.map +1 -1
  50. package/v1/utils/actor.js +139 -322
  51. package/v1/utils/actor.js.map +1 -1
  52. package/v1/utils/auth.js +44 -134
  53. package/v1/utils/auth.js.map +1 -1
  54. package/v1/utils/bls.js +41 -109
  55. package/v1/utils/bls.js.map +1 -1
  56. package/v1/utils/buffer.js +47 -111
  57. package/v1/utils/buffer.js.map +1 -1
  58. package/v1/utils/cbor.js +50 -85
  59. package/v1/utils/cbor.js.map +1 -1
  60. package/v1/utils/certificate.js +116 -238
  61. package/v1/utils/certificate.js.map +1 -1
  62. package/v1/utils/convert.d.ts +1 -1
  63. package/v1/utils/convert.js +29 -49
  64. package/v1/utils/convert.js.map +1 -1
  65. package/v1/utils/der.js +37 -35
  66. package/v1/utils/der.js.map +1 -1
  67. package/v1/utils/errors.js +10 -30
  68. package/v1/utils/errors.js.map +1 -1
  69. package/v1/utils/hdkey.js +33 -33
  70. package/v1/utils/hdkey.js.map +1 -1
  71. package/v1/utils/http.d.ts +1 -1
  72. package/v1/utils/http.js +202 -426
  73. package/v1/utils/http.js.map +1 -1
  74. package/v1/utils/icrc1.js +24 -41
  75. package/v1/utils/icrc1.js.map +1 -1
  76. package/v1/utils/idl.js +780 -1159
  77. package/v1/utils/idl.js.map +1 -1
  78. package/v1/utils/json.d.ts +1 -0
  79. package/v1/utils/json.js +19 -0
  80. package/v1/utils/json.js.map +1 -0
  81. package/v1/utils/leb128.js +29 -30
  82. package/v1/utils/leb128.js.map +1 -1
  83. package/v1/utils/polling.js +84 -234
  84. package/v1/utils/polling.js.map +1 -1
  85. package/v1/utils/principal.js +78 -126
  86. package/v1/utils/principal.js.map +1 -1
  87. package/v1/utils/secp256k1.js +68 -134
  88. package/v1/utils/secp256k1.js.map +1 -1
  89. package/v1/utils/transaction.js +7 -7
  90. package/v1/utils/transaction.js.map +1 -1
@@ -0,0 +1,1177 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.getDetailsFromSignedDisburse = exports.signDisburse = exports.getDetailsFromUnsignedDisburse = exports.prepareDisburse = exports.getDetailsFromSignedFollowNeuron = exports.signFollowNeuron = exports.getDetailsFromUnsignedFollowNeuron = exports.prepareFollowNeuron = exports.getDetailsFromSignedAutoStakeMaturity = exports.signAutoStakeMaturity = exports.getDetailsFromUnsignedAutoStakeMaturity = exports.prepareAutoStakeMaturity = exports.getDetailsFromSignedStopDissolving = exports.signStopDissolving = exports.getDetailsFromUnsignedStopDissolving = exports.prepareStopDissolving = exports.getDetailsFromSignedStartDissolving = exports.signStartDissolving = exports.getDetailsFromUnsignedStartDissolving = exports.prepareStartDissolving = exports.getDetailsFromSignedIncreaseDissolveDelay = exports.signIncreaseDissolveDelay = exports.getDetailsFromUnsignedIncreaseDissolveDelay = exports.prepareIncreaseDissolveDelay = exports.getDetailsFromSignedClaimGovernance = exports.signClaimGovernance = exports.getDetailsFromUnsignedClaimGovernance = exports.prepareClaimOrRefreshNeuron = exports.getDetailsFromSignedTransferToSubaccount = exports.signTransferToSubaccount = exports.getDetailsFromUnsignedTransferToSubaccount = exports.prepareTransferToSubaccount = exports.getDetailsFromSignedGetNeuronInfo = exports.signGetNeuronInfo = exports.getDetailsFromUnsignedGetNeuronInfo = exports.prepareGetNeuronInfo = void 0;
36
+ const module_kit_1 = require("@airgap/module-kit");
37
+ const transaction_1 = require("../types/transaction");
38
+ const account_1 = require("../utils/account");
39
+ const Cbor = __importStar(require("../utils/cbor"));
40
+ const convert_1 = require("../utils/convert");
41
+ const IDL = __importStar(require("../utils/idl"));
42
+ const json_1 = require("../utils/json");
43
+ const principal_1 = require("../utils/principal");
44
+ const ICPImplementation_1 = require("./ICPImplementation");
45
+ // GET_NEURON_INFO
46
+ // CANISTER : (name: NNS Governance, identifier: rrkah-fqaaa-aaaaa-aaaaq-cai)
47
+ // METHOD : (name: list_neurons, type: query)
48
+ // PAYLOAD : (neuron_ids : {}, include_neurons_readable_by_caller : true)
49
+ // RESPONSE :
50
+ // root : {
51
+ // neuron_infos : [
52
+ // [
53
+ // neuronId : float,
54
+ // {
55
+ // dissolve_delay_seconds: int,
56
+ // recent_ballots: [],
57
+ // created_timestamp_seconds: int,
58
+ // state: int,
59
+ // stake_e8s: int,
60
+ // joined_community_fund_timestamp_seconds: [],
61
+ // retrieved_at_timestamp_seconds: int,
62
+ // known_neuron_data:[],
63
+ // voting_power: int,
64
+ // age_seconds: int
65
+ // }
66
+ // ]
67
+ // ],
68
+ // full_neurons : [
69
+ // {
70
+ // id: [],
71
+ // staked_maturity_e8s_equivalent: [],
72
+ // controller: [],
73
+ // recent_ballots: [],
74
+ // kyc_verified: bool,
75
+ // not_for_profit: bool,
76
+ // maturity_e8s_equivalent: int,
77
+ // cached_neuron_stake_e8s: int,
78
+ // created_timestamp_seconds: int,
79
+ // auto_stake_maturity: [],
80
+ // aging_since_timestamp_seconds: float,
81
+ // hot_keys: [],
82
+ // account: {},
83
+ // joined_community_fund_timestamp_seconds: [],
84
+ // dissolve_state: [],
85
+ // followees: [],
86
+ // neuron_fees_e8s: int,
87
+ // transfer: [],
88
+ // known_neuron_data: [],
89
+ // spawn_at_timestamp_seconds: []
90
+ // }
91
+ // ]
92
+ // }
93
+ function prepareGetNeuronInfo() {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ // Does not need to create a transaction as it is only a call to the governance token
96
+ return [
97
+ {
98
+ actionType: transaction_1.ICPActionType.GET_NEURON_INFO,
99
+ encoded: ''
100
+ }
101
+ ];
102
+ });
103
+ }
104
+ exports.prepareGetNeuronInfo = prepareGetNeuronInfo;
105
+ function getDetailsFromUnsignedGetNeuronInfo(publicKey, network) {
106
+ // Does not need info from transaction because it is only a call to the governance canister
107
+ return [
108
+ {
109
+ from: [(0, ICPImplementation_1.getAddressFromPublicKey)(publicKey)],
110
+ to: [network.governanceCanisterId],
111
+ isInbound: false,
112
+ amount: (0, module_kit_1.newAmount)('0', 'blockchain'),
113
+ fee: (0, module_kit_1.newAmount)('0', 'blockchain'),
114
+ network,
115
+ type: transaction_1.ICPActionType.GET_NEURON_INFO
116
+ }
117
+ ];
118
+ }
119
+ exports.getDetailsFromUnsignedGetNeuronInfo = getDetailsFromUnsignedGetNeuronInfo;
120
+ function signGetNeuronInfo(_unsignedTransaction, privateKey, canisterId) {
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ const NeuronIdOrSubaccount = IDL.Variant({
123
+ Subaccount: IDL.Vec(IDL.Nat8)
124
+ });
125
+ const { subAccount } = (0, ICPImplementation_1.getFixedSubaccountFromPrivateKey)(privateKey);
126
+ const args = IDL.encode([NeuronIdOrSubaccount], [{ Subaccount: subAccount.toUint8Array() }]);
127
+ const signedTransaction = (0, ICPImplementation_1.signTransaction)(privateKey, canisterId, args, 'get_full_neuron_by_id_or_subaccount', 'query');
128
+ return signedTransaction;
129
+ });
130
+ }
131
+ exports.signGetNeuronInfo = signGetNeuronInfo;
132
+ function getDetailsFromSignedGetNeuronInfo(encoded, publicKey, network) {
133
+ const NeuronIdOrSubaccount = IDL.Variant({
134
+ Subaccount: IDL.Vec(IDL.Nat8)
135
+ });
136
+ const cborDecoded = Cbor.decode((0, convert_1.hexStringToArrayBuffer)(encoded));
137
+ const neuronIdOrSubaccount = IDL.decode([NeuronIdOrSubaccount], cborDecoded.content.arg)[0];
138
+ return [
139
+ {
140
+ from: [(0, ICPImplementation_1.getAddressFromPublicKey)(publicKey)],
141
+ to: [network.governanceCanisterId],
142
+ isInbound: false,
143
+ amount: (0, module_kit_1.newAmount)('0', 'blockchain'),
144
+ fee: (0, module_kit_1.newAmount)('0', 'blockchain'),
145
+ network,
146
+ type: transaction_1.ICPActionType.GET_NEURON_INFO,
147
+ json: Object.assign(Object.assign({}, cborDecoded.content), { arg: (0, json_1.idlDecodedToJsonStringifiable)(neuronIdOrSubaccount) })
148
+ }
149
+ ];
150
+ }
151
+ exports.getDetailsFromSignedGetNeuronInfo = getDetailsFromSignedGetNeuronInfo;
152
+ // TRANSFER_TO_SUBACCOUNT
153
+ // CANISTER : (name: NNS Ledger, identifier: ryjl3-tyaaa-aaaaa-aaaba-cai)
154
+ // METHOD : (name: transfer, type: update)
155
+ // PAYLOAD : (to : {}, fee : {e8s: int}, memo: int, from_subaccount: [], created_at_time: [{timestamp_nanos : float}], amount: {e8s: int})
156
+ // RESPONSE : (Ok : int)
157
+ function prepareTransferToSubaccount(publicKey, canisterId, amount, fee) {
158
+ return __awaiter(this, void 0, void 0, function* () {
159
+ // Create subaccount from publicKey
160
+ const { subAccount, nonce } = (0, ICPImplementation_1.getFixedSubaccountFromPublicKey)(publicKey);
161
+ const accountIdentifier = account_1.AccountIdentifier.fromPrincipal({
162
+ principal: principal_1.Principal.from(canisterId),
163
+ subAccount: subAccount
164
+ });
165
+ const unsignedTransfer = (0, ICPImplementation_1.createUnsignedTransaction)({
166
+ memo: nonce,
167
+ amount,
168
+ to: accountIdentifier.toHex(),
169
+ fee
170
+ });
171
+ return [
172
+ {
173
+ actionType: transaction_1.ICPActionType.TRANSFER_TO_SUBACCOUNT,
174
+ encoded: unsignedTransfer
175
+ }
176
+ ];
177
+ });
178
+ }
179
+ exports.prepareTransferToSubaccount = prepareTransferToSubaccount;
180
+ function getDetailsFromUnsignedTransferToSubaccount(unsignedTransaction, publicKey, network) {
181
+ const info = (0, ICPImplementation_1.getInfoFromUnsignedTransaction)(unsignedTransaction);
182
+ return [
183
+ {
184
+ from: [(0, ICPImplementation_1.getAddressFromPublicKey)(publicKey)],
185
+ to: [info.to],
186
+ isInbound: false,
187
+ amount: (0, module_kit_1.newAmount)(info.amount.toString(), 'blockchain'),
188
+ fee: (0, module_kit_1.newAmount)(info.fee.toString(), 'blockchain'),
189
+ network,
190
+ type: transaction_1.ICPActionType.TRANSFER_TO_SUBACCOUNT,
191
+ json: (0, json_1.idlDecodedToJsonStringifiable)(info.json)
192
+ }
193
+ ];
194
+ }
195
+ exports.getDetailsFromUnsignedTransferToSubaccount = getDetailsFromUnsignedTransferToSubaccount;
196
+ function signTransferToSubaccount(unsignedTransaction, privateKey, canisterId) {
197
+ return __awaiter(this, void 0, void 0, function* () {
198
+ return (0, ICPImplementation_1.signTransactionTransfer)(unsignedTransaction, privateKey, canisterId);
199
+ });
200
+ }
201
+ exports.signTransferToSubaccount = signTransferToSubaccount;
202
+ function getDetailsFromSignedTransferToSubaccount(signedTransaction, publicKey, network) {
203
+ const info = (0, ICPImplementation_1.getDetailsFromSignedTransactionTransfer)(signedTransaction, publicKey, network);
204
+ return info.map((tx) => (Object.assign(Object.assign({}, tx), { type: transaction_1.ICPActionType.TRANSFER_TO_SUBACCOUNT })));
205
+ }
206
+ exports.getDetailsFromSignedTransferToSubaccount = getDetailsFromSignedTransferToSubaccount;
207
+ // CLAIM_GOVERNANCE ?
208
+ // CANISTER : (name: NNS Governance, identifier: rrkah-fqaaa-aaaaa-aaaaq-cai)
209
+ // METHOD : (name: claim_or_refresh_neuron_from_account, type: call)
210
+ function prepareClaimOrRefreshNeuron(publicKey) {
211
+ return __awaiter(this, void 0, void 0, function* () {
212
+ // Create subaccount from publicKey
213
+ const { nonce } = (0, ICPImplementation_1.getFixedSubaccountFromPublicKey)(publicKey);
214
+ // Get Principal from public key
215
+ const principal = (0, ICPImplementation_1.getPrincipalFromPublicKey)(publicKey);
216
+ // IDL for ManageNeuron
217
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
218
+ const ClaimOrRefreshNeuronFromAccount = IDL.Record({
219
+ controller: IDL.Opt(IDL.Principal),
220
+ memo: IDL.Nat64
221
+ });
222
+ const By = IDL.Variant({
223
+ NeuronIdOrSubaccount: IDL.Record({}),
224
+ MemoAndController: ClaimOrRefreshNeuronFromAccount,
225
+ Memo: IDL.Nat64
226
+ });
227
+ const ClaimOrRefresh = IDL.Record({ by: IDL.Opt(By) });
228
+ const Command = IDL.Variant({
229
+ ClaimOrRefresh: ClaimOrRefresh
230
+ });
231
+ const NeuronIdOrSubaccount = IDL.Variant({
232
+ Subaccount: IDL.Vec(IDL.Nat8),
233
+ NeuronId: NeuronId
234
+ });
235
+ const ManageNeuron = IDL.Record({
236
+ id: IDL.Opt(NeuronId),
237
+ command: IDL.Opt(Command),
238
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
239
+ });
240
+ // Encode
241
+ const unsignedTransactionBuffer = IDL.encode([ManageNeuron], [
242
+ {
243
+ id: [],
244
+ command: [
245
+ {
246
+ ClaimOrRefresh: {
247
+ by: [
248
+ {
249
+ MemoAndController: { controller: [principal], memo: nonce }
250
+ }
251
+ ]
252
+ }
253
+ }
254
+ ],
255
+ neuron_id_or_subaccount: []
256
+ }
257
+ ]);
258
+ return [
259
+ {
260
+ actionType: transaction_1.ICPActionType.CLAIM_GOVERNANCE,
261
+ encoded: (0, convert_1.arrayBufferToHexString)(unsignedTransactionBuffer)
262
+ }
263
+ ];
264
+ });
265
+ }
266
+ exports.prepareClaimOrRefreshNeuron = prepareClaimOrRefreshNeuron;
267
+ function getDetailsFromUnsignedClaimGovernance(encoded, publicKey, network) {
268
+ // IDL for ManageNeuron
269
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
270
+ const ClaimOrRefreshNeuronFromAccount = IDL.Record({
271
+ controller: IDL.Opt(IDL.Principal),
272
+ memo: IDL.Nat64
273
+ });
274
+ const By = IDL.Variant({
275
+ NeuronIdOrSubaccount: IDL.Record({}),
276
+ MemoAndController: ClaimOrRefreshNeuronFromAccount,
277
+ Memo: IDL.Nat64
278
+ });
279
+ const ClaimOrRefresh = IDL.Record({ by: IDL.Opt(By) });
280
+ const Command = IDL.Variant({
281
+ ClaimOrRefresh: ClaimOrRefresh
282
+ });
283
+ const NeuronIdOrSubaccount = IDL.Variant({
284
+ Subaccount: IDL.Vec(IDL.Nat8),
285
+ NeuronId: NeuronId
286
+ });
287
+ const ManageNeuron = IDL.Record({
288
+ id: IDL.Opt(NeuronId),
289
+ command: IDL.Opt(Command),
290
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
291
+ });
292
+ const manageNeuron = IDL.decode([ManageNeuron], (0, convert_1.hexStringToArrayBuffer)(encoded))[0];
293
+ return [
294
+ {
295
+ from: [(0, ICPImplementation_1.getAddressFromPublicKey)(publicKey)],
296
+ to: [network.governanceCanisterId],
297
+ isInbound: false,
298
+ amount: (0, module_kit_1.newAmount)('0', 'blockchain'),
299
+ fee: (0, module_kit_1.newAmount)('0', 'blockchain'),
300
+ network,
301
+ type: transaction_1.ICPActionType.CLAIM_GOVERNANCE,
302
+ json: {
303
+ ManageNeuron: (0, json_1.idlDecodedToJsonStringifiable)(manageNeuron)
304
+ }
305
+ }
306
+ ];
307
+ }
308
+ exports.getDetailsFromUnsignedClaimGovernance = getDetailsFromUnsignedClaimGovernance;
309
+ function signClaimGovernance(unsignedTransaction, privateKey, canisterId) {
310
+ return __awaiter(this, void 0, void 0, function* () {
311
+ // unsignedTransaction has already the arguments needed for signing, just need to be in a Buffer
312
+ const args = (0, convert_1.hexStringToArrayBuffer)(unsignedTransaction);
313
+ // Sign transaction
314
+ const signedTransaction = (0, ICPImplementation_1.signTransaction)(privateKey, canisterId, args, 'manage_neuron', 'call');
315
+ return signedTransaction;
316
+ });
317
+ }
318
+ exports.signClaimGovernance = signClaimGovernance;
319
+ function getDetailsFromSignedClaimGovernance(encoded, publicKey, network) {
320
+ // IDL for ManageNeuron
321
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
322
+ const ClaimOrRefreshNeuronFromAccount = IDL.Record({
323
+ controller: IDL.Opt(IDL.Principal),
324
+ memo: IDL.Nat64
325
+ });
326
+ const By = IDL.Variant({
327
+ NeuronIdOrSubaccount: IDL.Record({}),
328
+ MemoAndController: ClaimOrRefreshNeuronFromAccount,
329
+ Memo: IDL.Nat64
330
+ });
331
+ const ClaimOrRefresh = IDL.Record({ by: IDL.Opt(By) });
332
+ const Command = IDL.Variant({
333
+ ClaimOrRefresh: ClaimOrRefresh
334
+ });
335
+ const NeuronIdOrSubaccount = IDL.Variant({
336
+ Subaccount: IDL.Vec(IDL.Nat8),
337
+ NeuronId: NeuronId
338
+ });
339
+ const ManageNeuron = IDL.Record({
340
+ id: IDL.Opt(NeuronId),
341
+ command: IDL.Opt(Command),
342
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
343
+ });
344
+ const cborDecoded = Cbor.decode((0, convert_1.hexStringToArrayBuffer)(encoded));
345
+ const manageNeuron = IDL.decode([ManageNeuron], cborDecoded.content.arg)[0];
346
+ return [
347
+ {
348
+ from: [(0, ICPImplementation_1.getAddressFromPublicKey)(publicKey)],
349
+ to: [network.governanceCanisterId],
350
+ isInbound: false,
351
+ amount: (0, module_kit_1.newAmount)('0', 'blockchain'),
352
+ fee: (0, module_kit_1.newAmount)('0', 'blockchain'),
353
+ network,
354
+ type: transaction_1.ICPActionType.CLAIM_GOVERNANCE,
355
+ json: Object.assign(Object.assign({}, cborDecoded.content), { arg: (0, json_1.idlDecodedToJsonStringifiable)(manageNeuron) })
356
+ }
357
+ ];
358
+ }
359
+ exports.getDetailsFromSignedClaimGovernance = getDetailsFromSignedClaimGovernance;
360
+ // INCREASE_DISSOLVE_DELAY
361
+ // CANISTER : (name: NNS Governance, identifier: rrkah-fqaaa-aaaaa-aaaaq-cai)
362
+ // METHOD : (name: manage_neuron, type: update)
363
+ // PAYLOAD : (id : [{id : float}], command : [{Configure : {operation : [{IncreaseDissolveDelay : {additional_dissolve_delay_seconds : int}}]}}], neuron_id_or_subaccount : [])
364
+ // RESPONSE : (command : [{configure : {}}])
365
+ function prepareIncreaseDissolveDelay(publicKey, additionalDissolveDelay) {
366
+ return __awaiter(this, void 0, void 0, function* () {
367
+ // Create subaccount from publicKey
368
+ const { subAccount, nonce: _ } = (0, ICPImplementation_1.getFixedSubaccountFromPublicKey)(publicKey);
369
+ // IDL for IncreaseDissolveDelay
370
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
371
+ const IncreaseDissolveDelay = IDL.Record({
372
+ additional_dissolve_delay_seconds: IDL.Nat32
373
+ });
374
+ const Operation = IDL.Variant({
375
+ IncreaseDissolveDelay: IncreaseDissolveDelay
376
+ });
377
+ const Configure = IDL.Record({ operation: IDL.Opt(Operation) });
378
+ const Command = IDL.Variant({
379
+ Configure: Configure
380
+ });
381
+ const NeuronIdOrSubaccount = IDL.Variant({
382
+ Subaccount: IDL.Vec(IDL.Nat8),
383
+ NeuronId: NeuronId
384
+ });
385
+ const ManageNeuron = IDL.Record({
386
+ id: IDL.Opt(NeuronId),
387
+ command: IDL.Opt(Command),
388
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
389
+ });
390
+ // Encode
391
+ const unsignedTransactionBuffer = IDL.encode([ManageNeuron], [
392
+ {
393
+ id: [],
394
+ command: [
395
+ {
396
+ Configure: {
397
+ operation: [
398
+ {
399
+ IncreaseDissolveDelay: { additional_dissolve_delay_seconds: additionalDissolveDelay }
400
+ }
401
+ ]
402
+ }
403
+ }
404
+ ],
405
+ neuron_id_or_subaccount: [{ Subaccount: subAccount.toUint8Array() }]
406
+ }
407
+ ]);
408
+ return [
409
+ {
410
+ actionType: transaction_1.ICPActionType.INCREASE_DISSOLVE_DELAY,
411
+ encoded: (0, convert_1.arrayBufferToHexString)(unsignedTransactionBuffer)
412
+ }
413
+ ];
414
+ });
415
+ }
416
+ exports.prepareIncreaseDissolveDelay = prepareIncreaseDissolveDelay;
417
+ function getDetailsFromUnsignedIncreaseDissolveDelay(encoded, publicKey, network) {
418
+ // IDL for IncreaseDissolveDelay
419
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
420
+ const IncreaseDissolveDelay = IDL.Record({
421
+ additional_dissolve_delay_seconds: IDL.Nat32
422
+ });
423
+ const Operation = IDL.Variant({
424
+ IncreaseDissolveDelay: IncreaseDissolveDelay
425
+ });
426
+ const Configure = IDL.Record({ operation: IDL.Opt(Operation) });
427
+ const Command = IDL.Variant({
428
+ Configure: Configure
429
+ });
430
+ const NeuronIdOrSubaccount = IDL.Variant({
431
+ Subaccount: IDL.Vec(IDL.Nat8),
432
+ NeuronId: NeuronId
433
+ });
434
+ const ManageNeuron = IDL.Record({
435
+ id: IDL.Opt(NeuronId),
436
+ command: IDL.Opt(Command),
437
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
438
+ });
439
+ const manageNeuron = IDL.decode([ManageNeuron], (0, convert_1.hexStringToArrayBuffer)(encoded))[0];
440
+ return [
441
+ {
442
+ from: [(0, ICPImplementation_1.getAddressFromPublicKey)(publicKey)],
443
+ to: [network.governanceCanisterId],
444
+ isInbound: false,
445
+ amount: (0, module_kit_1.newAmount)('0', 'blockchain'),
446
+ fee: (0, module_kit_1.newAmount)('0', 'blockchain'),
447
+ network,
448
+ type: transaction_1.ICPActionType.INCREASE_DISSOLVE_DELAY,
449
+ json: {
450
+ ManageNeuron: (0, json_1.idlDecodedToJsonStringifiable)(manageNeuron)
451
+ }
452
+ }
453
+ ];
454
+ }
455
+ exports.getDetailsFromUnsignedIncreaseDissolveDelay = getDetailsFromUnsignedIncreaseDissolveDelay;
456
+ function signIncreaseDissolveDelay(unsignedTransaction, privateKey, canisterId) {
457
+ return __awaiter(this, void 0, void 0, function* () {
458
+ // unsignedTransaction has already the arguments needed for signing, just need to be in a Buffer
459
+ const args = (0, convert_1.hexStringToArrayBuffer)(unsignedTransaction);
460
+ // Sign transaction
461
+ const signedTransaction = (0, ICPImplementation_1.signTransaction)(privateKey, canisterId, args, 'manage_neuron', 'call');
462
+ return signedTransaction;
463
+ });
464
+ }
465
+ exports.signIncreaseDissolveDelay = signIncreaseDissolveDelay;
466
+ function getDetailsFromSignedIncreaseDissolveDelay(encoded, publicKey, network) {
467
+ // IDL for IncreaseDissolveDelay
468
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
469
+ const IncreaseDissolveDelay = IDL.Record({
470
+ additional_dissolve_delay_seconds: IDL.Nat32
471
+ });
472
+ const Operation = IDL.Variant({
473
+ IncreaseDissolveDelay: IncreaseDissolveDelay
474
+ });
475
+ const Configure = IDL.Record({ operation: IDL.Opt(Operation) });
476
+ const Command = IDL.Variant({
477
+ Configure: Configure
478
+ });
479
+ const NeuronIdOrSubaccount = IDL.Variant({
480
+ Subaccount: IDL.Vec(IDL.Nat8),
481
+ NeuronId: NeuronId
482
+ });
483
+ const ManageNeuron = IDL.Record({
484
+ id: IDL.Opt(NeuronId),
485
+ command: IDL.Opt(Command),
486
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
487
+ });
488
+ const cborDecoded = Cbor.decode((0, convert_1.hexStringToArrayBuffer)(encoded));
489
+ const manageNeuron = IDL.decode([ManageNeuron], cborDecoded.content.arg)[0];
490
+ return [
491
+ {
492
+ from: [(0, ICPImplementation_1.getAddressFromPublicKey)(publicKey)],
493
+ to: [network.governanceCanisterId],
494
+ isInbound: false,
495
+ amount: (0, module_kit_1.newAmount)('0', 'blockchain'),
496
+ fee: (0, module_kit_1.newAmount)('0', 'blockchain'),
497
+ network,
498
+ type: transaction_1.ICPActionType.INCREASE_DISSOLVE_DELAY,
499
+ json: Object.assign(Object.assign({}, cborDecoded.content), { arg: (0, json_1.idlDecodedToJsonStringifiable)(manageNeuron) })
500
+ }
501
+ ];
502
+ }
503
+ exports.getDetailsFromSignedIncreaseDissolveDelay = getDetailsFromSignedIncreaseDissolveDelay;
504
+ // START_DISSOLVING
505
+ // CANISTER : (name: NNS Governance, identifier: rrkah-fqaaa-aaaaa-aaaaq-cai)
506
+ // METHOD : (name: manage_neuron, type: update)
507
+ // PAYLOAD : (id : [{id : float}], command : [{Configure : {operation : [{StartDissolving : {}}]}}], neuron_id_or_subaccount : [])
508
+ // RESPONSE : (command : [{configure : {}}])
509
+ function prepareStartDissolving(publicKey) {
510
+ return __awaiter(this, void 0, void 0, function* () {
511
+ // Create subaccount from publicKey
512
+ const { subAccount, nonce: _ } = (0, ICPImplementation_1.getFixedSubaccountFromPublicKey)(publicKey);
513
+ // IDL for StartDissolving
514
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
515
+ const StartDissolving = IDL.Record({});
516
+ const Operation = IDL.Variant({
517
+ StartDissolving: StartDissolving
518
+ });
519
+ const Configure = IDL.Record({ operation: IDL.Opt(Operation) });
520
+ const Command = IDL.Variant({
521
+ Configure: Configure
522
+ });
523
+ const NeuronIdOrSubaccount = IDL.Variant({
524
+ Subaccount: IDL.Vec(IDL.Nat8),
525
+ NeuronId: NeuronId
526
+ });
527
+ const ManageNeuron = IDL.Record({
528
+ id: IDL.Opt(NeuronId),
529
+ command: IDL.Opt(Command),
530
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
531
+ });
532
+ // Encode
533
+ const unsignedTransactionBuffer = IDL.encode([ManageNeuron], [
534
+ {
535
+ id: [],
536
+ command: [{ Configure: { operation: [{ StartDissolving: {} }] } }],
537
+ neuron_id_or_subaccount: [{ Subaccount: subAccount.toUint8Array() }]
538
+ }
539
+ ]);
540
+ return [
541
+ {
542
+ actionType: transaction_1.ICPActionType.START_DISSOLVING,
543
+ encoded: (0, convert_1.arrayBufferToHexString)(unsignedTransactionBuffer)
544
+ }
545
+ ];
546
+ });
547
+ }
548
+ exports.prepareStartDissolving = prepareStartDissolving;
549
+ function getDetailsFromUnsignedStartDissolving(encoded, publicKey, network) {
550
+ // IDL for StartDissolving
551
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
552
+ const StartDissolving = IDL.Record({});
553
+ const Operation = IDL.Variant({
554
+ StartDissolving: StartDissolving
555
+ });
556
+ const Configure = IDL.Record({ operation: IDL.Opt(Operation) });
557
+ const Command = IDL.Variant({
558
+ Configure: Configure
559
+ });
560
+ const NeuronIdOrSubaccount = IDL.Variant({
561
+ Subaccount: IDL.Vec(IDL.Nat8),
562
+ NeuronId: NeuronId
563
+ });
564
+ const ManageNeuron = IDL.Record({
565
+ id: IDL.Opt(NeuronId),
566
+ command: IDL.Opt(Command),
567
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
568
+ });
569
+ const manageNeuron = IDL.decode([ManageNeuron], (0, convert_1.hexStringToArrayBuffer)(encoded))[0];
570
+ return [
571
+ {
572
+ from: [(0, ICPImplementation_1.getAddressFromPublicKey)(publicKey)],
573
+ to: [network.governanceCanisterId],
574
+ isInbound: false,
575
+ amount: (0, module_kit_1.newAmount)('0', 'blockchain'),
576
+ fee: (0, module_kit_1.newAmount)('0', 'blockchain'),
577
+ network,
578
+ type: transaction_1.ICPActionType.START_DISSOLVING,
579
+ json: {
580
+ ManageNeuron: (0, json_1.idlDecodedToJsonStringifiable)(manageNeuron)
581
+ }
582
+ }
583
+ ];
584
+ }
585
+ exports.getDetailsFromUnsignedStartDissolving = getDetailsFromUnsignedStartDissolving;
586
+ function signStartDissolving(unsignedTransaction, privateKey, canisterId) {
587
+ return __awaiter(this, void 0, void 0, function* () {
588
+ // unsignedTransaction has already the arguments needed for signing, just need to be in a Buffer
589
+ const args = (0, convert_1.hexStringToArrayBuffer)(unsignedTransaction);
590
+ // Sign transaction
591
+ const signedTransaction = (0, ICPImplementation_1.signTransaction)(privateKey, canisterId, args, 'manage_neuron', 'call');
592
+ return signedTransaction;
593
+ });
594
+ }
595
+ exports.signStartDissolving = signStartDissolving;
596
+ function getDetailsFromSignedStartDissolving(encoded, publicKey, network) {
597
+ // IDL for StartDissolving
598
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
599
+ const StartDissolving = IDL.Record({});
600
+ const Operation = IDL.Variant({
601
+ StartDissolving: StartDissolving
602
+ });
603
+ const Configure = IDL.Record({ operation: IDL.Opt(Operation) });
604
+ const Command = IDL.Variant({
605
+ Configure: Configure
606
+ });
607
+ const NeuronIdOrSubaccount = IDL.Variant({
608
+ Subaccount: IDL.Vec(IDL.Nat8),
609
+ NeuronId: NeuronId
610
+ });
611
+ const ManageNeuron = IDL.Record({
612
+ id: IDL.Opt(NeuronId),
613
+ command: IDL.Opt(Command),
614
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
615
+ });
616
+ const cborDecoded = Cbor.decode((0, convert_1.hexStringToArrayBuffer)(encoded));
617
+ const manageNeuron = IDL.decode([ManageNeuron], cborDecoded.content.arg)[0];
618
+ return [
619
+ {
620
+ from: [(0, ICPImplementation_1.getAddressFromPublicKey)(publicKey)],
621
+ to: [network.governanceCanisterId],
622
+ isInbound: false,
623
+ amount: (0, module_kit_1.newAmount)('0', 'blockchain'),
624
+ fee: (0, module_kit_1.newAmount)('0', 'blockchain'),
625
+ network,
626
+ type: transaction_1.ICPActionType.START_DISSOLVING,
627
+ json: Object.assign(Object.assign({}, cborDecoded.content), { arg: (0, json_1.idlDecodedToJsonStringifiable)(manageNeuron) })
628
+ }
629
+ ];
630
+ }
631
+ exports.getDetailsFromSignedStartDissolving = getDetailsFromSignedStartDissolving;
632
+ // STOP_DISSOLVING
633
+ // CANISTER : (name: NNS Governance, identifier: rrkah-fqaaa-aaaaa-aaaaq-cai)
634
+ // METHOD : (name: manage_neuron, type: update)
635
+ // PAYLOAD : (id : [{id : float}], command : [{Configure : {operation : [{StopDissolving : {}}]}}], neuron_id_or_subaccount : [])
636
+ // RESPONSE : (command : [{configure : {}}])
637
+ function prepareStopDissolving(publicKey) {
638
+ return __awaiter(this, void 0, void 0, function* () {
639
+ // Create subaccount from publicKey
640
+ const { subAccount, nonce: _ } = (0, ICPImplementation_1.getFixedSubaccountFromPublicKey)(publicKey);
641
+ // IDL for StopDissolving
642
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
643
+ const StopDissolving = IDL.Record({});
644
+ const Operation = IDL.Variant({
645
+ StopDissolving: StopDissolving
646
+ });
647
+ const Configure = IDL.Record({ operation: IDL.Opt(Operation) });
648
+ const Command = IDL.Variant({
649
+ Configure: Configure
650
+ });
651
+ const NeuronIdOrSubaccount = IDL.Variant({
652
+ Subaccount: IDL.Vec(IDL.Nat8),
653
+ NeuronId: NeuronId
654
+ });
655
+ const ManageNeuron = IDL.Record({
656
+ id: IDL.Opt(NeuronId),
657
+ command: IDL.Opt(Command),
658
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
659
+ });
660
+ // Encode
661
+ const unsignedTransactionBuffer = IDL.encode([ManageNeuron], [
662
+ {
663
+ id: [],
664
+ command: [{ Configure: { operation: [{ StopDissolving: {} }] } }],
665
+ neuron_id_or_subaccount: [{ Subaccount: subAccount.toUint8Array() }]
666
+ }
667
+ ]);
668
+ return [
669
+ {
670
+ actionType: transaction_1.ICPActionType.STOP_DISSOLVING,
671
+ encoded: (0, convert_1.arrayBufferToHexString)(unsignedTransactionBuffer)
672
+ }
673
+ ];
674
+ });
675
+ }
676
+ exports.prepareStopDissolving = prepareStopDissolving;
677
+ function getDetailsFromUnsignedStopDissolving(encoded, publicKey, network) {
678
+ // IDL for StopDissolving
679
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
680
+ const StopDissolving = IDL.Record({});
681
+ const Operation = IDL.Variant({
682
+ StopDissolving: StopDissolving
683
+ });
684
+ const Configure = IDL.Record({ operation: IDL.Opt(Operation) });
685
+ const Command = IDL.Variant({
686
+ Configure: Configure
687
+ });
688
+ const NeuronIdOrSubaccount = IDL.Variant({
689
+ Subaccount: IDL.Vec(IDL.Nat8),
690
+ NeuronId: NeuronId
691
+ });
692
+ const ManageNeuron = IDL.Record({
693
+ id: IDL.Opt(NeuronId),
694
+ command: IDL.Opt(Command),
695
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
696
+ });
697
+ const manageNeuron = IDL.decode([ManageNeuron], (0, convert_1.hexStringToArrayBuffer)(encoded))[0];
698
+ return [
699
+ {
700
+ from: [(0, ICPImplementation_1.getAddressFromPublicKey)(publicKey)],
701
+ to: [network.governanceCanisterId],
702
+ isInbound: false,
703
+ amount: (0, module_kit_1.newAmount)('0', 'blockchain'),
704
+ fee: (0, module_kit_1.newAmount)('0', 'blockchain'),
705
+ network,
706
+ type: transaction_1.ICPActionType.STOP_DISSOLVING,
707
+ json: {
708
+ ManageNeuron: (0, json_1.idlDecodedToJsonStringifiable)(manageNeuron)
709
+ }
710
+ }
711
+ ];
712
+ }
713
+ exports.getDetailsFromUnsignedStopDissolving = getDetailsFromUnsignedStopDissolving;
714
+ function signStopDissolving(unsignedTransaction, privateKey, canisterId) {
715
+ return __awaiter(this, void 0, void 0, function* () {
716
+ // unsignedTransaction has already the arguments needed for signing, just need to be in a Buffer
717
+ const args = (0, convert_1.hexStringToArrayBuffer)(unsignedTransaction);
718
+ // Sign transaction
719
+ const signedTransaction = (0, ICPImplementation_1.signTransaction)(privateKey, canisterId, args, 'manage_neuron', 'call');
720
+ return signedTransaction;
721
+ });
722
+ }
723
+ exports.signStopDissolving = signStopDissolving;
724
+ function getDetailsFromSignedStopDissolving(encoded, publicKey, network) {
725
+ // IDL for StopDissolving
726
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
727
+ const StopDissolving = IDL.Record({});
728
+ const Operation = IDL.Variant({
729
+ StopDissolving: StopDissolving
730
+ });
731
+ const Configure = IDL.Record({ operation: IDL.Opt(Operation) });
732
+ const Command = IDL.Variant({
733
+ Configure: Configure
734
+ });
735
+ const NeuronIdOrSubaccount = IDL.Variant({
736
+ Subaccount: IDL.Vec(IDL.Nat8),
737
+ NeuronId: NeuronId
738
+ });
739
+ const ManageNeuron = IDL.Record({
740
+ id: IDL.Opt(NeuronId),
741
+ command: IDL.Opt(Command),
742
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
743
+ });
744
+ const cborDecoded = Cbor.decode((0, convert_1.hexStringToArrayBuffer)(encoded));
745
+ const manageNeuron = IDL.decode([ManageNeuron], cborDecoded.content.arg)[0];
746
+ return [
747
+ {
748
+ from: [(0, ICPImplementation_1.getAddressFromPublicKey)(publicKey)],
749
+ to: [network.governanceCanisterId],
750
+ isInbound: false,
751
+ amount: (0, module_kit_1.newAmount)('0', 'blockchain'),
752
+ fee: (0, module_kit_1.newAmount)('0', 'blockchain'),
753
+ network,
754
+ type: transaction_1.ICPActionType.STOP_DISSOLVING,
755
+ json: Object.assign(Object.assign({}, cborDecoded.content), { arg: (0, json_1.idlDecodedToJsonStringifiable)(manageNeuron) })
756
+ }
757
+ ];
758
+ }
759
+ exports.getDetailsFromSignedStopDissolving = getDetailsFromSignedStopDissolving;
760
+ // AUTO_STAKE_MATURITY
761
+ function prepareAutoStakeMaturity(publicKey) {
762
+ return __awaiter(this, void 0, void 0, function* () {
763
+ // Create subaccount from publicKey
764
+ const { subAccount, nonce: _ } = (0, ICPImplementation_1.getFixedSubaccountFromPublicKey)(publicKey);
765
+ // IDL for ChangeAutoStakeMaturity
766
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
767
+ const ChangeAutoStakeMaturity = IDL.Record({
768
+ requested_setting_for_auto_stake_maturity: IDL.Bool
769
+ });
770
+ const Operation = IDL.Variant({
771
+ ChangeAutoStakeMaturity: ChangeAutoStakeMaturity
772
+ });
773
+ const Configure = IDL.Record({ operation: IDL.Opt(Operation) });
774
+ const Command = IDL.Variant({
775
+ Configure: Configure
776
+ });
777
+ const NeuronIdOrSubaccount = IDL.Variant({
778
+ Subaccount: IDL.Vec(IDL.Nat8),
779
+ NeuronId: NeuronId
780
+ });
781
+ const ManageNeuron = IDL.Record({
782
+ id: IDL.Opt(NeuronId),
783
+ command: IDL.Opt(Command),
784
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
785
+ });
786
+ // Encode
787
+ const unsignedTransactionBuffer = IDL.encode([ManageNeuron], [
788
+ {
789
+ id: [],
790
+ command: [
791
+ {
792
+ Configure: {
793
+ operation: [
794
+ {
795
+ ChangeAutoStakeMaturity: {
796
+ requested_setting_for_auto_stake_maturity: true
797
+ }
798
+ }
799
+ ]
800
+ }
801
+ }
802
+ ],
803
+ neuron_id_or_subaccount: [{ Subaccount: subAccount.toUint8Array() }]
804
+ }
805
+ ]);
806
+ return [
807
+ {
808
+ actionType: transaction_1.ICPActionType.AUTO_STAKE_MATURITY,
809
+ encoded: (0, convert_1.arrayBufferToHexString)(unsignedTransactionBuffer)
810
+ }
811
+ ];
812
+ });
813
+ }
814
+ exports.prepareAutoStakeMaturity = prepareAutoStakeMaturity;
815
+ function getDetailsFromUnsignedAutoStakeMaturity(encoded, publicKey, network) {
816
+ // IDL for ChangeAutoStakeMaturity
817
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
818
+ const ChangeAutoStakeMaturity = IDL.Record({
819
+ requested_setting_for_auto_stake_maturity: IDL.Bool
820
+ });
821
+ const Operation = IDL.Variant({
822
+ ChangeAutoStakeMaturity: ChangeAutoStakeMaturity
823
+ });
824
+ const Configure = IDL.Record({ operation: IDL.Opt(Operation) });
825
+ const Command = IDL.Variant({
826
+ Configure: Configure
827
+ });
828
+ const NeuronIdOrSubaccount = IDL.Variant({
829
+ Subaccount: IDL.Vec(IDL.Nat8),
830
+ NeuronId: NeuronId
831
+ });
832
+ const ManageNeuron = IDL.Record({
833
+ id: IDL.Opt(NeuronId),
834
+ command: IDL.Opt(Command),
835
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
836
+ });
837
+ const manageNeuron = IDL.decode([ManageNeuron], (0, convert_1.hexStringToArrayBuffer)(encoded))[0];
838
+ return [
839
+ {
840
+ from: [(0, ICPImplementation_1.getAddressFromPublicKey)(publicKey)],
841
+ to: [network.governanceCanisterId],
842
+ isInbound: false,
843
+ amount: (0, module_kit_1.newAmount)('0', 'blockchain'),
844
+ fee: (0, module_kit_1.newAmount)('0', 'blockchain'),
845
+ network,
846
+ type: transaction_1.ICPActionType.AUTO_STAKE_MATURITY,
847
+ json: {
848
+ ManageNeuron: (0, json_1.idlDecodedToJsonStringifiable)(manageNeuron)
849
+ }
850
+ }
851
+ ];
852
+ }
853
+ exports.getDetailsFromUnsignedAutoStakeMaturity = getDetailsFromUnsignedAutoStakeMaturity;
854
+ function signAutoStakeMaturity(unsignedTransaction, privateKey, canisterId) {
855
+ return __awaiter(this, void 0, void 0, function* () {
856
+ // unsignedTransaction has already the arguments needed for signing, just need to be in a Buffer
857
+ const args = (0, convert_1.hexStringToArrayBuffer)(unsignedTransaction);
858
+ // Sign transaction
859
+ const signedTransaction = (0, ICPImplementation_1.signTransaction)(privateKey, canisterId, args, 'manage_neuron', 'call');
860
+ return signedTransaction;
861
+ });
862
+ }
863
+ exports.signAutoStakeMaturity = signAutoStakeMaturity;
864
+ function getDetailsFromSignedAutoStakeMaturity(encoded, publicKey, network) {
865
+ // IDL for ChangeAutoStakeMaturity
866
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
867
+ const ChangeAutoStakeMaturity = IDL.Record({
868
+ requested_setting_for_auto_stake_maturity: IDL.Bool
869
+ });
870
+ const Operation = IDL.Variant({
871
+ ChangeAutoStakeMaturity: ChangeAutoStakeMaturity
872
+ });
873
+ const Configure = IDL.Record({ operation: IDL.Opt(Operation) });
874
+ const Command = IDL.Variant({
875
+ Configure: Configure
876
+ });
877
+ const NeuronIdOrSubaccount = IDL.Variant({
878
+ Subaccount: IDL.Vec(IDL.Nat8),
879
+ NeuronId: NeuronId
880
+ });
881
+ const ManageNeuron = IDL.Record({
882
+ id: IDL.Opt(NeuronId),
883
+ command: IDL.Opt(Command),
884
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
885
+ });
886
+ const cborDecoded = Cbor.decode((0, convert_1.hexStringToArrayBuffer)(encoded));
887
+ const manageNeuron = IDL.decode([ManageNeuron], cborDecoded.content.arg)[0];
888
+ return [
889
+ {
890
+ from: [(0, ICPImplementation_1.getAddressFromPublicKey)(publicKey)],
891
+ to: [network.governanceCanisterId],
892
+ isInbound: false,
893
+ amount: (0, module_kit_1.newAmount)('0', 'blockchain'),
894
+ fee: (0, module_kit_1.newAmount)('0', 'blockchain'),
895
+ network,
896
+ type: transaction_1.ICPActionType.AUTO_STAKE_MATURITY,
897
+ json: Object.assign(Object.assign({}, cborDecoded.content), { arg: (0, json_1.idlDecodedToJsonStringifiable)(manageNeuron) })
898
+ }
899
+ ];
900
+ }
901
+ exports.getDetailsFromSignedAutoStakeMaturity = getDetailsFromSignedAutoStakeMaturity;
902
+ // FOLLOW_NEURON
903
+ // CANISTER : (name: NNS Governance, identifier: rrkah-fqaaa-aaaaa-aaaaq-cai)
904
+ // METHOD : (name: manage_neuron, type: update)
905
+ // PAYLOAD : (id : [{id : float}], command : [{Follow : {topic : int, followees : [{id: int}]}}], neuron_id_or_subaccount : [])
906
+ // RESPONSE : (command : [{Follow : {}}])
907
+ const TOPICS = [
908
+ { id: 0, name: 'All Except Governance, and SNS & Community Fund' },
909
+ { id: 4, name: 'Governance' },
910
+ { id: 14, name: 'SNS & Community Fund' }
911
+ ];
912
+ function prepareFollowNeuron(publicKey, neuronId) {
913
+ return __awaiter(this, void 0, void 0, function* () {
914
+ // Create subaccount from publicKey
915
+ const { subAccount, nonce: _ } = (0, ICPImplementation_1.getFixedSubaccountFromPublicKey)(publicKey);
916
+ // IDL for FollowNeuron
917
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
918
+ const Follow = IDL.Record({
919
+ topic: IDL.Int32,
920
+ followees: IDL.Vec(NeuronId)
921
+ });
922
+ const Command = IDL.Variant({
923
+ Follow: Follow
924
+ });
925
+ const NeuronIdOrSubaccount = IDL.Variant({
926
+ Subaccount: IDL.Vec(IDL.Nat8),
927
+ NeuronId: NeuronId
928
+ });
929
+ const ManageNeuron = IDL.Record({
930
+ id: IDL.Opt(NeuronId),
931
+ command: IDL.Opt(Command),
932
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
933
+ });
934
+ return TOPICS.map(({ id }) => {
935
+ // Encode
936
+ const unsignedTransactionBuffer = IDL.encode([ManageNeuron], [
937
+ {
938
+ id: [],
939
+ command: [{ Follow: { topic: id, followees: neuronId !== undefined ? [{ id: neuronId }] : [] } }],
940
+ neuron_id_or_subaccount: [{ Subaccount: subAccount.toUint8Array() }]
941
+ }
942
+ ]);
943
+ return {
944
+ actionType: transaction_1.ICPActionType.FOLLOW_NEURON,
945
+ encoded: (0, convert_1.arrayBufferToHexString)(unsignedTransactionBuffer)
946
+ };
947
+ });
948
+ });
949
+ }
950
+ exports.prepareFollowNeuron = prepareFollowNeuron;
951
+ function getDetailsFromUnsignedFollowNeuron(encoded, publicKey, network) {
952
+ // IDL for FollowNeuron
953
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
954
+ const Follow = IDL.Record({
955
+ topic: IDL.Int32,
956
+ followees: IDL.Vec(NeuronId)
957
+ });
958
+ const Command = IDL.Variant({
959
+ Follow: Follow
960
+ });
961
+ const NeuronIdOrSubaccount = IDL.Variant({
962
+ Subaccount: IDL.Vec(IDL.Nat8),
963
+ NeuronId: NeuronId
964
+ });
965
+ const ManageNeuron = IDL.Record({
966
+ id: IDL.Opt(NeuronId),
967
+ command: IDL.Opt(Command),
968
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
969
+ });
970
+ const manageNeuron = IDL.decode([ManageNeuron], (0, convert_1.hexStringToArrayBuffer)(encoded))[0];
971
+ const topicId = manageNeuron.command[0].Follow.topic;
972
+ const topic = TOPICS.find(({ id }) => id.toString() === topicId.toString());
973
+ return [
974
+ {
975
+ from: [(0, ICPImplementation_1.getAddressFromPublicKey)(publicKey)],
976
+ to: [network.governanceCanisterId],
977
+ isInbound: false,
978
+ amount: (0, module_kit_1.newAmount)('0', 'blockchain'),
979
+ fee: (0, module_kit_1.newAmount)('0', 'blockchain'),
980
+ network,
981
+ type: transaction_1.ICPActionType.FOLLOW_NEURON,
982
+ json: {
983
+ ManageNeuron: (0, json_1.idlDecodedToJsonStringifiable)(manageNeuron)
984
+ },
985
+ extra: {
986
+ labeled: topic ? { topic: topic.name } : undefined
987
+ }
988
+ }
989
+ ];
990
+ }
991
+ exports.getDetailsFromUnsignedFollowNeuron = getDetailsFromUnsignedFollowNeuron;
992
+ function signFollowNeuron(unsignedTransaction, privateKey, canisterId) {
993
+ return __awaiter(this, void 0, void 0, function* () {
994
+ // unsignedTransaction has already the arguments needed for signing, just need to be in a Buffer
995
+ const args = (0, convert_1.hexStringToArrayBuffer)(unsignedTransaction);
996
+ // Sign transaction
997
+ const signedTransaction = (0, ICPImplementation_1.signTransaction)(privateKey, canisterId, args, 'manage_neuron', 'call');
998
+ return signedTransaction;
999
+ });
1000
+ }
1001
+ exports.signFollowNeuron = signFollowNeuron;
1002
+ function getDetailsFromSignedFollowNeuron(encoded, publicKey, network) {
1003
+ // IDL for FollowNeuron
1004
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
1005
+ const Follow = IDL.Record({
1006
+ topic: IDL.Int32,
1007
+ followees: IDL.Vec(NeuronId)
1008
+ });
1009
+ const Command = IDL.Variant({
1010
+ Follow: Follow
1011
+ });
1012
+ const NeuronIdOrSubaccount = IDL.Variant({
1013
+ Subaccount: IDL.Vec(IDL.Nat8),
1014
+ NeuronId: NeuronId
1015
+ });
1016
+ const ManageNeuron = IDL.Record({
1017
+ id: IDL.Opt(NeuronId),
1018
+ command: IDL.Opt(Command),
1019
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
1020
+ });
1021
+ const cborDecoded = Cbor.decode((0, convert_1.hexStringToArrayBuffer)(encoded));
1022
+ const manageNeuron = IDL.decode([ManageNeuron], cborDecoded.content.arg)[0];
1023
+ const topicId = manageNeuron.command[0].Follow.topic;
1024
+ const topic = TOPICS.find(({ id }) => id.toString() === topicId.toString());
1025
+ return [
1026
+ {
1027
+ from: [(0, ICPImplementation_1.getAddressFromPublicKey)(publicKey)],
1028
+ to: [network.governanceCanisterId],
1029
+ isInbound: false,
1030
+ amount: (0, module_kit_1.newAmount)('0', 'blockchain'),
1031
+ fee: (0, module_kit_1.newAmount)('0', 'blockchain'),
1032
+ network,
1033
+ type: transaction_1.ICPActionType.FOLLOW_NEURON,
1034
+ json: Object.assign(Object.assign({}, cborDecoded.content), { arg: (0, json_1.idlDecodedToJsonStringifiable)(manageNeuron) }),
1035
+ extra: {
1036
+ labeled: topic ? { topic: topic.name } : undefined
1037
+ }
1038
+ }
1039
+ ];
1040
+ }
1041
+ exports.getDetailsFromSignedFollowNeuron = getDetailsFromSignedFollowNeuron;
1042
+ // DISBURSE
1043
+ // Cannot extrapolate method from call since we have to wait 6 months to do so
1044
+ function prepareDisburse(publicKey) {
1045
+ return __awaiter(this, void 0, void 0, function* () {
1046
+ // Create subaccount from publicKey
1047
+ const { subAccount, nonce: _ } = (0, ICPImplementation_1.getFixedSubaccountFromPublicKey)(publicKey);
1048
+ // IDL for Disburse
1049
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
1050
+ const AccountIdentifier = IDL.Record({ hash: IDL.Vec(IDL.Nat8) });
1051
+ const Amount = IDL.Record({ e8s: IDL.Nat64 });
1052
+ const Disburse = IDL.Record({
1053
+ to_account: IDL.Opt(AccountIdentifier),
1054
+ amount: IDL.Opt(Amount)
1055
+ });
1056
+ const Command = IDL.Variant({
1057
+ Disburse: Disburse
1058
+ });
1059
+ const NeuronIdOrSubaccount = IDL.Variant({
1060
+ Subaccount: IDL.Vec(IDL.Nat8),
1061
+ NeuronId: NeuronId
1062
+ });
1063
+ const ManageNeuron = IDL.Record({
1064
+ id: IDL.Opt(NeuronId),
1065
+ command: IDL.Opt(Command),
1066
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
1067
+ });
1068
+ // Encode
1069
+ const unsignedTransactionBuffer = IDL.encode([ManageNeuron], [
1070
+ {
1071
+ id: [],
1072
+ command: [
1073
+ {
1074
+ Disburse: {
1075
+ to_account: [],
1076
+ amount: []
1077
+ }
1078
+ }
1079
+ ],
1080
+ neuron_id_or_subaccount: [{ Subaccount: subAccount.toUint8Array() }]
1081
+ }
1082
+ ]);
1083
+ return [
1084
+ {
1085
+ actionType: transaction_1.ICPActionType.DISBURSE,
1086
+ encoded: (0, convert_1.arrayBufferToHexString)(unsignedTransactionBuffer)
1087
+ }
1088
+ ];
1089
+ });
1090
+ }
1091
+ exports.prepareDisburse = prepareDisburse;
1092
+ function getDetailsFromUnsignedDisburse(encoded, publicKey, network) {
1093
+ // IDL for Disburse
1094
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
1095
+ const AccountIdentifier = IDL.Record({ hash: IDL.Vec(IDL.Nat8) });
1096
+ const Amount = IDL.Record({ e8s: IDL.Nat64 });
1097
+ const Disburse = IDL.Record({
1098
+ to_account: IDL.Opt(AccountIdentifier),
1099
+ amount: IDL.Opt(Amount)
1100
+ });
1101
+ const Command = IDL.Variant({
1102
+ Disburse: Disburse
1103
+ });
1104
+ const NeuronIdOrSubaccount = IDL.Variant({
1105
+ Subaccount: IDL.Vec(IDL.Nat8),
1106
+ NeuronId: NeuronId
1107
+ });
1108
+ const ManageNeuron = IDL.Record({
1109
+ id: IDL.Opt(NeuronId),
1110
+ command: IDL.Opt(Command),
1111
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
1112
+ });
1113
+ const manageNeuron = IDL.decode([ManageNeuron], (0, convert_1.hexStringToArrayBuffer)(encoded))[0];
1114
+ return [
1115
+ {
1116
+ from: [network.governanceCanisterId],
1117
+ to: [(0, ICPImplementation_1.getAddressFromPublicKey)(publicKey)],
1118
+ isInbound: false,
1119
+ amount: (0, module_kit_1.newAmount)('0', 'blockchain'),
1120
+ fee: (0, module_kit_1.newAmount)('0', 'blockchain'),
1121
+ network,
1122
+ type: transaction_1.ICPActionType.DISBURSE,
1123
+ json: {
1124
+ ManageNeuron: (0, json_1.idlDecodedToJsonStringifiable)(manageNeuron)
1125
+ }
1126
+ }
1127
+ ];
1128
+ }
1129
+ exports.getDetailsFromUnsignedDisburse = getDetailsFromUnsignedDisburse;
1130
+ function signDisburse(unsignedTransaction, privateKey, canisterId) {
1131
+ return __awaiter(this, void 0, void 0, function* () {
1132
+ // unsignedTransaction has already the arguments needed for signing, just need to be in a Buffer
1133
+ const args = (0, convert_1.hexStringToArrayBuffer)(unsignedTransaction);
1134
+ // Sign transaction
1135
+ const signedTransaction = (0, ICPImplementation_1.signTransaction)(privateKey, canisterId, args, 'manage_neuron', 'call');
1136
+ return signedTransaction;
1137
+ });
1138
+ }
1139
+ exports.signDisburse = signDisburse;
1140
+ function getDetailsFromSignedDisburse(encoded, publicKey, network) {
1141
+ // IDL for Disburse
1142
+ const NeuronId = IDL.Record({ id: IDL.Nat64 });
1143
+ const AccountIdentifier = IDL.Record({ hash: IDL.Vec(IDL.Nat8) });
1144
+ const Amount = IDL.Record({ e8s: IDL.Nat64 });
1145
+ const Disburse = IDL.Record({
1146
+ to_account: IDL.Opt(AccountIdentifier),
1147
+ amount: IDL.Opt(Amount)
1148
+ });
1149
+ const Command = IDL.Variant({
1150
+ Disburse: Disburse
1151
+ });
1152
+ const NeuronIdOrSubaccount = IDL.Variant({
1153
+ Subaccount: IDL.Vec(IDL.Nat8),
1154
+ NeuronId: NeuronId
1155
+ });
1156
+ const ManageNeuron = IDL.Record({
1157
+ id: IDL.Opt(NeuronId),
1158
+ command: IDL.Opt(Command),
1159
+ neuron_id_or_subaccount: IDL.Opt(NeuronIdOrSubaccount)
1160
+ });
1161
+ const cborDecoded = Cbor.decode((0, convert_1.hexStringToArrayBuffer)(encoded));
1162
+ const manageNeuron = IDL.decode([ManageNeuron], cborDecoded.content.arg)[0];
1163
+ return [
1164
+ {
1165
+ from: [network.governanceCanisterId],
1166
+ to: [(0, ICPImplementation_1.getAddressFromPublicKey)(publicKey)],
1167
+ isInbound: false,
1168
+ amount: (0, module_kit_1.newAmount)('0', 'blockchain'),
1169
+ fee: (0, module_kit_1.newAmount)('0', 'blockchain'),
1170
+ network,
1171
+ type: transaction_1.ICPActionType.DISBURSE,
1172
+ json: Object.assign(Object.assign({}, cborDecoded.content), { arg: (0, json_1.idlDecodedToJsonStringifiable)(manageNeuron) })
1173
+ }
1174
+ ];
1175
+ }
1176
+ exports.getDetailsFromSignedDisburse = getDetailsFromSignedDisburse;
1177
+ //# sourceMappingURL=ICPGovernance.js.map