@msafe/sui3-sdk 0.0.2-pre-9f39791.0 → 0.0.2

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.
@@ -0,0 +1,454 @@
1
+ import * as _mysten_sui_js_src_cryptography from '@mysten/sui.js/src/cryptography';
2
+ import { PublicKey } from '@mysten/sui.js/src/cryptography';
3
+ import { SuiClient, ExecuteTransactionRequestType, SuiTransactionBlockResponseOptions, SuiTransactionBlockResponse, CoinStruct, CoinMetadata, SuiObjectData } from '@mysten/sui.js/client';
4
+ import { SerializedSignature, PublicKey as PublicKey$1, SignatureScheme } from '@mysten/sui.js/cryptography';
5
+ import * as _mysten_sui_js_dist_cjs_builder from '@mysten/sui.js/dist/cjs/builder';
6
+ import { ModelConfig } from '@msafe/sui3-model/common';
7
+ import { SignatureWithBytes } from '@mysten/sui.js/src/cryptography/keypair';
8
+ import { TransactionBlock } from '@mysten/sui.js/transactions';
9
+ import * as _mysten_sui_js_dist_cjs_client from '@mysten/sui.js/dist/cjs/client';
10
+ import { Ed25519PublicKey } from '@mysten/sui.js/keypairs/ed25519';
11
+ import { MultiSigPublicKey } from '@mysten/sui.js/multisig';
12
+
13
+ interface IntentionCoinTransfer {
14
+ txType: 'CoinTransfer';
15
+ recipient: string;
16
+ coinType: string;
17
+ amount: string;
18
+ }
19
+
20
+ interface IntentionObjectTransfer {
21
+ txType: 'ObjectTransfer';
22
+ receiver: string;
23
+ objectId: string;
24
+ objectType: string;
25
+ }
26
+
27
+ type TxIntention = IntentionObjectTransfer | IntentionCoinTransfer;
28
+ declare class IntentionHelper {
29
+ static ser(intention: TxIntention): string;
30
+ static de(val: string): TxIntention;
31
+ static buildTxb(input: {
32
+ suiClient: SuiClient;
33
+ intention: TxIntention;
34
+ sender: string;
35
+ }): Promise<_mysten_sui_js_dist_cjs_builder.TransactionBlock>;
36
+ static getTxType(intention: TxIntention): {
37
+ txType: string;
38
+ txSubType: string;
39
+ };
40
+ static buildRejectTransaction(input: {
41
+ msafeAddress: string;
42
+ payloadToReject: string;
43
+ }): Promise<_mysten_sui_js_dist_cjs_builder.TransactionBlock>;
44
+ }
45
+
46
+ interface MSafeAccountInfo {
47
+ address: string;
48
+ ownersWithWeightPK: OwnerWithWeightPK[];
49
+ threshold: number;
50
+ name: string;
51
+ description?: string;
52
+ creationNonce: number;
53
+ }
54
+ type OwnerWithWeightPK = OwnerWithWeight & {
55
+ publicKey: PublicKey;
56
+ };
57
+ interface OwnerWithWeight {
58
+ address: string;
59
+ weight: number;
60
+ }
61
+ interface PendingTx {
62
+ digest: string;
63
+ payload: string;
64
+ msafeAddress: string;
65
+ isRejectTx: boolean;
66
+ intention?: TxIntention;
67
+ creator: string;
68
+ createdAt: Date;
69
+ sequenceNumber: number;
70
+ votes: PendingVote[];
71
+ }
72
+ interface PendingVote {
73
+ userAddress: string;
74
+ signature: string;
75
+ timestamp: Date;
76
+ }
77
+ interface HistorySendTx {
78
+ digest: string;
79
+ payload: string;
80
+ msafeAddress: string;
81
+ sequenceNumber: number;
82
+ isRejectTx: boolean;
83
+ status: string;
84
+ creator: string;
85
+ createdAt: Date;
86
+ votes: HistoryVote[];
87
+ }
88
+ interface ReceiveTransaction {
89
+ digest: string;
90
+ payload: string;
91
+ txType: string;
92
+ txSubType: string;
93
+ timestamp: Date;
94
+ }
95
+ interface HistoryVote {
96
+ userAddress: string;
97
+ timestamp: Date;
98
+ }
99
+ interface FutureIntention {
100
+ intention: TxIntention;
101
+ sequenceNumber: number;
102
+ msafeAddress: string;
103
+ creator: string;
104
+ txType: string;
105
+ txSubType: string;
106
+ rawData: string;
107
+ status: string;
108
+ statusRemark?: string;
109
+ createdAt: Date;
110
+ }
111
+
112
+ type JWTToken = string;
113
+ interface CreateMSafeParams {
114
+ ownerWithWeight: OwnerWithWeightPK[];
115
+ threshold: number;
116
+ name: string;
117
+ description?: string;
118
+ creationNonce: number;
119
+ signature: SerializedSignature;
120
+ }
121
+ interface UserWithOwnedMSafe {
122
+ address: string;
123
+ publicKey: string;
124
+ schema: string;
125
+ creationNonce: number;
126
+ ownedMSafe: MSafeAccountInfo[];
127
+ }
128
+
129
+ interface IBackend {
130
+ isJWTTokenValid(jwt: JWTToken): Promise<boolean>;
131
+ authSign(input: {
132
+ address: string;
133
+ message: string;
134
+ signature: SerializedSignature;
135
+ walletType: string;
136
+ }): Promise<JWTToken>;
137
+ setJWTToken(token: JWTToken): void;
138
+ getPublicKey(address: string): Promise<PublicKey$1 | undefined>;
139
+ getPublicKeyBatch(addresses: string[]): Promise<(PublicKey$1 | undefined)[]>;
140
+ getMSafeAccountInfo(msafeAddress: string): Promise<MSafeAccountInfo>;
141
+ getUserInfo(userAddress: string): Promise<UserWithOwnedMSafe>;
142
+ getPendingTransactions(msafeAddress: string): Promise<PendingTx[]>;
143
+ getHistoryTransactions(msafeAddress: string): Promise<HistorySendTx[]>;
144
+ getFutureIntentions(msafeAddress: string): Promise<FutureIntention[]>;
145
+ getCurrentSequenceNumber(msafeAddress: string): Promise<number>;
146
+ getNextSequenceNumber(msafeAddress: string): Promise<number>;
147
+ createMSafeAccount(input: CreateMSafeParams): Promise<void>;
148
+ proposeIntention(input: {
149
+ intention: TxIntention;
150
+ sequenceNumber: number;
151
+ userAddress: string;
152
+ msafeAddress: string;
153
+ signature: SerializedSignature;
154
+ }): Promise<void>;
155
+ proposePendingTransaction(input: {
156
+ intention: TxIntention;
157
+ userAddress: string;
158
+ msafeAddress: string;
159
+ digest: string;
160
+ signature: SerializedSignature;
161
+ }): Promise<void>;
162
+ rejectCurrentTx(input: {
163
+ userAddress: string;
164
+ msafeAddress: string;
165
+ digest: string;
166
+ signature: SerializedSignature;
167
+ }): Promise<void>;
168
+ voteForTransaction(input: {
169
+ txDigest: string;
170
+ msafeAddress: string;
171
+ userAddress: string;
172
+ signature: SerializedSignature;
173
+ }): Promise<void>;
174
+ buildNextIntentionAndAddToPending(input: {
175
+ msafeAddress: string;
176
+ }): Promise<void>;
177
+ skipNextFailedIntention(input: {
178
+ msafeAddress: string;
179
+ userAddress: string;
180
+ }): Promise<void>;
181
+ processExecutedTransaction(digest: string): Promise<void>;
182
+ }
183
+
184
+ declare enum MSafeEnv {
185
+ local = "local",
186
+ unit = "unit",
187
+ dev = "dev",
188
+ prev = "prev",
189
+ prod = "prod"
190
+ }
191
+ interface MSafeConfig {
192
+ suiClient: {
193
+ url: string;
194
+ };
195
+ backend: DBConfig;
196
+ }
197
+ interface MSafeConfigOptions {
198
+ suiClient?: {
199
+ url?: string;
200
+ };
201
+ backend?: DBConfig;
202
+ }
203
+ type DBConfig = ModelConfig;
204
+ declare const LOCAL_DATABASE_CONFIG: DBConfig;
205
+ declare const DEV_DATABASE_CONFIG: DBConfig;
206
+ declare const TESTNET_RPC_URL = "https://sui-testnet.blockvision.org/v1/2Sgk89ivT64MnKdcGzjmyjY2ndD";
207
+ declare const MAINNET_RPC_URL = "https://sui-mainnet.blockvision.org/v1/2Sgk7NPvqkd7mESYkxF01yX15l7";
208
+ declare const ENV_CONFIGS: Map<MSafeEnv, MSafeConfig>;
209
+ declare function getMSafeConfig(env: MSafeEnv, options?: MSafeConfigOptions): MSafeConfig;
210
+ declare const AUTH_SIGN_MESSAGE = "Welcome to MSafe";
211
+
212
+ interface IWallet {
213
+ walletType: string;
214
+ address(): Promise<string>;
215
+ signPersonalMessage(input: {
216
+ messageStr: string;
217
+ }): Promise<SignatureWithBytes>;
218
+ signTransactionBlock(input: {
219
+ transactionBlock: TransactionBlock | Uint8Array;
220
+ }): Promise<SignatureWithBytes>;
221
+ signAndExecuteTransactionBlock(input: {
222
+ transactionBlock: TransactionBlock;
223
+ requestType?: ExecuteTransactionRequestType;
224
+ options?: SuiTransactionBlockResponseOptions;
225
+ }): Promise<SuiTransactionBlockResponse>;
226
+ }
227
+
228
+ declare class MSafeGlobals {
229
+ readonly backend: IBackend;
230
+ readonly suiClient: SuiClient;
231
+ readonly config: MSafeConfig;
232
+ _wallet: IWallet | undefined;
233
+ constructor(input: {
234
+ backend: IBackend;
235
+ suiClient: SuiClient;
236
+ config: MSafeConfig;
237
+ });
238
+ static New(env: MSafeEnv, options?: MSafeConfigOptions): Promise<MSafeGlobals>;
239
+ connectWallet(wallet: IWallet): void;
240
+ get wallet(): IWallet;
241
+ set wallet(val: IWallet);
242
+ }
243
+
244
+ /**
245
+ * PublicKeyHelper is the helper to query for public keys from
246
+ * backend and blockchain.
247
+ */
248
+ declare class PublicKeyHelper {
249
+ readonly globals: MSafeGlobals;
250
+ private knownPublicKeys;
251
+ constructor(globals: MSafeGlobals);
252
+ getPublicKey(address: string): Promise<PublicKey | undefined>;
253
+ getPublicKeyBatch(addresses: string[]): Promise<(PublicKey | undefined)[]>;
254
+ private _getPublicKey;
255
+ private getPublicKeyFromBackend;
256
+ private getPublicKeyFromChain;
257
+ }
258
+
259
+ interface CreateMSafeAccountInfo {
260
+ ownerWithWeight: {
261
+ address: string;
262
+ weight: number;
263
+ }[];
264
+ threshold: number;
265
+ name: string;
266
+ description?: string;
267
+ creationNonce: number;
268
+ }
269
+ interface CreatePermissionInfo {
270
+ ownerWithWeight: {
271
+ address: string;
272
+ weight: number;
273
+ }[];
274
+ threshold: number;
275
+ creationNonce: number;
276
+ }
277
+
278
+ declare class CreateHelper {
279
+ readonly globals: MSafeGlobals;
280
+ readonly pkHelper: PublicKeyHelper;
281
+ constructor(globals: MSafeGlobals, pkHelper: PublicKeyHelper);
282
+ getPublicKeyBatch(addresses: string[]): Promise<(_mysten_sui_js_src_cryptography.PublicKey | undefined)[]>;
283
+ calculateMSafeAddress(info: CreatePermissionInfo): Promise<string>;
284
+ validateCreateInfo(createInfo: CreateMSafeAccountInfo): Promise<string>;
285
+ submitMSafeCreation(creationInfo: CreateMSafeAccountInfo): Promise<string>;
286
+ private reduceCreationInfoToRawConfig;
287
+ private submitToBackend;
288
+ }
289
+
290
+ declare class MessageHelper {
291
+ static createMSafeMessage(msafeAddress: string): string;
292
+ static deCreateMSafeMessage(msg: string): string | undefined;
293
+ static welcomeMessage(timestamp: string): string;
294
+ static deWelcomeMessage(msg: string): string | undefined;
295
+ static proposeIntentionMessage(data: ProposeIntentionData): string;
296
+ static deProposeIntentionMessage(s: string): ProposeIntentionData;
297
+ }
298
+ interface ProposeIntentionData {
299
+ intention: TxIntention;
300
+ sn: number;
301
+ }
302
+
303
+ interface PublicKeyWithWeight {
304
+ publicKey: PublicKey$1;
305
+ weight: number;
306
+ }
307
+ interface MultiSigConfig {
308
+ threshold: number;
309
+ ownerWithWeight: PublicKeyWithWeight[];
310
+ creationNonce: number | undefined;
311
+ }
312
+ declare const NONCE_PK_PREFIX = "maven";
313
+ declare const NONCE_PREFIX_MAX_SIZE = 16;
314
+ declare const NONCE_PK_WEIGHT = 1;
315
+ declare const MAX_WEIGHT = 255;
316
+ declare const MIN_WEIGHT = 1;
317
+ declare const MAX_OWNER_WITH_NONCE = 9;
318
+ declare const MAX_OWNER_WITHOUT_NONCE = 10;
319
+ declare const MIN_THRESHOLD = 1;
320
+ declare class RawMultiSig {
321
+ readonly config: MultiSigConfig;
322
+ rawMsPK: MultiSigPublicKey;
323
+ constructor(config: MultiSigConfig);
324
+ static fromMSafeAccountInfo(info: MSafeAccountInfo): RawMultiSig;
325
+ get suiAddress(): string;
326
+ get publicKeys(): PublicKeyWithWeight[];
327
+ get threshold(): number;
328
+ combinePartialSignatures(signatures: SerializedSignature[]): SerializedSignature;
329
+ verifyPersonalMessage(messageStr: string, multiSigSignature: SerializedSignature): Promise<boolean>;
330
+ }
331
+ declare function getMultiSigPublicKey(config: MultiSigConfig): MultiSigPublicKey;
332
+ declare function makeNoncePublicKey(nonce: number): Ed25519PublicKey;
333
+ declare function validateMultiSigConfig(config: MultiSigConfig): void;
334
+
335
+ declare class MSafeAccount {
336
+ readonly globals: MSafeGlobals;
337
+ readonly info: MSafeAccountInfo;
338
+ rawMultiSig: RawMultiSig;
339
+ constructor(globals: MSafeGlobals, info: MSafeAccountInfo);
340
+ static new(globals: MSafeGlobals, address: string): Promise<MSafeAccount>;
341
+ pendingTransactions(): Promise<PendingTx[]>;
342
+ historyTransaction(): Promise<HistorySendTx[]>;
343
+ futureIntentions(): Promise<FutureIntention[]>;
344
+ currentSequenceNumber(): Promise<number>;
345
+ nextSequenceNumber(): Promise<number>;
346
+ proposeIntention(intention: TxIntention, sequenceNumber: number): Promise<void>;
347
+ voteForTransaction(digest: string, payload: string): Promise<void>;
348
+ proposePendingTransaction(intention: TxIntention): Promise<void>;
349
+ rejectCurrentTx(pending?: PendingTx): Promise<void>;
350
+ buildNextIntentionAndAddToPending(): Promise<void>;
351
+ skipNextFailedIntention(): Promise<void>;
352
+ executePendingTx(pending: PendingTx): Promise<_mysten_sui_js_dist_cjs_client.SuiTransactionBlockResponse>;
353
+ get address(): string;
354
+ private get backend();
355
+ private get wallet();
356
+ private userAddress;
357
+ private get suiClient();
358
+ }
359
+
360
+ declare class MSafeClient {
361
+ readonly globals: MSafeGlobals;
362
+ private _creationHelper;
363
+ private _publicKeyHelper;
364
+ constructor(globals: MSafeGlobals);
365
+ static New(env: MSafeEnv, options?: MSafeConfigOptions): Promise<MSafeClient>;
366
+ connectWallet(input: {
367
+ wallet: IWallet;
368
+ jwtToken?: JWTToken;
369
+ }): Promise<JWTToken>;
370
+ userInfo(): Promise<UserWithOwnedMSafe>;
371
+ createAccount(info: CreateMSafeAccountInfo): Promise<string>;
372
+ getMSafeAccount(info: MSafeAccountInfo): MSafeAccount;
373
+ getMSafeAccountFromAddress(msafeAddress: string): Promise<MSafeAccount>;
374
+ get creationHelper(): CreateHelper;
375
+ get publicKeyHelper(): PublicKeyHelper;
376
+ get config(): MSafeConfig;
377
+ get backend(): IBackend;
378
+ get wallet(): IWallet;
379
+ private walletAddress;
380
+ }
381
+
382
+ declare function stringToBuffer(s: string): Buffer;
383
+ declare function Uint8ArrayToHex(b: Uint8Array): string;
384
+ declare function HexToUint8Array(hex: string): Uint8Array;
385
+
386
+ declare class SignatureVerifier {
387
+ static getPublicKeyFromSignature(input: {
388
+ message: Uint8Array;
389
+ messageType: 'TransactionBlock' | 'Personal';
390
+ signature: SerializedSignature;
391
+ }): Promise<PublicKey$1>;
392
+ static getPublicKeyFromPersonalSignature(input: {
393
+ messageStr: string;
394
+ signature: SerializedSignature;
395
+ }): Promise<PublicKey$1>;
396
+ static verifySignature(input: {
397
+ message: Uint8Array;
398
+ messageType: 'TransactionBlock' | 'Personal';
399
+ signature: SerializedSignature;
400
+ targetAddress: string;
401
+ }): Promise<boolean>;
402
+ static verifyPersonalSignature(input: {
403
+ messageStr: string;
404
+ signature: SerializedSignature;
405
+ targetAddress: string;
406
+ }): Promise<boolean>;
407
+ static verifyTransactionSignature(input: {
408
+ payload: Uint8Array;
409
+ signature: SerializedSignature;
410
+ targetAddress: string;
411
+ }): Promise<boolean>;
412
+ }
413
+ declare class PublicKeySerde {
414
+ static ser(publicKey: PublicKey$1): {
415
+ publicKey: string;
416
+ scheme: "ED25519" | "Secp256r1" | "Secp256k1" | "MultiSig" | "ZkLogin";
417
+ };
418
+ static de(input: {
419
+ publicKey: string | Uint8Array;
420
+ scheme: SignatureScheme;
421
+ }): PublicKey$1;
422
+ }
423
+
424
+ declare class Formatter {
425
+ static normalizeSuiAddress(addr: string): string;
426
+ static normalizeStructTag(struct: string): string;
427
+ static isSuiAddressEqual(addr1: string, addr2: string): boolean;
428
+ static isSuiStructEqual(struct1: string, struct2: string): boolean;
429
+ static isCoinObjectType(struct: string): boolean;
430
+ }
431
+
432
+ declare const SUI_COIN = "0x2::sui::SUI";
433
+ declare function getPublicKeyFromChain(suiClient: SuiClient, address: string): Promise<PublicKey$1 | undefined>;
434
+ declare function getAllCoins(input: {
435
+ suiClient: SuiClient;
436
+ owner: string;
437
+ coinType: string | undefined;
438
+ }): Promise<CoinStruct[]>;
439
+
440
+ declare class CoinHelper {
441
+ private _client;
442
+ private _coinMetaReg;
443
+ constructor(client: SuiClient);
444
+ getCoinMeta(coinType: string): Promise<CoinMetadata | undefined>;
445
+ private queryCoinMeta;
446
+ }
447
+ declare const COIN_TYPE_ARG_REGEX: RegExp;
448
+ declare class Coin {
449
+ static isCoin(type: string | undefined | null): boolean;
450
+ static getCoinType(type: string): string | null;
451
+ static getBalance(data: SuiObjectData): bigint | undefined;
452
+ }
453
+
454
+ export { AUTH_SIGN_MESSAGE, COIN_TYPE_ARG_REGEX, Coin, CoinHelper, CreateHelper, type CreateMSafeAccountInfo, type CreatePermissionInfo, type DBConfig, DEV_DATABASE_CONFIG, ENV_CONFIGS, Formatter, type FutureIntention, HexToUint8Array, type HistorySendTx, type HistoryVote, type IWallet, IntentionHelper, LOCAL_DATABASE_CONFIG, MAINNET_RPC_URL, MAX_OWNER_WITHOUT_NONCE, MAX_OWNER_WITH_NONCE, MAX_WEIGHT, MIN_THRESHOLD, MIN_WEIGHT, MSafeAccount, type MSafeAccountInfo, MSafeClient, type MSafeConfig, type MSafeConfigOptions, MSafeEnv, MSafeGlobals, MessageHelper, type MultiSigConfig, NONCE_PK_PREFIX, NONCE_PK_WEIGHT, NONCE_PREFIX_MAX_SIZE, type OwnerWithWeight, type OwnerWithWeightPK, type PendingTx, type PendingVote, PublicKeySerde, type PublicKeyWithWeight, RawMultiSig, type ReceiveTransaction, SUI_COIN, SignatureVerifier, TESTNET_RPC_URL, type TxIntention, Uint8ArrayToHex, getAllCoins, getMSafeConfig, getMultiSigPublicKey, getPublicKeyFromChain, makeNoncePublicKey, stringToBuffer, validateMultiSigConfig };