@msafe/sui3-sdk 0.0.6-pre-fdcc3ff.0 → 0.0.6

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.
@@ -15,6 +15,7 @@ import {
15
15
  MultisigAccountManager,
16
16
  OwnerWithWeightPK,
17
17
  UserWithOwnedMSafe,
18
+ HistoryTransaction as HistoryTx,
18
19
  } from '@msafe/sui3-utils';
19
20
  import { SuiClient } from '@mysten/sui.js/client';
20
21
  import { PublicKey, SerializedSignature } from '@mysten/sui.js/cryptography';
@@ -23,11 +24,11 @@ import { MoreThanOrEqual } from 'typeorm';
23
24
 
24
25
  import { CoreDB } from '@/backend/CoreDatabase';
25
26
  import { IBackend } from '@/backend/interface';
26
- import { JWTToken } from '@/backend/types';
27
+ import { JWTToken, PaginationOption, PaginationResponse } from '@/backend/types';
27
28
  import { MessageHelper } from '@/core/MessageHelper';
28
29
  import { DBConfig } from '@/globals/const';
29
30
  import { IntentionHelper, TxIntention } from '@/transactions/intention';
30
- import { FutureIntention, HistorySendTx, PendingTx } from '@/types/msafe';
31
+ import { FutureIntention, PendingTx } from '@/types/msafe';
31
32
  import { Uint8ArrayToHex, HexToUint8Array } from '@/utils/buffer';
32
33
  import { PublicKeySerde, SignatureVerifier } from '@/utils/crypto';
33
34
  import { Formatter } from '@/utils/format';
@@ -177,24 +178,28 @@ export class PseudoBackend implements IBackend {
177
178
  throw new Error('MSafe already exist in database');
178
179
  }
