@astrox/connection 0.0.20 → 0.0.24

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 (123) hide show
  1. package/lib/tsconfig.tsbuildinfo +1 -2838
  2. package/package.json +2 -2
  3. package/lib/cjs/canisters/internet_identity_idl.d.ts +0 -7
  4. package/lib/cjs/canisters/internet_identity_idl.js +0 -101
  5. package/lib/cjs/canisters/internet_identity_idl.js.map +0 -1
  6. package/lib/cjs/canisters/ledger.idl.d.ts +0 -7
  7. package/lib/cjs/canisters/ledger.idl.js +0 -81
  8. package/lib/cjs/canisters/ledger.idl.js.map +0 -1
  9. package/lib/cjs/canisters/me.idl.d.ts +0 -7
  10. package/lib/cjs/canisters/me.idl.js +0 -125
  11. package/lib/cjs/canisters/me.idl.js.map +0 -1
  12. package/lib/cjs/canisters/nns-dapp-cert.idl.d.ts +0 -7
  13. package/lib/cjs/canisters/nns-dapp-cert.idl.js +0 -86
  14. package/lib/cjs/canisters/nns-dapp-cert.idl.js.map +0 -1
  15. package/lib/cjs/canisters/nns-dapp.idl.d.ts +0 -7
  16. package/lib/cjs/canisters/nns-dapp.idl.js +0 -184
  17. package/lib/cjs/canisters/nns-dapp.idl.js.map +0 -1
  18. package/lib/cjs/connections/baseConnection.d.ts +0 -23
  19. package/lib/cjs/connections/baseConnection.js +0 -87
  20. package/lib/cjs/connections/baseConnection.js.map +0 -1
  21. package/lib/cjs/connections/ledgerConnection.d.ts +0 -53
  22. package/lib/cjs/connections/ledgerConnection.js +0 -137
  23. package/lib/cjs/connections/ledgerConnection.js.map +0 -1
  24. package/lib/cjs/connections/nnsConnection.d.ts +0 -63
  25. package/lib/cjs/connections/nnsConnection.js +0 -161
  26. package/lib/cjs/connections/nnsConnection.js.map +0 -1
  27. package/lib/cjs/ic/icAuthClient.d.ts +0 -31
  28. package/lib/cjs/ic/icAuthClient.js +0 -235
  29. package/lib/cjs/ic/icAuthClient.js.map +0 -1
  30. package/lib/cjs/ic/icConnect.d.ts +0 -35
  31. package/lib/cjs/ic/icConnect.js +0 -194
  32. package/lib/cjs/ic/icConnect.js.map +0 -1
  33. package/lib/cjs/ic/icStorage.d.ts +0 -16
  34. package/lib/cjs/ic/icStorage.js +0 -49
  35. package/lib/cjs/ic/icStorage.js.map +0 -1
  36. package/lib/cjs/ic/icWindow.d.ts +0 -7
  37. package/lib/cjs/ic/icWindow.js +0 -20
  38. package/lib/cjs/ic/icWindow.js.map +0 -1
  39. package/lib/cjs/ic/index.d.ts +0 -2
  40. package/lib/cjs/ic/index.js +0 -7
  41. package/lib/cjs/ic/index.js.map +0 -1
  42. package/lib/cjs/ic/types.d.ts +0 -129
  43. package/lib/cjs/ic/types.js +0 -17
  44. package/lib/cjs/ic/types.js.map +0 -1
  45. package/lib/cjs/index.d.ts +0 -5
  46. package/lib/cjs/index.js +0 -18
  47. package/lib/cjs/index.js.map +0 -1
  48. package/lib/cjs/types/index.d.ts +0 -175
  49. package/lib/cjs/types/index.js +0 -17
  50. package/lib/cjs/types/index.js.map +0 -1
  51. package/lib/cjs/utils/common/types.d.ts +0 -15
  52. package/lib/cjs/utils/common/types.js +0 -12
  53. package/lib/cjs/utils/common/types.js.map +0 -1
  54. package/lib/cjs/utils/constants.d.ts +0 -6
  55. package/lib/cjs/utils/constants.js +0 -13
  56. package/lib/cjs/utils/constants.js.map +0 -1
  57. package/lib/cjs/utils/converter.d.ts +0 -32
  58. package/lib/cjs/utils/converter.js +0 -130
  59. package/lib/cjs/utils/converter.js.map +0 -1
  60. package/lib/cjs/utils/index.d.ts +0 -3
  61. package/lib/cjs/utils/index.js +0 -16
  62. package/lib/cjs/utils/index.js.map +0 -1
  63. package/lib/esm/canisters/internet_identity_idl.d.ts +0 -7
  64. package/lib/esm/canisters/internet_identity_idl.js +0 -98
  65. package/lib/esm/canisters/internet_identity_idl.js.map +0 -1
  66. package/lib/esm/canisters/ledger.idl.d.ts +0 -7
  67. package/lib/esm/canisters/ledger.idl.js +0 -78
  68. package/lib/esm/canisters/ledger.idl.js.map +0 -1
  69. package/lib/esm/canisters/me.idl.d.ts +0 -7
  70. package/lib/esm/canisters/me.idl.js +0 -122
  71. package/lib/esm/canisters/me.idl.js.map +0 -1
  72. package/lib/esm/canisters/nns-dapp-cert.idl.d.ts +0 -7
  73. package/lib/esm/canisters/nns-dapp-cert.idl.js +0 -83
  74. package/lib/esm/canisters/nns-dapp-cert.idl.js.map +0 -1
  75. package/lib/esm/canisters/nns-dapp.idl.d.ts +0 -7
  76. package/lib/esm/canisters/nns-dapp.idl.js +0 -181
  77. package/lib/esm/canisters/nns-dapp.idl.js.map +0 -1
  78. package/lib/esm/connections/baseConnection.d.ts +0 -23
  79. package/lib/esm/connections/baseConnection.js +0 -80
  80. package/lib/esm/connections/baseConnection.js.map +0 -1
  81. package/lib/esm/connections/ledgerConnection.d.ts +0 -53
  82. package/lib/esm/connections/ledgerConnection.js +0 -130
  83. package/lib/esm/connections/ledgerConnection.js.map +0 -1
  84. package/lib/esm/connections/nnsConnection.d.ts +0 -63
  85. package/lib/esm/connections/nnsConnection.js +0 -154
  86. package/lib/esm/connections/nnsConnection.js.map +0 -1
  87. package/lib/esm/ic/icAuthClient.d.ts +0 -31
  88. package/lib/esm/ic/icAuthClient.js +0 -231
  89. package/lib/esm/ic/icAuthClient.js.map +0 -1
  90. package/lib/esm/ic/icConnect.d.ts +0 -35
  91. package/lib/esm/ic/icConnect.js +0 -190
  92. package/lib/esm/ic/icConnect.js.map +0 -1
  93. package/lib/esm/ic/icStorage.d.ts +0 -16
  94. package/lib/esm/ic/icStorage.js +0 -44
  95. package/lib/esm/ic/icStorage.js.map +0 -1
  96. package/lib/esm/ic/icWindow.d.ts +0 -7
  97. package/lib/esm/ic/icWindow.js +0 -16
  98. package/lib/esm/ic/icWindow.js.map +0 -1
  99. package/lib/esm/ic/index.d.ts +0 -2
  100. package/lib/esm/ic/index.js +0 -3
  101. package/lib/esm/ic/index.js.map +0 -1
  102. package/lib/esm/ic/types.d.ts +0 -129
  103. package/lib/esm/ic/types.js +0 -14
  104. package/lib/esm/ic/types.js.map +0 -1
  105. package/lib/esm/index.d.ts +0 -5
  106. package/lib/esm/index.js +0 -6
  107. package/lib/esm/index.js.map +0 -1
  108. package/lib/esm/types/index.d.ts +0 -175
  109. package/lib/esm/types/index.js +0 -14
  110. package/lib/esm/types/index.js.map +0 -1
  111. package/lib/esm/utils/common/types.d.ts +0 -15
  112. package/lib/esm/utils/common/types.js +0 -9
  113. package/lib/esm/utils/common/types.js.map +0 -1
  114. package/lib/esm/utils/constants.d.ts +0 -6
  115. package/lib/esm/utils/constants.js +0 -10
  116. package/lib/esm/utils/constants.js.map +0 -1
  117. package/lib/esm/utils/converter.d.ts +0 -32
  118. package/lib/esm/utils/converter.js +0 -124
  119. package/lib/esm/utils/converter.js.map +0 -1
  120. package/lib/esm/utils/index.d.ts +0 -3
  121. package/lib/esm/utils/index.js +0 -4
  122. package/lib/esm/utils/index.js.map +0 -1
  123. package/lib/tsconfig-cjs.tsbuildinfo +0 -2839
