@astrox/connection 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +23 -0
  3. package/lib/cjs/canisters/internet_identity_idl.d.ts +7 -0
  4. package/lib/cjs/canisters/internet_identity_idl.js +101 -0
  5. package/lib/cjs/canisters/internet_identity_idl.js.map +1 -0
  6. package/lib/cjs/canisters/ledger.idl.d.ts +7 -0
  7. package/lib/cjs/canisters/ledger.idl.js +81 -0
  8. package/lib/cjs/canisters/ledger.idl.js.map +1 -0
  9. package/lib/cjs/canisters/me.idl.d.ts +7 -0
  10. package/lib/cjs/canisters/me.idl.js +125 -0
  11. package/lib/cjs/canisters/me.idl.js.map +1 -0
  12. package/lib/cjs/canisters/nns-dapp-cert.idl.d.ts +7 -0
  13. package/lib/cjs/canisters/nns-dapp-cert.idl.js +86 -0
  14. package/lib/cjs/canisters/nns-dapp-cert.idl.js.map +1 -0
  15. package/lib/cjs/canisters/nns-dapp.idl.d.ts +7 -0
  16. package/lib/cjs/canisters/nns-dapp.idl.js +184 -0
  17. package/lib/cjs/canisters/nns-dapp.idl.js.map +1 -0
  18. package/lib/cjs/connections/baseConnection.d.ts +52 -0
  19. package/lib/cjs/connections/baseConnection.js +87 -0
  20. package/lib/cjs/connections/baseConnection.js.map +1 -0
  21. package/lib/cjs/connections/ledgerConnection.d.ts +57 -0
  22. package/lib/cjs/connections/ledgerConnection.js +135 -0
  23. package/lib/cjs/connections/ledgerConnection.js.map +1 -0
  24. package/lib/cjs/connections/nnsConnection.d.ts +62 -0
  25. package/lib/cjs/connections/nnsConnection.js +166 -0
  26. package/lib/cjs/connections/nnsConnection.js.map +1 -0
  27. package/lib/cjs/ic/icAuthClient.d.ts +31 -0
  28. package/lib/cjs/ic/icAuthClient.js +233 -0
  29. package/lib/cjs/ic/icAuthClient.js.map +1 -0
  30. package/lib/cjs/ic/icConnect.d.ts +32 -0
  31. package/lib/cjs/ic/icConnect.js +181 -0
  32. package/lib/cjs/ic/icConnect.js.map +1 -0
  33. package/lib/cjs/ic/icStorage.d.ts +16 -0
  34. package/lib/cjs/ic/icStorage.js +49 -0
  35. package/lib/cjs/ic/icStorage.js.map +1 -0
  36. package/lib/cjs/ic/icWindow.d.ts +7 -0
  37. package/lib/cjs/ic/icWindow.js +20 -0
  38. package/lib/cjs/ic/icWindow.js.map +1 -0
  39. package/lib/cjs/ic/index.d.ts +2 -0
  40. package/lib/cjs/ic/index.js +7 -0
  41. package/lib/cjs/ic/index.js.map +1 -0
  42. package/lib/cjs/ic/types.d.ts +129 -0
  43. package/lib/cjs/ic/types.js +17 -0
  44. package/lib/cjs/ic/types.js.map +1 -0
  45. package/lib/cjs/index.d.ts +5 -0
  46. package/lib/cjs/index.js +18 -0
  47. package/lib/cjs/index.js.map +1 -0
  48. package/lib/cjs/utils/common/types.d.ts +15 -0
  49. package/lib/cjs/utils/common/types.js +12 -0
  50. package/lib/cjs/utils/common/types.js.map +1 -0
  51. package/lib/cjs/utils/constants.d.ts +6 -0
  52. package/lib/cjs/utils/constants.js +13 -0
  53. package/lib/cjs/utils/constants.js.map +1 -0
  54. package/lib/cjs/utils/converter.d.ts +32 -0
  55. package/lib/cjs/utils/converter.js +130 -0
  56. package/lib/cjs/utils/converter.js.map +1 -0
  57. package/lib/cjs/utils/index.d.ts +3 -0
  58. package/lib/cjs/utils/index.js +16 -0
  59. package/lib/cjs/utils/index.js.map +1 -0
  60. package/lib/esm/canisters/internet_identity_idl.d.ts +7 -0
  61. package/lib/esm/canisters/internet_identity_idl.js +98 -0
  62. package/lib/esm/canisters/internet_identity_idl.js.map +1 -0
  63. package/lib/esm/canisters/ledger.idl.d.ts +7 -0
  64. package/lib/esm/canisters/ledger.idl.js +78 -0
  65. package/lib/esm/canisters/ledger.idl.js.map +1 -0
  66. package/lib/esm/canisters/me.idl.d.ts +7 -0
  67. package/lib/esm/canisters/me.idl.js +122 -0
  68. package/lib/esm/canisters/me.idl.js.map +1 -0
  69. package/lib/esm/canisters/nns-dapp-cert.idl.d.ts +7 -0
  70. package/lib/esm/canisters/nns-dapp-cert.idl.js +83 -0
  71. package/lib/esm/canisters/nns-dapp-cert.idl.js.map +1 -0
  72. package/lib/esm/canisters/nns-dapp.idl.d.ts +7 -0
  73. package/lib/esm/canisters/nns-dapp.idl.js +181 -0
  74. package/lib/esm/canisters/nns-dapp.idl.js.map +1 -0
  75. package/lib/esm/connections/baseConnection.d.ts +52 -0
  76. package/lib/esm/connections/baseConnection.js +80 -0
  77. package/lib/esm/connections/baseConnection.js.map +1 -0
  78. package/lib/esm/connections/ledgerConnection.d.ts +57 -0
  79. package/lib/esm/connections/ledgerConnection.js +128 -0
  80. package/lib/esm/connections/ledgerConnection.js.map +1 -0
  81. package/lib/esm/connections/nnsConnection.d.ts +62 -0
  82. package/lib/esm/connections/nnsConnection.js +159 -0
  83. package/lib/esm/connections/nnsConnection.js.map +1 -0
  84. package/lib/esm/ic/icAuthClient.d.ts +31 -0
  85. package/lib/esm/ic/icAuthClient.js +229 -0
  86. package/lib/esm/ic/icAuthClient.js.map +1 -0
  87. package/lib/esm/ic/icConnect.d.ts +32 -0
  88. package/lib/esm/ic/icConnect.js +177 -0
  89. package/lib/esm/ic/icConnect.js.map +1 -0
  90. package/lib/esm/ic/icStorage.d.ts +16 -0
  91. package/lib/esm/ic/icStorage.js +44 -0
  92. package/lib/esm/ic/icStorage.js.map +1 -0
  93. package/lib/esm/ic/icWindow.d.ts +7 -0
  94. package/lib/esm/ic/icWindow.js +16 -0
  95. package/lib/esm/ic/icWindow.js.map +1 -0
  96. package/lib/esm/ic/index.d.ts +2 -0
  97. package/lib/esm/ic/index.js +3 -0
  98. package/lib/esm/ic/index.js.map +1 -0
  99. package/lib/esm/ic/types.d.ts +129 -0
  100. package/lib/esm/ic/types.js +14 -0
  101. package/lib/esm/ic/types.js.map +1 -0
  102. package/lib/esm/index.d.ts +5 -0
  103. package/lib/esm/index.js +6 -0
  104. package/lib/esm/index.js.map +1 -0
  105. package/lib/esm/utils/common/types.d.ts +15 -0
  106. package/lib/esm/utils/common/types.js +9 -0
  107. package/lib/esm/utils/common/types.js.map +1 -0
  108. package/lib/esm/utils/constants.d.ts +6 -0
  109. package/lib/esm/utils/constants.js +10 -0
  110. package/lib/esm/utils/constants.js.map +1 -0
  111. package/lib/esm/utils/converter.d.ts +32 -0
  112. package/lib/esm/utils/converter.js +124 -0
  113. package/lib/esm/utils/converter.js.map +1 -0
  114. package/lib/esm/utils/index.d.ts +3 -0
  115. package/lib/esm/utils/index.js +4 -0
  116. package/lib/esm/utils/index.js.map +1 -0
  117. package/lib/tsconfig-cjs.tsbuildinfo +2834 -0
  118. package/lib/tsconfig.tsbuildinfo +2833 -0
  119. package/package.json +53 -0