179
180
  input.ownersWithWeightPKEncoded.forEach((ownerInfo) => {
180
- if (!Formatter.isSuiAddressEqual(ownerInfo.address, ownerInfo.publicKey.toSuiAddress())) {
181
+ if (
182
+ !Formatter.isSuiAddressEqual(
183
+ ownerInfo.address,
184
+ PublicKeySerde.de({ publicKey: ownerInfo.publicKeyEncoded, scheme: ownerInfo.schema }).toSuiAddress(),
185
+ )
186
+ ) {
181
187
  throw new Error('Sui address public key not match');
182
188
  }
183
189
  });
184
190
 
185
191
  // For each manager, add user info if not exist. Add userMSafe entry.
186
- for (let i = 0; i !== input.ownerWithWeight.length; i++) {
187
- const ownerInfo = input.ownerWithWeight[i];
192
+ for (let i = 0; i !== input.ownersWithWeightPKEncoded.length; i++) {
193
+ const ownerInfo = input.ownersWithWeightPKEncoded[i];
188
194
  // Creator has been verified and already exist in database
189
195
  if (i !== 0) {
190
196
  const coManager = await this.getUser(ownerInfo.address);
191
- const serPK = PublicKeySerde.ser(ownerInfo.publicKey);
192
197
  // Add user with public key if not exist
193
198
  if (coManager === null) {
194
199
  const user: User = {
195
200
  address: ownerInfo.address,
196
- publicKey: serPK.publicKey,
197
- schema: serPK.scheme,
201
+ publicKey: ownerInfo.publicKeyEncoded,
202
+ schema: ownerInfo.schema,
198
203
  nonce: 0,
199
204
  lastLogin: new Date(),
200
205
  };
@@ -343,7 +348,10 @@ export class PseudoBackend implements IBackend {
343
348
  return maxSNIntention === null ? 0 : maxSNIntention.sequenceNumber + 1;
344
349
  }
345
350
 
346
- async getHistoryTransactions(msafeAddress: string): Promise<HistorySendTx[]> {
351
+ async getHistoryTransactions(
352
+ msafeAddress: string,
353
+ paginationOption?: PaginationOption,
354
+ ): Promise<PaginationResponse<HistoryTx>> {
347
355
  // TODO: Add pagination options. Filter by sequence number based
348
356
  // on pagination options.
349
357
  // Notice there can be multiple transactions with the same sequence
@@ -363,23 +371,35 @@ export class PseudoBackend implements IBackend {
363
371
  }),
364
372
  ),
365
373
  );
366
- return transactions.map((tx, i) => ({
367
- digest: tx.digest,
368
- payload: tx.payload,
369
- msafeAddress: tx.msafeAddress,
370
- isRejectTx: tx.isRejectTx,
371
- status: tx.status,
372
- creator: tx.creator,
373
- createdAt: tx.createdAt as Date,
374
- sequenceNumber: tx.sequenceNumber,
375
- votes: votes[i].map((vote) => ({
376
- userAddress: vote.userAddress,
377
- timestamp: vote.updatedAt as Date,
374
+ return {
375
+ items: transactions.map((tx, i) => ({
376
+ digest: tx.digest,
377
+ payload: tx.payload,
378
+ msafeAddress: tx.msafeAddress,
379
+ isRejectTx: tx.isRejectTx,
380
+ status: tx.status,
381
+ creator: tx.creator,
382
+ createdAt: tx.createdAt as Date,
383
+ sequenceNumber: tx.sequenceNumber,
384
+ votes: votes[i].map((vote) => ({
385
+ userAddress: vote.userAddress,
386
+ timestamp: vote.updatedAt as Date,
387
+ })),
378
388
  })),
379
- }));
389
+ meta: {
390
+ totalItems: 0,
391
+ itemCount: 0,
392
+ itemsPerPage: 0,
393
+ totalPages: 0,
394
+ currentPage: 0,
395
+ },
396
+ };
380
397
  }
381
398
 
382
- async getFutureIntentions(msafeAddress: string): Promise<FutureIntention[]> {
399
+ async getFutureIntentions(
400
+ msafeAddress: string,
401
+ paginationOption?: PaginationOption,
402
+ ): Promise<PaginationResponse<FutureIntention>> {
383
403
  // TODO: Add pagination options, add user permission validation
384
404
  const currentSequenceNumber = await this.getCurrentSequenceNumber(msafeAddress);
385
405
  const hasPending = (await this.model.pendingTransaction.findOneBy({ msafeAddress })) !== null;
@@ -389,19 +409,28 @@ export class PseudoBackend implements IBackend {
389
409
  where: { msafeAddress, sequenceNumber: MoreThanOrEqual(futureSNStart) },
390
410
  order: { sequenceNumber: 'asc' },
391
411
  });
392
- return futureTxs.map((tx) => ({
393
- intention: IntentionHelper.de(tx.data),
394
- msafeAddress: tx.msafeAddress,
395
- sequenceNumber: tx.sequenceNumber,
396
- rawData: tx.data,
397
- txType: tx.txType,
398
- txSubType: tx.txSubType,
399
- processed: tx.processed,
400
- status: tx.status,
401
- statusRemark: tx.statusRemark,
402
- creator: tx.creator,
403
- createdAt: tx.createdAt as Date,
404
- }));
412
+ return {
413
+ items: futureTxs.map((tx) => ({
414
+ intention: IntentionHelper.de(tx.data),
415
+ msafeAddress: tx.msafeAddress,
416
+ sequenceNumber: tx.sequenceNumber,
417
+ rawData: tx.data,
418
+ txType: tx.txType,
419
+ txSubType: tx.txSubType,
420
+ processed: tx.processed,
421
+ status: tx.status,
422
+ statusRemark: tx.statusRemark,
423
+ creator: tx.creator,
424
+ createdAt: tx.createdAt as Date,
425
+ })),
426
+ meta: {
427
+ totalItems: 0,
428
+ itemCount: 0,
429
+ itemsPerPage: 0,
430
+ totalPages: 0,
431
+ currentPage: 0,
432
+ },
433
+ };
405
434
  }
406
435
 
407
436
  async proposeIntention(input: {
@@ -648,6 +677,7 @@ export class PseudoBackend implements IBackend {
648
677
 
649
678
  // Verify the signature
650
679
  const payload = HexToUint8Array(pendingTx.payload);
680
+
651
681
  const verified = await SignatureVerifier.verifyTransactionSignature({
652
682
  payload,
653
683
  targetAddress: input.userAddress,
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  AuthLoginRequest,
3
- CreateMSafeAccountInfoRequest,
3
+ CreateMSafeAccountInfoRequest, HistoryTransaction,
4
4
  MSafeAccountInfo,
5
- UserWithOwnedMSafe,
6
- } from '@msafe/sui3-utils';
5
+ UserWithOwnedMSafe
6
+ } from "@msafe/sui3-utils";
7
7
  import { PublicKey, SerializedSignature } from '@mysten/sui.js/cryptography';
8
8
 
9
- import { JWTToken } from '@/backend/types';
9
+ import { JWTToken, PaginationOption, PaginationResponse } from '@/backend/types';
10
10
  import { TxIntention } from '@/transactions/intention';
11
11
  import { FutureIntention, HistorySendTx, PendingTx } from '@/types/msafe';
12
12
 
@@ -19,8 +19,14 @@ export interface IBackend {
19
19
  getMSafeAccountInfo(msafeAddress: string): Promise<MSafeAccountInfo>;
20
20
  getUserInfo(userAddress: string): Promise<UserWithOwnedMSafe>;
21
21
  getPendingTransactions(msafeAddress: string): Promise<PendingTx[]>;
22
- getHistoryTransactions(msafeAddress: string): Promise<HistorySendTx[]>;
23
- getFutureIntentions(msafeAddress: string): Promise<FutureIntention[]>;
22
+ getHistoryTransactions(
23
+ msafeAddress: string,
24
+ paginationOption?: PaginationOption,
25
+ ): Promise<PaginationResponse<HistoryTransaction>>;
26
+ getFutureIntentions(
27
+ msafeAddress: string,
28
+ paginationOption?: PaginationOption,
29
+ ): Promise<PaginationResponse<FutureIntention>>;
24
30
  getCurrentSequenceNumber(msafeAddress: string): Promise<number>;
25
31
  getNextSequenceNumber(msafeAddress: string): Promise<number>;
26
32
 
@@ -1 +1,19 @@
1
1
  export type JWTToken = string;
2
+
3
+ export interface PaginationOption {
4
+ page?: number;
5
+ pageSize: number;
6
+ }
7
+
8
+ export interface PaginationResponse<T> {
9
+ items: T[];
10
+ meta: PaginationMeta;
11
+ }
12
+
13
+ export interface PaginationMeta {
14
+ totalItems: number;
15
+ itemCount: number;
16
+ itemsPerPage: number;
17
+ totalPages: number;
18
+ currentPage: number;
19
+ }
@@ -1,4 +1,4 @@
1
- import { MSafeAccountInfo, MultisigAccountManager } from "@msafe/sui3-utils";
1
+ import { MSafeAccountInfo, MultisigAccountManager, verifyTransactionSignature } from "@msafe/sui3-utils";
2
2
  import { SerializedSignature } from '@mysten/sui.js/cryptography';
3
3
 
4
4
  import { MessageHelper } from '@/core/MessageHelper';
@@ -6,6 +6,8 @@ import { MSafeGlobals } from '@/globals/MSafeGlobals';
6
6
  import { IntentionHelper, TxIntention } from '@/transactions/intention';
7
7
  import { PendingTx } from '@/types/msafe';
8
8
  import { HexToUint8Array } from '@/utils/buffer';
9
+ import { PaginationOption } from "@/backend/types";
10
+ import { SignatureVerifier } from "@/utils";
9
11
 
10
12
  export class MSafeAccount {
11
13
  public multisigManager: MultisigAccountManager;
@@ -30,12 +32,14 @@ export class MSafeAccount {
30
32
  return this.backend.getPendingTransactions(this.address);
31
33
  }
32
34
 
33
- async historyTransaction() {
34
- return this.backend.getHistoryTransactions(this.address);
35
+ async historyTransaction(paginationOption?: PaginationOption) {
36
+ const paginatedHistoryTransactions = await this.backend.getHistoryTransactions(this.address, paginationOption);
37
+ return paginatedHistoryTransactions.items;
35
38
  }
36
39
 
37
- async futureIntentions() {
38
- return this.backend.getFutureIntentions(this.address);
40
+ async futureIntentions(paginationOption?: PaginationOption) {
41
+ const paginatedIntentions = await this.backend.getFutureIntentions(this.address, paginationOption);
42
+ return paginatedIntentions.items;
39
43
  }
40
44
 
41
45
  async currentSequenceNumber() {
@@ -14,6 +14,7 @@ export interface MSafeConfig {
14
14
  };
15
15
  backend: DBConfig;
16
16
  apiURL: string;
17
+ syncingURL: string;
17
18
  }
18
19
 
19
20
  export interface MSafeConfigOptions {
@@ -56,6 +57,8 @@ export const TESTNET_RPC_URL = 'https://sui-testnet.blockvision.org/v1/2Sgk89ivT
56
57
  export const MAINNET_RPC_URL = 'https://sui-mainnet.blockvision.org/v1/2Sgk7NPvqkd7mESYkxF01yX15l7';
57
58
 
58
59
  export const LOCAL_API_URL = 'http://127.0.0.1:3000';
60
+ export const LOCAL_SYNCING_URL = 'http://127.0.0.1:3001';
61
+
59
62
  export const DEV_API_URL = 'http://13.56.226.148';
60
63
 
61
64
  export const ENV_CONFIGS = new Map<MSafeEnv, MSafeConfig>([
@@ -67,6 +70,7 @@ export const ENV_CONFIGS = new Map<MSafeEnv, MSafeConfig>([
67
70
  },
68
71
  backend: LOCAL_DATABASE_CONFIG,
69
72
  apiURL: LOCAL_API_URL,
73
+ syncingURL: LOCAL_SYNCING_URL,
70
74
  },
71
75
  ],
72
76
  [
@@ -77,6 +81,7 @@ export const ENV_CONFIGS = new Map<MSafeEnv, MSafeConfig>([
77
81
  },
78
82
  backend: LOCAL_DATABASE_CONFIG,
79
83
  apiURL: LOCAL_API_URL,
84
+ syncingURL: LOCAL_SYNCING_URL,
80
85
  },
81
86
  ],
82
87
  [
@@ -87,6 +92,7 @@ export const ENV_CONFIGS = new Map<MSafeEnv, MSafeConfig>([
87
92
  },
88
93
  backend: DEV_DATABASE_CONFIG,
89
94
  apiURL: DEV_API_URL,
95
+ syncingURL: LOCAL_SYNCING_URL,
90
96
  },
91
97
  ],
92
98
  ]);