@@ -1,175 +0,0 @@
1
- import { ActorSubclass, HttpAgent, SignIdentity } from '@dfinity/agent';
2
- import { Principal } from '@dfinity/principal';
3
- import { AccountIdentifier, Memo } from '../utils/common/types';
4
- import { DelegationChain, DelegationIdentity } from '@dfinity/identity';
5
- import { IC } from 'src/ic';
6
- export interface IIDelegationResult {
7
- delegation: {
8
- pubkey: Uint8Array;
9
- expiration: bigint;
10
- targets?: Principal[];
11
- };
12
- signature: Uint8Array;
13
- }
14
- export interface DelegationMessage {
15
- kind: string;
16
- delegations: IIDelegationResult[];
17
- userPublicKey: Uint8Array;
18
- }
19
- export interface HandleDelegationResult {
20
- delegationChain: DelegationChain;
21
- delegationIdentity: DelegationIdentity;
22
- }
23
- export interface AbstractConnection<T> {
24
- identity: SignIdentity;
25
- delegationIdentity: DelegationIdentity;
26
- actor?: ActorSubclass<T>;
27
- agent?: HttpAgent;
28
- canisterId?: string;
29
- getActor(): Promise<ActorSubclass<T>>;
30
- }
31
- export interface CreateActorResult<T> {
32
- actor: ActorSubclass<T>;
33
- agent: HttpAgent;
34
- }
35
- export interface SendOpts {
36
- fee?: bigint;
37
- memo?: Memo;
38
- from_subaccount?: number;
39
- created_at_time?: Date;
40
- }
41
- /**
42
- * List of options for creating an {@link AuthClient}.
43
- */
44
- export interface AuthClientCreateOptions {
45
- /**
46
- * An identity to use as the base
47
- */
48
- identity?: SignIdentity;
49
- /**
50
- * Optional storage with get, set, and remove. Uses SessionStorage by default
51
- */
52
- storage?: AuthClientStorage;
53
- appId?: string;
54
- idpWindowOption?: string;
55
- }
56
- export interface AuthClientLoginOptions extends AuthClientCreateOptions {
57
- /**
58
- * Identity provider. By default, use the identity service.
59
- */
60
- identityProvider?: string | URL;
61
- permissions?: PermissionsType[];
62
- /**
63
- * Experiation of the authentication
64
- */
65
- maxTimeToLive?: bigint;
66
- /**
67
- * Callback once login has completed
68
- */
69
- onSuccess?: () => void | Promise<void>;
70
- /**
71
- * Callback in case authentication fails
72
- */
73
- onError?: (error?: string) => void;
74
- /**
75
- * Callback once is authenticated
76
- */
77
- onAuthenticated?: (ic: IC) => void | Promise<void>;
78
- }
79
- export interface ConnectOptions extends AuthClientLoginOptions {
80
- ledgerCanisterId?: string;
81
- walletProviderUrl?: string;
82
- }
83
- export interface TransactionOptions {
84
- /**
85
- * Identity provider. By default, use the identity service.
86
- */
87
- walletProvider?: string | URL;
88
- from: AccountIdentifier;
89
- to: AccountIdentifier;
90
- amount: bigint;
91
- sendOpts: SendOpts;
92
- /**
93
- * Callback once login has completed
94
- */
95
- onSuccess?: () => void | Promise<void>;
96
- /**
97
- * Callback in case authentication fails
98
- */
99
- onError?: (error?: string) => void;
100
- }
101
- /**
102
- * Interface for persisting user authentication data
103
- */
104
- export interface AuthClientStorage {
105
- get(key: string): Promise<string | null>;
106
- set(key: string, value: string): Promise<void>;
107
- remove(key: string): Promise<void>;
108
- }
109
- export interface InternetIdentityAuthRequest {
110
- kind: 'authorize-client';
111
- sessionPublicKey: Uint8Array;
112
- permissions?: PermissionsType[];
113
- maxTimeToLive?: bigint;
114
- appId?: string;
115
- }
116
- export interface DelegationResult {
117
- delegations: {
118
- delegation: {
119
- pubkey: Uint8Array;
120
- expiration: bigint;
121
- targets?: Principal[];
122
- };
123
- signature: Uint8Array;
124
- }[];
125
- userPublicKey: Uint8Array;
126
- }
127
- export interface MeAuthResponseSuccess {
128
- kind: 'authorize-client-success';
129
- identity: DelegationResult;
130
- wallet?: string;
131
- }
132
- export interface IIAuthResponseSuccess extends DelegationResult {
133
- kind: 'authorize-client-success';
134
- }
135
- export declare type AuthResponseSuccess = MeAuthResponseSuccess | IIAuthResponseSuccess;
136
- export declare type EventHandler = (event: MessageEvent) => Promise<void>;
137
- export declare enum PermissionsType {
138
- identity = "permissions-identity",
139
- wallet = "permissions-wallet"
140
- }
141
- export declare enum TransactionMessageKind {
142
- client = "transaction-client",
143
- ready = "transaction-ready",
144
- success = "transaction-client-success",
145
- fail = "transaction-client-failure"
146
- }
147
- export interface TransactionReadyMessage {
148
- kind: TransactionMessageKind.ready;
149
- }
150
- export interface TransactionResponseFailure {
151
- kind: TransactionMessageKind.fail;
152
- text: string;
153
- }
154
- export interface TransactionResponseSuccess {
155
- kind: TransactionMessageKind.success;
156
- payload?: {
157
- blockHeight: bigint;
158
- originPayload: {
159
- to: AccountIdentifier;
160
- amount: bigint;
161
- sendOpts?: Partial<SendOpts>;
162
- };
163
- };
164
- }
165
- export declare type TransactionResponseMessage = TransactionReadyMessage | TransactionResponse;
166
- export declare type TransactionResponse = TransactionResponseSuccess | TransactionResponseFailure;
167
- export interface AuthReadyMessage {
168
- kind: 'authorize-ready';
169
- }
170
- export interface AuthResponseFailure {
171
- kind: 'authorize-client-failure';
172
- text: string;
173
- }
174
- export declare type IdentityServiceResponseMessage = AuthReadyMessage | AuthResponse;
175
- export declare type AuthResponse = AuthResponseSuccess | AuthResponseFailure;
@@ -1,14 +0,0 @@
1
- export var PermissionsType;
2
- (function (PermissionsType) {
3
- PermissionsType["identity"] = "permissions-identity";
4
- PermissionsType["wallet"] = "permissions-wallet";
5
- })(PermissionsType || (PermissionsType = {}));
6
- // Transaction Types
7
- export var TransactionMessageKind;
8
- (function (TransactionMessageKind) {
9
- TransactionMessageKind["client"] = "transaction-client";
10
- TransactionMessageKind["ready"] = "transaction-ready";
11
- TransactionMessageKind["success"] = "transaction-client-success";
12
- TransactionMessageKind["fail"] = "transaction-client-failure";
13
- })(TransactionMessageKind || (TransactionMessageKind = {}));
14
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAgKA,MAAM,CAAN,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,oDAAiC,CAAA;IACjC,gDAA6B,CAAA;AAC/B,CAAC,EAHW,eAAe,KAAf,eAAe,QAG1B;AAED,oBAAoB;AACpB,MAAM,CAAN,IAAY,sBAKX;AALD,WAAY,sBAAsB;IAChC,uDAA6B,CAAA;IAC7B,qDAA2B,CAAA;IAC3B,gEAAsC,CAAA;IACtC,6DAAmC,CAAA;AACrC,CAAC,EALW,sBAAsB,KAAtB,sBAAsB,QAKjC"}
@@ -1,15 +0,0 @@
1
- export declare type CanisterIdString = string;
2
- export declare type NeuronId = bigint;
3
- export declare type AccountIdentifier = string;
4
- export declare type BlockHeight = bigint;
5
- export declare type E8s = bigint;
6
- export declare type Memo = bigint;
7
- export declare type PrincipalString = string;
8
- export declare type SubAccount = Uint8Array;
9
- export declare enum WalletType {
10
- nns = "nns",
11
- plug = "plug",
12
- stoic = "stoic",
13
- me = "me",
14
- unknown = "unknown"
15
- }
@@ -1,9 +0,0 @@
1
- export var WalletType;
2
- (function (WalletType) {
3
- WalletType["nns"] = "nns";
4
- WalletType["plug"] = "plug";
5
- WalletType["stoic"] = "stoic";
6
- WalletType["me"] = "me";
7
- WalletType["unknown"] = "unknown";
8
- })(WalletType || (WalletType = {}));
9
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/utils/common/types.ts"],"names":[],"mappings":"AAQA,MAAM,CAAN,IAAY,UAMX;AAND,WAAY,UAAU;IACpB,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,6BAAe,CAAA;IACf,uBAAS,CAAA;IACT,iCAAmB,CAAA;AACrB,CAAC,EANW,UAAU,KAAV,UAAU,QAMrB"}
@@ -1,6 +0,0 @@
1
- export declare const SUB_ACCOUNT_BYTE_LENGTH = 32;
2
- export declare const CREATE_CANISTER_MEMO: bigint;
3
- export declare const TOP_UP_CANISTER_MEMO: bigint;
4
- export declare const TRANSACTION_FEE: bigint;
5
- export declare const LEDGER_CANISTER_ID = "ryjl3-tyaaa-aaaaa-aaaba-cai";
6
- export declare const NNS_CANISTER_ID = "qoctq-giaaa-aaaaa-aaaea-cai";
@@ -1,10 +0,0 @@
1
- export const SUB_ACCOUNT_BYTE_LENGTH = 32;
2
- export const CREATE_CANISTER_MEMO = BigInt(0x41455243); // CREA,
3
- export const TOP_UP_CANISTER_MEMO = BigInt(0x50555054); // TPUP
4
- export const TRANSACTION_FEE = BigInt(10000);
5
- export const LEDGER_CANISTER_ID = 'ryjl3-tyaaa-aaaaa-aaaba-cai';
6
- export const NNS_CANISTER_ID = 'qoctq-giaaa-aaaaa-aaaea-cai';
7
- // import config from "../config";
8
- // // @ts-ignore
9
- // export const HOST = "HOST" in config ? config["HOST"] : undefined;
10
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAC1C,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ;AAChE,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO;AAE/D,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,KAAM,CAAC,CAAC;AAE9C,MAAM,CAAC,MAAM,kBAAkB,GAAG,6BAA6B,CAAC;AAChE,MAAM,CAAC,MAAM,eAAe,GAAG,6BAA6B,CAAC;AAE7D,kCAAkC;AAElC,gBAAgB;AAChB,qEAAqE"}
@@ -1,32 +0,0 @@
1
- import { Principal } from '@dfinity/principal';
2
- import { AccountIdentifier, SubAccount } from './common/types';
3
- export declare const uint8ArrayToBigInt: (array: Uint8Array) => bigint;
4
- export declare const bigIntToUint8Array: (value: bigint) => Uint8Array;
5
- export declare const arrayBufferToArrayOfNumber: (buffer: ArrayBuffer) => Array<number>;
6
- export declare const arrayOfNumberToUint8Array: (numbers: Array<number>) => Uint8Array;
7
- export declare const arrayOfNumberToArrayBuffer: (numbers: Array<number>) => ArrayBuffer;
8
- export declare const arrayBufferToNumber: (buffer: ArrayBuffer) => number;
9
- export declare const numberToArrayBuffer: (value: number, byteLength: number) => ArrayBuffer;
10
- export declare const asciiStringToByteArray: (text: string) => Array<number>;
11
- export declare const toSubAccountId: (subAccount: Array<number>) => number;
12
- export declare const fromSubAccountId: (subAccountId: number) => Array<number>;
13
- export declare const accountIdentifierToBytes: (accountIdentifier: AccountIdentifier) => Uint8Array;
14
- export declare const accountIdentifierFromBytes: (accountIdentifier: Uint8Array) => AccountIdentifier;
15
- export declare const principalToAccountIdentifier: (principal: Principal, subAccount?: Uint8Array | undefined) => string;
16
- export declare const principalToSubAccount: (principal: Principal) => SubAccount;
17
- export declare const stringToAccountIdentifier: (str: string) => AccountIdentifier | undefined;
18
- export declare const calculateCrc32: (bytes: Uint8Array) => Uint8Array;
19
- export declare const E8S_PER_ICP = 100000000;
20
- export declare enum TokenSymbol {
21
- ICP = "ICP"
22
- }
23
- export interface TokenMapItem {
24
- [key: string]: {
25
- amount: number;
26
- symbol: string;
27
- };
28
- }
29
- export declare const formatAssetBySymbol: (_amount: bigint, symbol: string) => {
30
- amount: number;
31
- symbol: string;
32
- } | undefined;
@@ -1,124 +0,0 @@
1
- import { Principal } from '@dfinity/principal';
2
- import { sha224 } from 'js-sha256';
3
- import { Buffer } from 'buffer';
4
- import crc from 'crc';
5
- import { SUB_ACCOUNT_BYTE_LENGTH } from './constants';
6
- export const uint8ArrayToBigInt = (array) => {
7
- const view = new DataView(array.buffer, array.byteOffset, array.byteLength);
8
- if (typeof view.getBigUint64 === 'function') {
9
- return view.getBigUint64(0);
10
- }
11
- else {
12
- const high = BigInt(view.getUint32(0));
13
- const low = BigInt(view.getUint32(4));
14
- return (high << BigInt(32)) + low;
15
- }
16
- };
17
- const TWO_TO_THE_32 = BigInt(1) << BigInt(32);
18
- export const bigIntToUint8Array = (value) => {
19
- const array = new Uint8Array(8);
20
- const view = new DataView(array.buffer, array.byteOffset, array.byteLength);
21
- if (typeof view.setBigUint64 === 'function') {
22
- view.setBigUint64(0, value);
23
- }
24
- else {
25
- view.setUint32(0, Number(value >> BigInt(32)));
26
- view.setUint32(4, Number(value % TWO_TO_THE_32));
27
- }
28
- return array;
29
- };
30
- export const arrayBufferToArrayOfNumber = (buffer) => {
31
- const typedArray = new Uint8Array(buffer);
32
- return Array.from(typedArray);
33
- };
34
- export const arrayOfNumberToUint8Array = (numbers) => {
35
- return new Uint8Array(numbers);
36
- };
37
- export const arrayOfNumberToArrayBuffer = (numbers) => {
38
- return arrayOfNumberToUint8Array(numbers).buffer;
39
- };
40
- export const arrayBufferToNumber = (buffer) => {
41
- const view = new DataView(buffer);
42
- return view.getUint32(view.byteLength - 4);
43
- };
44
- export const numberToArrayBuffer = (value, byteLength) => {
45
- const buffer = new ArrayBuffer(byteLength);
46
- new DataView(buffer).setUint32(byteLength - 4, value);
47
- return buffer;
48
- };
49
- export const asciiStringToByteArray = (text) => {
50
- return Array.from(text).map(c => c.charCodeAt(0));
51
- };
52
- export const toSubAccountId = (subAccount) => {
53
- const bytes = arrayOfNumberToArrayBuffer(subAccount);
54
- return arrayBufferToNumber(bytes);
55
- };
56
- export const fromSubAccountId = (subAccountId) => {
57
- const buffer = numberToArrayBuffer(subAccountId, SUB_ACCOUNT_BYTE_LENGTH);
58
- return arrayBufferToArrayOfNumber(buffer);
59
- };
60
- export const accountIdentifierToBytes = (accountIdentifier) => {
61
- return Uint8Array.from(Buffer.from(accountIdentifier, 'hex')).subarray(4);
62
- };
63
- export const accountIdentifierFromBytes = (accountIdentifier) => {
64
- return Buffer.from(accountIdentifier).toString('hex');
65
- };
66
- export const principalToAccountIdentifier = (principal, subAccount) => {
67
- // Hash (sha224) the principal, the subAccount and some padding
68
- const padding = asciiStringToByteArray('\x0Aaccount-id');
69
- const shaObj = sha224.create();
70
- shaObj.update([...padding, ...principal.toUint8Array(), ...(subAccount !== null && subAccount !== void 0 ? subAccount : Array(32).fill(0))]);
71
- const hash = new Uint8Array(shaObj.array());
72
- // Prepend the checksum of the hash and convert to a hex string
73
- const checksum = calculateCrc32(hash);
74
- const bytes = new Uint8Array([...checksum, ...hash]);
75
- return toHexString(bytes);
76
- };
77
- export const principalToSubAccount = (principal) => {
78
- const bytes = principal.toUint8Array();
79
- const subAccount = new Uint8Array(32);
80
- subAccount[0] = bytes.length;
81
- subAccount.set(bytes, 1);
82
- return subAccount;
83
- };
84
- export const stringToAccountIdentifier = (str) => {
85
- try {
86
- if (str.length === 64) {
87
- return str;
88
- }
89
- if (str.length === 63) {
90
- return principalToAccountIdentifier(Principal.fromText(str));
91
- }
92
- return undefined;
93
- }
94
- catch (error) {
95
- return undefined;
96
- }
97
- };
98
- const toHexString = (bytes) => bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');
99
- // 4 bytes
100
- export const calculateCrc32 = (bytes) => {
101
- const checksumArrayBuf = new ArrayBuffer(4);
102
- const view = new DataView(checksumArrayBuf);
103
- view.setUint32(0, crc.crc32(Buffer.from(bytes)), false);
104
- return Buffer.from(checksumArrayBuf);
105
- };
106
- export const E8S_PER_ICP = 100000000;
107
- export var TokenSymbol;
108
- (function (TokenSymbol) {
109
- TokenSymbol["ICP"] = "ICP";
110
- })(TokenSymbol || (TokenSymbol = {}));
111
- export const formatAssetBySymbol = (_amount, symbol) => {
112
- const amount = parseInt(_amount === null || _amount === void 0 ? void 0 : _amount.toString(), 10);
113
- const tokenMap = [
114
- {
115
- ICP: {
116
- amount: amount / E8S_PER_ICP,
117
- symbol: 'ICP',
118
- },
119
- },
120
- ];
121
- const found = tokenMap.find(v => v[symbol] !== undefined);
122
- return found === null || found === void 0 ? void 0 : found[symbol];
123
- };
124
- //# sourceMappingURL=converter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"converter.js","sourceRoot":"","sources":["../../../src/utils/converter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAGtD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAiB,EAAU,EAAE;IAC9D,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IAC5E,IAAI,OAAO,IAAI,CAAC,YAAY,KAAK,UAAU,EAAE;QAC3C,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;KAC7B;SAAM;QACL,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;QACvC,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;QAEtC,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,G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b,CAAC,EAFW,WAAW,KAAX,WAAW,QAEtB;AAMD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,OAAe,EACf,MAAc,EACkC,EAAE;IAClD,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,IAAI,EAAE,CAAC,CAAC;IACjD,MAAM,QAAQ,GAAmB;QAC/B;YACE,GAAG,EAAE;gBACH,MAAM,EAAE,MAAM,GAAG,WAAW;gBAC5B,MAAM,EAAE,KAAK;aACd;SACF;KACF,CAAC;IACF,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC;IAC1D,OAAO,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAG,MAAM,EAAE;AACzB,CAAC,CAAC"}
@@ -1,3 +0,0 @@
1
- export * from './common/types';
2
- export * from './constants';
3
- export * from './converter';
@@ -1,4 +0,0 @@
1
- export * from './common/types';
2
- export * from './constants';
3
- export * from './converter';
4
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}