@astrox/connection 0.0.24 → 0.0.27

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 (118) hide show
  1. package/README.md +22 -10
  2. package/lib/cjs/canisters/internet_identity_idl.d.ts +7 -0
  3. package/lib/cjs/canisters/internet_identity_idl.js +102 -0
  4. package/lib/cjs/canisters/internet_identity_idl.js.map +1 -0
  5. package/lib/cjs/canisters/ledger.idl.d.ts +7 -0
  6. package/lib/cjs/canisters/ledger.idl.js +82 -0
  7. package/lib/cjs/canisters/ledger.idl.js.map +1 -0
  8. package/lib/cjs/canisters/me.idl.d.ts +7 -0
  9. package/lib/cjs/canisters/me.idl.js +126 -0
  10. package/lib/cjs/canisters/me.idl.js.map +1 -0
  11. package/lib/cjs/canisters/nns-dapp-cert.idl.d.ts +7 -0
  12. package/lib/cjs/canisters/nns-dapp-cert.idl.js +87 -0
  13. package/lib/cjs/canisters/nns-dapp-cert.idl.js.map +1 -0
  14. package/lib/cjs/canisters/nns-dapp.idl.d.ts +7 -0
  15. package/lib/cjs/canisters/nns-dapp.idl.js +185 -0
  16. package/lib/cjs/canisters/nns-dapp.idl.js.map +1 -0
  17. package/lib/cjs/connections/baseConnection.d.ts +23 -0
  18. package/lib/cjs/connections/baseConnection.js +89 -0
  19. package/lib/cjs/connections/baseConnection.js.map +1 -0
  20. package/lib/cjs/connections/ledgerConnection.d.ts +53 -0
  21. package/lib/cjs/connections/ledgerConnection.js +137 -0
  22. package/lib/cjs/connections/ledgerConnection.js.map +1 -0
  23. package/lib/cjs/connections/nnsConnection.d.ts +63 -0
  24. package/lib/cjs/connections/nnsConnection.js +161 -0
  25. package/lib/cjs/connections/nnsConnection.js.map +1 -0
  26. package/lib/cjs/ic/icAuthClient.d.ts +31 -0
  27. package/lib/cjs/ic/icAuthClient.js +236 -0
  28. package/lib/cjs/ic/icAuthClient.js.map +1 -0
  29. package/lib/cjs/ic/icConnect.d.ts +36 -0
  30. package/lib/cjs/ic/icConnect.js +192 -0
  31. package/lib/cjs/ic/icConnect.js.map +1 -0
  32. package/lib/cjs/ic/icStorage.d.ts +16 -0
  33. package/lib/cjs/ic/icStorage.js +49 -0
  34. package/lib/cjs/ic/icStorage.js.map +1 -0
  35. package/lib/cjs/ic/icWindow.d.ts +8 -0
  36. package/lib/cjs/ic/icWindow.js +24 -0
  37. package/lib/cjs/ic/icWindow.js.map +1 -0
  38. package/lib/cjs/ic/index.d.ts +2 -0
  39. package/lib/cjs/ic/index.js +8 -0
  40. package/lib/cjs/ic/index.js.map +1 -0
  41. package/lib/cjs/index.d.ts +5 -0
  42. package/lib/cjs/index.js +18 -0
  43. package/lib/cjs/index.js.map +1 -0
  44. package/lib/cjs/types/index.d.ts +175 -0
  45. package/lib/cjs/types/index.js +17 -0
  46. package/lib/cjs/types/index.js.map +1 -0
  47. package/lib/cjs/utils/common/types.d.ts +15 -0
  48. package/lib/cjs/utils/common/types.js +12 -0
  49. package/lib/cjs/utils/common/types.js.map +1 -0
  50. package/lib/cjs/utils/constants.d.ts +6 -0
  51. package/lib/cjs/utils/constants.js +13 -0
  52. package/lib/cjs/utils/constants.js.map +1 -0
  53. package/lib/cjs/utils/converter.d.ts +32 -0
  54. package/lib/cjs/utils/converter.js +147 -0
  55. package/lib/cjs/utils/converter.js.map +1 -0
  56. package/lib/cjs/utils/index.d.ts +3 -0
  57. package/lib/cjs/utils/index.js +16 -0
  58. package/lib/cjs/utils/index.js.map +1 -0
  59. package/lib/esm/canisters/internet_identity_idl.d.ts +7 -0
  60. package/lib/esm/canisters/internet_identity_idl.js +98 -0
  61. package/lib/esm/canisters/internet_identity_idl.js.map +1 -0
  62. package/lib/esm/canisters/ledger.idl.d.ts +7 -0
  63. package/lib/esm/canisters/ledger.idl.js +78 -0
  64. package/lib/esm/canisters/ledger.idl.js.map +1 -0
  65. package/lib/esm/canisters/me.idl.d.ts +7 -0
  66. package/lib/esm/canisters/me.idl.js +122 -0
  67. package/lib/esm/canisters/me.idl.js.map +1 -0
  68. package/lib/esm/canisters/nns-dapp-cert.idl.d.ts +7 -0
  69. package/lib/esm/canisters/nns-dapp-cert.idl.js +83 -0
  70. package/lib/esm/canisters/nns-dapp-cert.idl.js.map +1 -0
  71. package/lib/esm/canisters/nns-dapp.idl.d.ts +7 -0
  72. package/lib/esm/canisters/nns-dapp.idl.js +181 -0
  73. package/lib/esm/canisters/nns-dapp.idl.js.map +1 -0
  74. package/lib/esm/connections/baseConnection.d.ts +23 -0
  75. package/lib/esm/connections/baseConnection.js +80 -0
  76. package/lib/esm/connections/baseConnection.js.map +1 -0
  77. package/lib/esm/connections/ledgerConnection.d.ts +53 -0
  78. package/lib/esm/connections/ledgerConnection.js +130 -0
  79. package/lib/esm/connections/ledgerConnection.js.map +1 -0
  80. package/lib/esm/connections/nnsConnection.d.ts +63 -0
  81. package/lib/esm/connections/nnsConnection.js +154 -0
  82. package/lib/esm/connections/nnsConnection.js.map +1 -0
  83. package/lib/esm/ic/icAuthClient.d.ts +31 -0
  84. package/lib/esm/ic/icAuthClient.js +232 -0
  85. package/lib/esm/ic/icAuthClient.js.map +1 -0
  86. package/lib/esm/ic/icConnect.d.ts +36 -0
  87. package/lib/esm/ic/icConnect.js +188 -0
  88. package/lib/esm/ic/icConnect.js.map +1 -0
  89. package/lib/esm/ic/icStorage.d.ts +16 -0
  90. package/lib/esm/ic/icStorage.js +44 -0
  91. package/lib/esm/ic/icStorage.js.map +1 -0
  92. package/lib/esm/ic/icWindow.d.ts +8 -0
  93. package/lib/esm/ic/icWindow.js +20 -0
  94. package/lib/esm/ic/icWindow.js.map +1 -0
  95. package/lib/esm/ic/index.d.ts +2 -0
  96. package/lib/esm/ic/index.js +3 -0
  97. package/lib/esm/ic/index.js.map +1 -0
  98. package/lib/esm/index.d.ts +5 -0
  99. package/lib/esm/index.js +6 -0
  100. package/lib/esm/index.js.map +1 -0
  101. package/lib/esm/types/index.d.ts +175 -0
  102. package/lib/esm/types/index.js +14 -0
  103. package/lib/esm/types/index.js.map +1 -0
  104. package/lib/esm/utils/common/types.d.ts +15 -0
  105. package/lib/esm/utils/common/types.js +9 -0
  106. package/lib/esm/utils/common/types.js.map +1 -0
  107. package/lib/esm/utils/constants.d.ts +6 -0
  108. package/lib/esm/utils/constants.js +10 -0
  109. package/lib/esm/utils/constants.js.map +1 -0
  110. package/lib/esm/utils/converter.d.ts +32 -0
  111. package/lib/esm/utils/converter.js +124 -0
  112. package/lib/esm/utils/converter.js.map +1 -0
  113. package/lib/esm/utils/index.d.ts +3 -0
  114. package/lib/esm/utils/index.js +4 -0
  115. package/lib/esm/utils/index.js.map +1 -0
  116. package/lib/tsconfig-cjs.tsbuildinfo +1 -0
  117. package/lib/tsconfig.tsbuildinfo +1 -1
  118. package/package.json +2 -2