@@ -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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nns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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,52 @@
1
+ import { ActorSubclass, HttpAgent, SignIdentity } from '@dfinity/agent';
2
+ import { InterfaceFactory } from '@dfinity/candid/lib/cjs/idl';
3
+ import { DelegationChain, DelegationIdentity } from '@dfinity/identity';
4
+ import { Principal } from '@dfinity/principal';
5
+ export interface CreateActorResult<T> {
6
+ actor: ActorSubclass<T>;
7
+ agent: HttpAgent;
8
+ }
9
+ export declare function createConnection<T>(identity: SignIdentity, delegationIdentity: DelegationIdentity, canisterId: string, interfaceFactory: InterfaceFactory, actor?: ActorSubclass<T>, agent?: HttpAgent): BaseConnection<T>;
10
+ export declare const requestDelegation: (identity: SignIdentity, { canisterId, date }: {
11
+ canisterId?: string | undefined;
12
+ date?: Date | undefined;
13
+ }) => Promise<DelegationIdentity>;
14
+ export declare function _createActor<T>(interfaceFactory: InterfaceFactory, canisterId: string, identity?: SignIdentity): Promise<CreateActorResult<T>>;
15
+ export interface AbstractConnection<T> {
16
+ identity: SignIdentity;
17
+ delegationIdentity: DelegationIdentity;
18
+ actor?: ActorSubclass<T>;
19
+ agent?: HttpAgent;
20
+ canisterId?: string;
21
+ getActor(): Promise<ActorSubclass<T>>;
22
+ }
23
+ export declare class BaseConnection<T> implements AbstractConnection<T> {
24
+ identity: SignIdentity;
25
+ delegationIdentity: DelegationIdentity;
26
+ canisterId: string;
27
+ interfaceFactory: InterfaceFactory;
28
+ actor?: ActorSubclass<T> | undefined;
29
+ agent?: HttpAgent | undefined;
30
+ constructor(identity: SignIdentity, delegationIdentity: DelegationIdentity, canisterId: string, interfaceFactory: InterfaceFactory, actor?: ActorSubclass<T> | undefined, agent?: HttpAgent | undefined);
31
+ getActor(): Promise<ActorSubclass<T>>;
32
+ protected _getActor(canisterId: string, interfaceFactory: InterfaceFactory, date?: Date): Promise<ActorSubclass<T>>;
33
+ }
34
+ export interface IIDelegationResult {
35
+ delegation: {
36
+ pubkey: Uint8Array;
37
+ expiration: bigint;
38
+ targets?: Principal[];
39
+ };
40
+ signature: Uint8Array;
41
+ }
42
+ export interface DelegationMessage {
43
+ kind: string;
44
+ delegations: IIDelegationResult[];
45
+ userPublicKey: Uint8Array;
46
+ }
47
+ export interface DelegationResult {
48
+ delegationIdentity: DelegationIdentity;
49
+ delegationChain: DelegationChain;
50
+ }
51
+ export declare function handleDelegation(message: DelegationMessage, key: SignIdentity): Promise<DelegationResult>;
52
+ 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 @@
1
+ {"version":3,"file":"baseConnection.js","sourceRoot":"","sources":["../../../src/connections/baseConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAGL,SAAS,GAGV,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAO/C,MAAM,UAAU,gBAAgB,CAC9B,QAAsB,EACtB,kBAAsC,EACtC,UAAkB,EAClB,gBAAkC,EAClC,KAAwB,EACxB,KAAiB;IAEjB,OAAO,IAAI,cAAc,CACvB,QAAQ,EACR,kBAAkB,EAClB,UAAU,EACV,gBAAgB,EAChB,KAAK,EACL,KAAK,CACN,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EACpC,QAAsB,EACtB,EAAE,UAAU,EAAE,IAAI,EAAwC,EAC7B,EAAE;IAC/B,MAAM,UAAU,GAAG,kBAAkB,CAAC,QAAQ,EAAE,CAAC;IACjD,MAAM,KAAK,GAAG,MAAM,eAAe,CAAC,MAAM,CACxC,QAAQ,EACR,UAAU,CAAC,YAAY,EAAE,EACzB,IAAI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AAe,CAAC,eAAe,CACrD,WAAW,EACX,OAAO,CAAC,aAAa,CAAC,MAA6B,CACpD,CAAC;IACF,OAAO;QACL,eAAe;QACf,kBAAkB,EAAE,kBAAkB,CAAC,cAAc,CAAC,GAAG,EAAE,eAAe,CAAC;KAC5E,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAK,IAAsB,EAAc,EAAE;IAChF,IAAI;QACF,OAAO,MAAM,IAAI,EAAE,CAAC;KACrB;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACf,MAAM,CAAC,CAAC;KACT;AACH,CAAC,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { BaseConnection, CreateActorResult } from './baseConnection';
2
+ import LEDGER_SERVICE, { AccountIdentifier, BlockHeight, Memo } from '../canisters/ledger';
3
+ import { ActorSubclass, HttpAgent, SignIdentity } from '@dfinity/agent';
4
+ import { DelegationIdentity } from '@dfinity/identity';
5
+ export interface SendOpts {
6
+ fee?: bigint;
7
+ memo?: Memo;
8
+ from_subaccount?: number;
9
+ created_at_time?: Date;
10
+ }
11
+ export declare class LedgerConnection extends BaseConnection<LEDGER_SERVICE> {
12
+ identity: SignIdentity;
13
+ delegationIdentity: DelegationIdentity;
14
+ actor?: ActorSubclass<LEDGER_SERVICE> | undefined;
15
+ agent?: HttpAgent | undefined;
16
+ protected constructor(identity: SignIdentity, delegationIdentity: DelegationIdentity, actor?: ActorSubclass<LEDGER_SERVICE> | undefined, agent?: HttpAgent | undefined, legerCanisterId?: string);
17
+ /**
18
+ * create connection
19
+ * @param identity
20
+ * @param delegationIdentity
21
+ * @param actor
22
+ * @param agent
23
+ * @function createConnection
24
+ * @returns {LedgerConnection}
25
+ */
26
+ static createConnection(identity: SignIdentity, delegationIdentity: DelegationIdentity, actor?: ActorSubclass<LEDGER_SERVICE>, agent?: HttpAgent): LedgerConnection;
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 createActor(delegationIdentity: DelegationIdentity, ledgerCanisterId?: string): Promise<CreateActorResult<LEDGER_SERVICE>>;
36
+ static createConnectionWithII(identity: SignIdentity, delegationIdentity: DelegationIdentity): Promise<LedgerConnection>;
37
+ static actorGetBalance(actor: ActorSubclass<LEDGER_SERVICE>, account: AccountIdentifier): Promise<bigint>;
38
+ static actorSend(actor: ActorSubclass<LEDGER_SERVICE>, { to, amount, sendOpts, }: {
39
+ to: AccountIdentifier;
40
+ amount: bigint;
41
+ sendOpts?: SendOpts;
42
+ }): Promise<BlockHeight>;
43
+ /**
44
+ * get NNS Actor, used internally
45
+ * @param canisterId
46
+ * @param ledgerCanisterId
47
+ * @function {function name}
48
+ * @returns {type} {description}
49
+ */
50
+ getLedgerActor(ledgerCanisterId?: string): Promise<ActorSubclass<LEDGER_SERVICE>>;
51
+ getBalance(account: AccountIdentifier): Promise<bigint>;
52
+ send({ to, amount, sendOpts, }: {
53
+ to: AccountIdentifier;
54
+ amount: bigint;
55
+ sendOpts: SendOpts;
56
+ }): Promise<BlockHeight>;
57
+ }
@@ -0,0 +1,128 @@
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 class LedgerConnection extends BaseConnection {
6
+ constructor(identity, delegationIdentity, actor, agent, legerCanisterId) {
7
+ super(identity, delegationIdentity, legerCanisterId !== null && legerCanisterId !== void 0 ? legerCanisterId : LEDGER_CANISTER_ID, ledger_idl, actor, agent);
8
+ this.identity = identity;
9
+ this.delegationIdentity = delegationIdentity;
10
+ this.actor = actor;
11
+ this.agent = agent;
12
+ }
13
+ /**
14
+ * create connection
15
+ * @param identity
16
+ * @param delegationIdentity
17
+ * @param actor
18
+ * @param agent
19
+ * @function createConnection
20
+ * @returns {LedgerConnection}
21
+ */
22
+ static createConnection(identity, delegationIdentity, actor, agent) {
23
+ return new LedgerConnection(identity, delegationIdentity, actor, agent);
24
+ }
25
+ /**
26
+ * create Actor with DelegationIdentity
27
+ * @param delegationIdentity
28
+ * @param canisterId
29
+ * @param ledgerCanisterId
30
+ * @function {function name}
31
+ * @returns {type} {description}
32
+ */
33
+ static async createActor(delegationIdentity, ledgerCanisterId) {
34
+ const actor = await _createActor(ledger_idl, ledgerCanisterId !== null && ledgerCanisterId !== void 0 ? ledgerCanisterId : LEDGER_CANISTER_ID, delegationIdentity);
35
+ return actor;
36
+ }
37
+ static async createConnectionWithII(identity, delegationIdentity) {
38
+ const actorResult = await LedgerConnection.createActor(delegationIdentity);
39
+ return LedgerConnection.createConnection(identity, delegationIdentity, actorResult.actor, actorResult.agent);
40
+ }
41
+ static async actorGetBalance(actor, account) {
42
+ const response = await executeWithLogging(() => actor.account_balance_dfx({ account }));
43
+ return response.e8s;
44
+ }
45
+ static async actorSend(actor, { to, amount, sendOpts, }) {
46
+ const response = await executeWithLogging(() => {
47
+ var _a, _b, _c;
48
+ const defaultFee = BigInt(10000);
49
+ const defaultMemo = BigInt(Math.floor(Math.random() * 10000));
50
+ const subAccount = (sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.from_subaccount) === undefined
51
+ ? []
52
+ : Array.from([fromSubAccountId(sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.from_subaccount)]);
53
+ const createAtTime = (sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.created_at_time) === undefined
54
+ ? []
55
+ : Array.from([
56
+ {
57
+ timestamp_nanos: BigInt((_a = sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.created_at_time) === null || _a === void 0 ? void 0 : _a.getTime()),
58
+ },
59
+ ]);
60
+ const sendArgs = {
61
+ to: to,
62
+ fee: {
63
+ e8s: (_b = sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.fee) !== null && _b !== void 0 ? _b : defaultFee,
64
+ },
65
+ amount: { e8s: amount },
66
+ memo: (_c = sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.memo) !== null && _c !== void 0 ? _c : defaultMemo,
67
+ from_subaccount: subAccount,
68
+ created_at_time: createAtTime,
69
+ };
70
+ return actor.send_dfx(sendArgs);
71
+ });
72
+ return response;
73
+ }
74
+ /**
75
+ * get NNS Actor, used internally
76
+ * @param canisterId
77
+ * @param ledgerCanisterId
78
+ * @function {function name}
79
+ * @returns {type} {description}
80
+ */
81
+ async getLedgerActor(ledgerCanisterId) {
82
+ const actor = await this._getActor(ledgerCanisterId !== null && ledgerCanisterId !== void 0 ? ledgerCanisterId : LEDGER_CANISTER_ID, ledger_idl);
83
+ return actor;
84
+ }
85
+ async getBalance(account) {
86
+ const actor = await this.getLedgerActor();
87
+ const response = await executeWithLogging(() => actor.account_balance_dfx({ account }));
88
+ return response.e8s;
89
+ }
90
+ async send({ to, amount, sendOpts, }) {
91
+ const actor = await this.getLedgerActor();
92
+ const response = await executeWithLogging(() => {
93
+ var _a, _b, _c;
94
+ const defaultFee = BigInt(10000);
95
+ const defaultMemo = BigInt(Math.floor(Math.random() * 10000));
96
+ const subAccount = (sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.from_subaccount) === undefined
97
+ ? []
98
+ : Array.from([fromSubAccountId(sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.from_subaccount)]);
99
+ const createAtTime = (sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.created_at_time) === undefined
100
+ ? []
101
+ : Array.from([
102
+ {
103
+ timestamp_nanos: BigInt((_a = sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.created_at_time) === null || _a === void 0 ? void 0 : _a.getTime()),
104
+ },
105
+ ]);
106
+ const sendArgs = {
107
+ to: to,
108
+ fee: {
109
+ e8s: (_b = sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.fee) !== null && _b !== void 0 ? _b : defaultFee,
110
+ },
111
+ amount: { e8s: amount },
112
+ memo: (_c = sendOpts === null || sendOpts === void 0 ? void 0 : sendOpts.memo) !== null && _c !== void 0 ? _c : defaultMemo,
113
+ from_subaccount: subAccount,
114
+ created_at_time: createAtTime,
115
+ };
116
+ return actor.send_dfx(sendArgs);
117
+ });
118
+ return response;
119
+ }
120
+ }
121
+ // export const requestNNSDelegation = async (
122
+ // identity: SignIdentity,
123
+ // ): Promise<DelegationIdentity> => {
124
+ // const tenMinutesInMsec = 10 * 1000 * 60;
125
+ // const date = new Date(Date.now() + tenMinutesInMsec);
126
+ // return requestDelegation(identity, { canisterId, date });
127
+ // };
128
+ //# sourceMappingURL=ledgerConnection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ledgerConnection.js","sourceRoot":"","sources":["../../../src/connections/ledgerConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAEd,kBAAkB,EAClB,YAAY,GACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,UAAU,MAAM,yBAAyB,CAAC;AAUjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAWxD,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;;;;;;;;OAQG;IACH,MAAM,CAAC,gBAAgB,CACrB,QAAsB,EACtB,kBAAsC,EACtC,KAAqC,EACrC,K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,QAAQ,uBAAR,QAAQ,CAAE,GAAG,mCAAI,UAAU;iBACjC;gBACD,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE;gBACvB,IAAI,QAAE,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,62 @@
1
+ import { ActorSubclass, HttpAgent, SignIdentity } from '@dfinity/agent';
2
+ import { DelegationIdentity } from '@dfinity/identity';
3
+ import { BaseConnection, CreateActorResult } from './baseConnection';
4
+ import NNS_SERVICE, { AccountDetails } from '../canisters/nns-dapp';
5
+ export declare class NNSConnection extends BaseConnection<NNS_SERVICE> {
6
+ identity: SignIdentity;
7
+ delegationIdentity: DelegationIdentity;
8
+ actor?: ActorSubclass<NNS_SERVICE> | undefined;
9
+ agent?: HttpAgent | undefined;
10
+ get accountDetails(): AccountDetails | undefined;
11
+ private _accountDetails?;
12
+ protected constructor(identity: SignIdentity, delegationIdentity: DelegationIdentity, actor?: ActorSubclass<NNS_SERVICE> | undefined, agent?: HttpAgent | undefined, nnsCanisterId?: string);
13
+ /**
14
+ * create connection
15
+ * @param identity
16
+ * @param delegationIdentity
17
+ * @param actor
18
+ * @param agent
19
+ * @function createConnection
20
+ * @returns {NNSConnection}
21
+ */
22
+ static createConnection(identity: SignIdentity, delegationIdentity: DelegationIdentity, actor?: ActorSubclass<NNS_SERVICE>, agent?: HttpAgent): NNSConnection;
23
+ /**
24
+ * create Actor with DelegationIdentity
25
+ * @param delegationIdentity
26
+ * @param nnsCanisterId
27
+ * @function {function name}
28
+ * @returns {type} {description}
29
+ */
30
+ static createActor(delegationIdentity: DelegationIdentity, nnsCanisterId?: string): Promise<CreateActorResult<NNS_SERVICE>>;
31
+ /**
32
+ * get NNS Actor, used internally
33
+ * @param nnsCanisterId
34
+ * @function {function name}
35
+ * @returns {type} {description}
36
+ */
37
+ getNNSActor(nnsCanisterId?: string): Promise<ActorSubclass<NNS_SERVICE>>;
38
+ /**
39
+ * get NNS Actor, used internally
40
+ * @param nnsCanisterId
41
+ * @function {function name}
42
+ * @returns {type} {description}
43
+ */
44
+ getNNSActorCert(nnsCanisterId?: string): Promise<ActorSubclass<NNS_SERVICE>>;
45
+ /**
46
+ * when NNSConnection is created, we can get account created to NNS.
47
+ * Even we can just calculate the login principal to NNS DApp, however,
48
+ * The NNS DApp stores and create account, thus, a new Identity login will get NO ACCOUNT created by default.
49
+ * We need to manually create account using `add_account` when no account found.
50
+ *
51
+ * @param cert
52
+ * @function {function name}
53
+ * @returns {type} {description}
54
+ */
55
+ getAccount(cert?: boolean): Promise<AccountDetails | undefined>;
56
+ /**
57
+ * create account when new identity logined to NNS
58
+ * @function {function name}
59
+ * @returns {type} {description}
60
+ */
61
+ addAccount(): Promise<string>;
62
+ }