@@ -0,0 +1,181 @@
1
+ export default ({ IDL }) => {
2
+ const AccountIdentifier = IDL.Text;
3
+ const AttachCanisterRequest = IDL.Record({
4
+ name: IDL.Text,
5
+ canister_id: IDL.Principal,
6
+ });
7
+ const AttachCanisterResponse = IDL.Variant({
8
+ Ok: IDL.Null,
9
+ CanisterAlreadyAttached: IDL.Null,
10
+ NameAlreadyTaken: IDL.Null,
11
+ NameTooLong: IDL.Null,
12
+ CanisterLimitExceeded: IDL.Null,
13
+ });
14
+ const SubAccount = IDL.Vec(IDL.Nat8);
15
+ const SubAccountDetails = IDL.Record({
16
+ name: IDL.Text,
17
+ sub_account: SubAccount,
18
+ account_identifier: AccountIdentifier,
19
+ });
20
+ const CreateSubAccountResponse = IDL.Variant({
21
+ Ok: SubAccountDetails,
22
+ AccountNotFound: IDL.Null,
23
+ NameTooLong: IDL.Null,
24
+ SubAccountLimitExceeded: IDL.Null,
25
+ });
26
+ const DetachCanisterRequest = IDL.Record({ canister_id: IDL.Principal });
27
+ const DetachCanisterResponse = IDL.Variant({
28
+ Ok: IDL.Null,
29
+ CanisterNotFound: IDL.Null,
30
+ });
31
+ const HardwareWalletAccountDetails = IDL.Record({
32
+ principal: IDL.Principal,
33
+ name: IDL.Text,
34
+ account_identifier: AccountIdentifier,
35
+ });
36
+ const AccountDetails = IDL.Record({
37
+ principal: IDL.Principal,
38
+ account_identifier: AccountIdentifier,
39
+ hardware_wallet_accounts: IDL.Vec(HardwareWalletAccountDetails),
40
+ sub_accounts: IDL.Vec(SubAccountDetails),
41
+ });
42
+ const GetAccountResponse = IDL.Variant({
43
+ Ok: AccountDetails,
44
+ AccountNotFound: IDL.Null,
45
+ });
46
+ const CanisterDetails = IDL.Record({
47
+ name: IDL.Text,
48
+ canister_id: IDL.Principal,
49
+ });
50
+ const BlockHeight = IDL.Nat64;
51
+ const MultiPartTransactionError = IDL.Record({
52
+ error_message: IDL.Text,
53
+ block_height: BlockHeight,
54
+ });
55
+ const CanisterId = IDL.Principal;
56
+ const NeuronId = IDL.Nat64;
57
+ const MultiPartTransactionStatus = IDL.Variant({
58
+ Queued: IDL.Null,
59
+ Error: IDL.Text,
60
+ Refunded: IDL.Tuple(BlockHeight, IDL.Text),
61
+ CanisterCreated: CanisterId,
62
+ Complete: IDL.Null,
63
+ NotFound: IDL.Null,
64
+ NeuronCreated: NeuronId,
65
+ PendingSync: IDL.Null,
66
+ ErrorWithRefundPending: IDL.Text,
67
+ });
68
+ const Stats = IDL.Record({
69
+ latest_transaction_block_height: BlockHeight,
70
+ seconds_since_last_ledger_sync: IDL.Nat64,
71
+ sub_accounts_count: IDL.Nat64,
72
+ neurons_topped_up_count: IDL.Nat64,
73
+ transactions_to_process_queue_length: IDL.Nat32,
74
+ neurons_created_count: IDL.Nat64,
75
+ hardware_wallet_accounts_count: IDL.Nat64,
76
+ accounts_count: IDL.Nat64,
77
+ earliest_transaction_block_height: BlockHeight,
78
+ transactions_count: IDL.Nat64,
79
+ block_height_synced_up_to: IDL.Opt(IDL.Nat64),
80
+ latest_transaction_timestamp_nanos: IDL.Nat64,
81
+ earliest_transaction_timestamp_nanos: IDL.Nat64,
82
+ });
83
+ const GetTransactionsRequest = IDL.Record({
84
+ page_size: IDL.Nat8,
85
+ offset: IDL.Nat32,
86
+ account_identifier: AccountIdentifier,
87
+ });
88
+ const TransactionType = IDL.Variant({
89
+ Burn: IDL.Null,
90
+ Mint: IDL.Null,
91
+ Send: IDL.Null,
92
+ StakeNeuronNotification: IDL.Null,
93
+ TopUpCanister: CanisterId,
94
+ CreateCanister: IDL.Null,
95
+ TopUpNeuron: IDL.Null,
96
+ StakeNeuron: IDL.Null,
97
+ });
98
+ const Timestamp = IDL.Record({ timestamp_nanos: IDL.Nat64 });
99
+ const ICPTs = IDL.Record({ e8s: IDL.Nat64 });
100
+ const Send = IDL.Record({
101
+ to: AccountIdentifier,
102
+ fee: ICPTs,
103
+ amount: ICPTs,
104
+ });
105
+ const Receive = IDL.Record({
106
+ fee: ICPTs,
107
+ from: AccountIdentifier,
108
+ amount: ICPTs,
109
+ });
110
+ const Transfer = IDL.Variant({
111
+ Burn: IDL.Record({ amount: ICPTs }),
112
+ Mint: IDL.Record({ amount: ICPTs }),
113
+ Send: Send,
114
+ Receive: Receive,
115
+ });
116
+ const Transaction = IDL.Record({
117
+ transaction_type: IDL.Opt(TransactionType),
118
+ memo: IDL.Nat64,
119
+ timestamp: Timestamp,
120
+ block_height: BlockHeight,
121
+ transfer: Transfer,
122
+ });
123
+ const GetTransactionsResponse = IDL.Record({
124
+ total: IDL.Nat32,
125
+ transactions: IDL.Vec(Transaction),
126
+ });
127
+ const HeaderField = IDL.Tuple(IDL.Text, IDL.Text);
128
+ const HttpRequest = IDL.Record({
129
+ url: IDL.Text,
130
+ method: IDL.Text,
131
+ body: IDL.Vec(IDL.Nat8),
132
+ headers: IDL.Vec(HeaderField),
133
+ });
134
+ const HttpResponse = IDL.Record({
135
+ body: IDL.Vec(IDL.Nat8),
136
+ headers: IDL.Vec(HeaderField),
137
+ status_code: IDL.Nat16,
138
+ });
139
+ const RegisterHardwareWalletRequest = IDL.Record({
140
+ principal: IDL.Principal,
141
+ name: IDL.Text,
142
+ });
143
+ const RegisterHardwareWalletResponse = IDL.Variant({
144
+ Ok: IDL.Null,
145
+ AccountNotFound: IDL.Null,
146
+ HardwareWalletAlreadyRegistered: IDL.Null,
147
+ HardwareWalletLimitExceeded: IDL.Null,
148
+ NameTooLong: IDL.Null,
149
+ });
150
+ const RenameSubAccountRequest = IDL.Record({
151
+ new_name: IDL.Text,
152
+ account_identifier: AccountIdentifier,
153
+ });
154
+ const RenameSubAccountResponse = IDL.Variant({
155
+ Ok: IDL.Null,
156
+ AccountNotFound: IDL.Null,
157
+ SubAccountNotFound: IDL.Null,
158
+ NameTooLong: IDL.Null,
159
+ });
160
+ return IDL.Service({
161
+ add_account: IDL.Func([], [AccountIdentifier], []),
162
+ add_stable_asset: IDL.Func([IDL.Vec(IDL.Nat8)], [], []),
163
+ attach_canister: IDL.Func([AttachCanisterRequest], [AttachCanisterResponse], []),
164
+ create_sub_account: IDL.Func([IDL.Text], [CreateSubAccountResponse], []),
165
+ detach_canister: IDL.Func([DetachCanisterRequest], [DetachCanisterResponse], []),
166
+ get_account: IDL.Func([], [GetAccountResponse], ['query']),
167
+ get_canisters: IDL.Func([], [IDL.Vec(CanisterDetails)], ['query']),
168
+ get_icp_to_cycles_conversion_rate: IDL.Func([], [IDL.Nat64], ['query']),
169
+ get_multi_part_transaction_errors: IDL.Func([], [IDL.Vec(MultiPartTransactionError)], ['query']),
170
+ get_multi_part_transaction_status: IDL.Func([IDL.Principal, BlockHeight], [MultiPartTransactionStatus], ['query']),
171
+ get_stats: IDL.Func([], [Stats], ['query']),
172
+ get_transactions: IDL.Func([GetTransactionsRequest], [GetTransactionsResponse], ['query']),
173
+ http_request: IDL.Func([HttpRequest], [HttpResponse], ['query']),
174
+ register_hardware_wallet: IDL.Func([RegisterHardwareWalletRequest], [RegisterHardwareWalletResponse], []),
175
+ rename_sub_account: IDL.Func([RenameSubAccountRequest], [RenameSubAccountResponse], []),
176
+ });
177
+ };
178
+ export const init = ({ IDL }) => {
179
+ return [];
180
+ };
181
+ //# sourceMappingURL=nns-dapp.idl.js.map
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B,CAAC,0BAA0B,CAAC,EAC5B,CAAC,OAAO,CAAC,CACV;QACD,SAAS,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;QAC3C,gBAAgB,EAAE,GAAG,CAAC,IAAI,CACxB,CAAC,sBAAsB,CAAC,EACxB,CAAC,uBAAuB,CAAC,EACzB,CAAC,OAAO,CAAC,CACV;QACD,YAAY,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;QAChE,wBAAwB,EAAE,GAAG,CAAC,IAAI,CAChC,CAAC,6BAA6B,CAAC,EAC/B,CAAC,8BAA8B,CAAC,EAChC,EAAE,CACH;QACD,kBAAkB,EAAE,GAAG,CAAC,IAAI,CAC1B,CAAC,uBAAuB,CAAC,EACzB,CAAC,wBAAwB,CAAC,EAC1B,EAAE,CACH;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AACF,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE;IAC9B,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { ActorSubclass, HttpAgent, SignIdentity } from '@dfinity/agent';
2
+ import { InterfaceFactory } from '@dfinity/candid/lib/cjs/idl';
3
+ import { DelegationIdentity } from '@dfinity/identity';
4
+ import { AbstractConnection, CreateActorResult, DelegationMessage, HandleDelegationResult } from '../types';
5
+ export declare function createConnection<T>(identity: SignIdentity, delegationIdentity: DelegationIdentity, canisterId: string, interfaceFactory: InterfaceFactory, actor?: ActorSubclass<T>, agent?: HttpAgent): BaseConnection<T>;
6
+ export declare const requestDelegation: (identity: SignIdentity, { canisterId, date }: {
7
+ canisterId?: string | undefined;
8
+ date?: Date | undefined;
9
+ }) => Promise<DelegationIdentity>;
10
+ export declare function _createActor<T>(interfaceFactory: InterfaceFactory, canisterId: string, identity?: SignIdentity): Promise<CreateActorResult<T>>;
11
+ export declare class BaseConnection<T> implements AbstractConnection<T> {
12
+ identity: SignIdentity;
13
+ delegationIdentity: DelegationIdentity;
14
+ canisterId: string;
15
+ interfaceFactory: InterfaceFactory;
16
+ actor?: ActorSubclass<T> | undefined;
17
+ agent?: HttpAgent | undefined;
18
+ constructor(identity: SignIdentity, delegationIdentity: DelegationIdentity, canisterId: string, interfaceFactory: InterfaceFactory, actor?: ActorSubclass<T> | undefined, agent?: HttpAgent | undefined);
19
+ getActor(): Promise<ActorSubclass<T>>;
20
+ protected _getActor(canisterId: string, interfaceFactory: InterfaceFactory, date?: Date): Promise<ActorSubclass<T>>;
21
+ }
22
+ export declare function handleDelegation(message: DelegationMessage, key: SignIdentity): Promise<HandleDelegationResult>;
23
+ export declare const executeWithLogging: <T>(func: () => Promise<T>) => Promise<T>;
@@ -0,0 +1,80 @@
1
+ import { Actor, HttpAgent, } from '@dfinity/agent';
2
+ import { Delegation, DelegationChain, DelegationIdentity, Ed25519KeyIdentity, } from '@dfinity/identity';
3
+ import { Principal } from '@dfinity/principal';
4
+ export function createConnection(identity, delegationIdentity, canisterId, interfaceFactory, actor, agent) {
5
+ return new BaseConnection(identity, delegationIdentity, canisterId, interfaceFactory, actor, agent);
6
+ }
7
+ export const requestDelegation = async (identity, { canisterId, date }) => {
8
+ const sessionKey = Ed25519KeyIdentity.generate();
9
+ const chain = await DelegationChain.create(identity, sessionKey.getPublicKey(), date || new Date(Date.parse('2100-01-01')), {
10
+ targets: canisterId != undefined ? [Principal.fromText(canisterId)] : undefined,
11
+ });
12
+ return DelegationIdentity.fromDelegation(sessionKey, chain);
13
+ };
14
+ export async function _createActor(interfaceFactory, canisterId, identity) {
15
+ const agent = new HttpAgent({ identity });
16
+ // Only fetch the root key when we're not in prod
17
+ if (process.env.II_ENV === 'development') {
18
+ await agent.fetchRootKey();
19
+ }
20
+ const actor = Actor.createActor(interfaceFactory, {
21
+ agent,
22
+ canisterId,
23
+ });
24
+ return { actor, agent };
25
+ }
26
+ export class BaseConnection {
27
+ constructor(identity, delegationIdentity, canisterId, interfaceFactory, actor, agent) {
28
+ this.identity = identity;
29
+ this.delegationIdentity = delegationIdentity;
30
+ this.canisterId = canisterId;
31
+ this.interfaceFactory = interfaceFactory;
32
+ this.actor = actor;
33
+ this.agent = agent;
34
+ }
35
+ async getActor() {
36
+ throw new Error('Method not implemented.');
37
+ }
38
+ async _getActor(canisterId, interfaceFactory, date) {
39
+ var _a, _b;
40
+ for (const { delegation } of this.delegationIdentity.getDelegation().delegations) {
41
+ // prettier-ignore
42
+ if (+new Date(Number(delegation.expiration / BigInt(1000000))) <= +Date.now()) {
43
+ this.actor = undefined;
44
+ break;
45
+ }
46
+ }
47
+ if (this.actor === undefined) {
48
+ // Create our actor with a DelegationIdentity to avoid re-prompting auth
49
+ this.delegationIdentity = await requestDelegation(this.identity, {
50
+ canisterId: (_a = this.canisterId) !== null && _a !== void 0 ? _a : canisterId,
51
+ date: date !== null && date !== void 0 ? date : undefined,
52
+ });
53
+ this.actor = (await _createActor(interfaceFactory, (_b = this.canisterId) !== null && _b !== void 0 ? _b : canisterId, this.delegationIdentity)).actor;
54
+ }
55
+ return this.actor;
56
+ }
57
+ }
58
+ export async function handleDelegation(message, key) {
59
+ const delegations = message.delegations.map(signedDelegation => {
60
+ return {
61
+ delegation: new Delegation(signedDelegation.delegation.pubkey, signedDelegation.delegation.expiration, signedDelegation.delegation.targets),
62
+ signature: signedDelegation.signature.buffer,
63
+ };
64
+ });
65
+ const delegationChain = DelegationChain.fromDelegations(delegations, message.userPublicKey.buffer);
66
+ return {
67
+ delegationChain,
68
+ delegationIdentity: DelegationIdentity.fromDelegation(key, delegationChain),
69
+ };
70
+ }
71
+ export const executeWithLogging = async (func) => {
72
+ try {
73
+ return await func();
74
+ }
75
+ catch (e) {
76
+ console.log(e);
77
+ throw e;
78
+ }
79
+ };
80
+ //# sourceMappingURL=baseConnection.js.map
@@ -0,0 +1 @@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 +1,53 @@
1
+ import { BaseConnection } from './baseConnection';
2
+ import LEDGER_SERVICE, { AccountIdentifier, BlockHeight } from '../canisters/ledger';
3
+ import { ActorSubclass, HttpAgent, SignIdentity } from '@dfinity/agent';
4
+ import { DelegationIdentity } from '@dfinity/identity';
5
+ import { CreateActorResult, SendOpts } from '../types';
6
+ export declare class LedgerConnection extends BaseConnection<LEDGER_SERVICE> {
7
+ identity: SignIdentity;
8
+ delegationIdentity: DelegationIdentity;
9
+ actor?: ActorSubclass<LEDGER_SERVICE> | undefined;
10
+ agent?: HttpAgent | undefined;
11
+ protected constructor(identity: SignIdentity, delegationIdentity: DelegationIdentity, actor?: ActorSubclass<LEDGER_SERVICE> | undefined, agent?: HttpAgent | undefined, legerCanisterId?: string);
12
+ /**
13
+ * create connection
14
+ * @param identity
15
+ * @param delegationIdentity
16
+ * @param legerCanisterId
17
+ * @param actor
18
+ * @param agent
19
+ * @function createConnection
20
+ * @returns {LedgerConnection}
21
+ */
22
+ static createConnection(identity: SignIdentity, delegationIdentity: DelegationIdentity, legerCanisterId?: string, actor?: ActorSubclass<LEDGER_SERVICE>, agent?: HttpAgent): LedgerConnection;
23
+ /**
24
+ * create Actor with DelegationIdentity
25
+ * @param delegationIdentity
26
+ * @param canisterId
27
+ * @param ledgerCanisterId
28
+ * @function {function name}
29
+ * @returns {type} {description}
30
+ */
31
+ static createActor(delegationIdentity: DelegationIdentity, ledgerCanisterId?: string): Promise<CreateActorResult<LEDGER_SERVICE>>;
32
+ static createConnectionWithII(identity: SignIdentity, delegationIdentity: DelegationIdentity, legerCanisterId?: string): Promise<LedgerConnection>;
33
+ static actorGetBalance(actor: ActorSubclass<LEDGER_SERVICE>, account: AccountIdentifier): Promise<bigint>;
34
+ static actorSend(actor: ActorSubclass<LEDGER_SERVICE>, { to, amount, sendOpts, }: {
35
+ to: AccountIdentifier;
36
+ amount: bigint;
37
+ sendOpts?: SendOpts;
38
+ }): Promise<BlockHeight>;
39
+ /**
40
+ * get NNS Actor, used internally
41
+ * @param canisterId
42
+ * @param ledgerCanisterId
43
+ * @function {function name}
44
+ * @returns {type} {description}
45
+ */
46
+ getLedgerActor(ledgerCanisterId?: string): Promise<ActorSubclass<LEDGER_SERVICE>>;
47
+ getBalance(account: AccountIdentifier): Promise<bigint>;
48
+ send({ to, amount, sendOpts, }: {
49
+ to: AccountIdentifier;
50
+ amount: bigint;
51
+ sendOpts: SendOpts;
52
+ }): Promise<BlockHeight>;
53
+ }
@@ -0,0 +1,130 @@
1
+ import { BaseConnection, executeWithLogging, _createActor } from './baseConnection';
2
+ import ledger_idl from '../canisters/ledger.idl';
3
+ import { fromSubAccountId } from '../utils/converter';
4
+ import { LEDGER_CANISTER_ID } from '../utils/constants';
5
+ // export const canisterIdPrincipal: Principal = Principal.fromText(LEDGER_CANISTER_ID);
6
+ export class LedgerConnection extends BaseConnection {
7
+ constructor(identity, delegationIdentity, actor, agent, legerCanisterId) {
8
+ super(identity, delegationIdentity, legerCanisterId !== null && legerCanisterId !== void 0 ? legerCanisterId : LEDGER_CANISTER_ID, ledger_idl, actor, agent);
9
+ this.identity = identity;
10
+ this.delegationIdentity = delegationIdentity;
11
+ this.actor = actor;
12
+ this.agent = agent;
13
+ }
14
+ /**
15
+ * create connection
16
+ * @param identity
17
+ * @param delegationIdentity
18
+ * @param legerCanisterId
19
+ * @param actor
20
+ * @param agent
21
+ * @function createConnection
22
+ * @returns {LedgerConnection}
23
+ */
24
+ static createConnection(identity, delegationIdentity, legerCanisterId, actor, agent) {
25
+ return new LedgerConnection(identity, delegationIdentity, actor, agent, legerCanisterId !== null && legerCanisterId !== void 0 ? legerCanisterId : LEDGER_CANISTER_ID);
26
+ }
27
+ /**
28
+ * create Actor with DelegationIdentity
29
+ * @param delegationIdentity
30
+ * @param canisterId
31
+ * @param ledgerCanisterId
32
+ * @function {function name}
33
+ * @returns {type} {description}
34
+ */
35
+ static async createActor(delegationIdentity, ledgerCanisterId) {
36
+ const actor = await _createActor(ledger_idl, ledgerCanisterId !== null && ledgerCanisterId !== void 0 ? ledgerCanisterId : LEDGER_CANISTER_ID, delegationIdentity);
37
+ return actor;
38
+ }
39
+ static async createConnectionWithII(identity, delegationIdentity, legerCanisterId) {
40
+ const actorResult = await LedgerConnection.createActor(delegationIdentity);
41
+ return LedgerConnection.createConnection(identity, delegationIdentity, legerCanisterId !== null && legerCanisterId !== void 0 ? legerCanisterId : LEDGER_CANISTER_ID, actorResult.actor, actorResult.agent);
42
+ }
43
+ static async actorGetBalance(actor, account) {
44
+ const response = await executeWithLogging(() => actor.account_balance_dfx({ account }));
45
+ return response.e8s;
46
+ }
47
+ static async actorSend(actor, { to, amount, sendOpts, }) {
48
+ const response = await executeWithLogging(() => {
49
+ var _a, _b, _c;
50
+ const defaultFee = BigInt(10000);
51
+ const defaultMemo = BigInt(Math.floor(Math.random() * 10000));
52
+ const subAccount = (sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.from_subaccount) === undefined
53
+ ? []
54
+ : Array.from([fromSubAccountId(sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.from_subaccount)]);
55
+ const createAtTime = (sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.created_at_time) === undefined
56
+ ? []
57
+ : Array.from([
58
+ {
59
+ timestamp_nanos: BigInt((_a = sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.created_at_time) === null || _a === void 0 ? void 0 : _a.getTime()),
60
+ },
61
+ ]);
62
+ const sendArgs = {
63
+ to: to,
64
+ fee: {
65
+ e8s: (_b = sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.fee) !== null && _b !== void 0 ? _b : defaultFee,
66
+ },
67
+ amount: { e8s: amount },
68
+ memo: (_c = sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.memo) !== null && _c !== void 0 ? _c : defaultMemo,
69
+ from_subaccount: subAccount,
70
+ created_at_time: createAtTime,
71
+ };
72
+ return actor.send_dfx(sendArgs);
73
+ });
74
+ return response;
75
+ }
76
+ /**
77
+ * get NNS Actor, used internally
78
+ * @param canisterId
79
+ * @param ledgerCanisterId
80
+ * @function {function name}
81
+ * @returns {type} {description}
82
+ */
83
+ async getLedgerActor(ledgerCanisterId) {
84
+ const actor = await this._getActor(ledgerCanisterId !== null && ledgerCanisterId !== void 0 ? ledgerCanisterId : LEDGER_CANISTER_ID, ledger_idl);
85
+ return actor;
86
+ }
87
+ async getBalance(account) {
88
+ const actor = await this.getLedgerActor();
89
+ const response = await executeWithLogging(() => actor.account_balance_dfx({ account }));
90
+ return response.e8s;
91
+ }
92
+ async send({ to, amount, sendOpts, }) {
93
+ const actor = await this.getLedgerActor();
94
+ const response = await executeWithLogging(() => {
95
+ var _a, _b, _c;
96
+ const defaultFee = BigInt(10000);
97
+ const defaultMemo = BigInt(Math.floor(Math.random() * 10000));
98
+ const subAccount = (sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.from_subaccount) === undefined
99
+ ? []
100
+ : Array.from([fromSubAccountId(sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.from_subaccount)]);
101
+ const createAtTime = (sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.created_at_time) === undefined
102
+ ? []
103
+ : Array.from([
104
+ {
105
+ timestamp_nanos: BigInt((_a = sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.created_at_time) === null || _a === void 0 ? void 0 : _a.getTime()),
106
+ },
107
+ ]);
108
+ const sendArgs = {
109
+ to: to,
110
+ fee: {
111
+ e8s: (_b = sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.fee) !== null && _b !== void 0 ? _b : defaultFee,
112
+ },
113
+ amount: { e8s: amount },
114
+ memo: (_c = sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.memo) !== null && _c !== void 0 ? _c : defaultMemo,
115
+ from_subaccount: subAccount,
116
+ created_at_time: createAtTime,
117
+ };
118
+ return actor.send_dfx(sendArgs);
119
+ });
120
+ return response;
121
+ }
122
+ }
123
+ // export const requestNNSDelegation = async (
124
+ // identity: SignIdentity,
125
+ // ): Promise<DelegationIdentity> => {
126
+ // const tenMinutesInMsec = 10 * 1000 * 60;
127
+ // const date = new Date(Date.now() + tenMinutesInMsec);
128
+ // return requestDelegation(identity, { canisterId, date });
129
+ // };
130
+ //# sourceMappingURL=ledgerConnection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ledgerConnection.js","sourceRoot":"","sources":["../../../src/connections/ledgerConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACpF,OAAO,UAAU,MAAM,yBAAyB,CAAC;AAUjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGxD,wFAAwF;AAExF,MAAM,OAAO,gBAAiB,SAAQ,cAA8B;IAClE,YACS,QAAsB,EACtB,kBAAsC,EACtC,KAAqC,EACrC,KAAiB,EACxB,eAAwB;QAExB,KAAK,CACH,QAAQ,EACR,kBAAkB,EAClB,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,kBAAkB,EACrC,UAAU,EACV,KAAK,EACL,KAAK,CACN,CAAC;QAbK,aAAQ,GAAR,QAAQ,CAAc;QACtB,uBAAkB,GAAlB,kBAAkB,CAAoB;QACtC,UAAK,GAAL,KAAK,CAAgC;QACrC,UAAK,GAAL,KAAK,CAAY;IAW1B,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,gBAAgB,CACrB,QAAsB,EACtB,kBAAsC,EACtC,eAAwB,EACxB,KAAqC,EACrC,KAAiB;QAEjB,OAAO,IAAI,gBAAgB,CACzB,QAAQ,EACR,kBAAkB,EAClB,KAAK,EACL,KAAK,EACL,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,kBAAkB,CACtC,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,KAAK,CAAC,WAAW,CACtB,kBAAsC,EACtC,gBA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G,EAAE,MAAM,EAAE;gBACvB,IAAI,EAAE,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,mCAAI,WAAW;gBACnC,eAAe,EAAE,UAAU;gBAE3B,eAAe,EAAE,YAAY;aAC9B,CAAC;YAEF,OAAO,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAED,8CAA8C;AAC9C,4BAA4B;AAC5B,sCAAsC;AACtC,6CAA6C;AAC7C,0DAA0D;AAC1D,8DAA8D;AAC9D,KAAK"}
@@ -0,0 +1,63 @@
1
+ import { ActorSubclass, HttpAgent, SignIdentity } from '@dfinity/agent';
2
+ import { DelegationIdentity } from '@dfinity/identity';
3
+ import { BaseConnection } from './baseConnection';
4
+ import NNS_SERVICE, { AccountDetails } from '../canisters/nns-dapp';
5
+ import { CreateActorResult } from '../types';
6
+ export declare class NNSConnection extends BaseConnection<NNS_SERVICE> {
7
+ identity: SignIdentity;
8
+ delegationIdentity: DelegationIdentity;
9
+ actor?: ActorSubclass<NNS_SERVICE> | undefined;
10
+ agent?: HttpAgent | undefined;
11
+ get accountDetails(): AccountDetails | undefined;
12
+ private _accountDetails?;
13
+ protected constructor(identity: SignIdentity, delegationIdentity: DelegationIdentity, actor?: ActorSubclass<NNS_SERVICE> | undefined, agent?: HttpAgent | undefined, nnsCanisterId?: string);
14
+ /**
15
+ * create connection
16
+ * @param identity
17
+ * @param delegationIdentity
18
+ * @param actor
19
+ * @param agent
20
+ * @function createConnection
21
+ * @returns {NNSConnection}
22
+ */
23
+ static createConnection(identity: SignIdentity, delegationIdentity: DelegationIdentity, actor?: ActorSubclass<NNS_SERVICE>, agent?: HttpAgent): NNSConnection;
24
+ /**
25
+ * create Actor with DelegationIdentity
26
+ * @param delegationIdentity
27
+ * @param nnsCanisterId
28
+ * @function {function name}
29
+ * @returns {type} {description}
30
+ */
31
+ static createActor(delegationIdentity: DelegationIdentity, nnsCanisterId?: string): Promise<CreateActorResult<NNS_SERVICE>>;
32
+ /**
33
+ * get NNS Actor, used internally
34
+ * @param nnsCanisterId
35
+ * @function {function name}
36
+ * @returns {type} {description}
37
+ */
38
+ getNNSActor(nnsCanisterId?: string): Promise<ActorSubclass<NNS_SERVICE>>;
39
+ /**
40
+ * get NNS Actor, used internally
41
+ * @param nnsCanisterId
42
+ * @function {function name}
43
+ * @returns {type} {description}
44
+ */
45
+ getNNSActorCert(nnsCanisterId?: string): Promise<ActorSubclass<NNS_SERVICE>>;
46
+ /**
47
+ * when NNSConnection is created, we can get account created to NNS.
48
+ * Even we can just calculate the login principal to NNS DApp, however,
49
+ * The NNS DApp stores and create account, thus, a new Identity login will get NO ACCOUNT created by default.
50
+ * We need to manually create account using `add_account` when no account found.
51
+ *
52
+ * @param cert
53
+ * @function {function name}
54
+ * @returns {type} {description}
55
+ */
56
+ getAccount(cert?: boolean): Promise<AccountDetails | undefined>;
57
+ /**
58
+ * create account when new identity logined to NNS
59
+ * @function {function name}
60
+ * @returns {type} {description}
61
+ */
62
+ addAccount(): Promise<string>;
63
+ }