@msafe/sui3-sdk 0.0.13 → 0.0.14

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.
@@ -1,95 +0,0 @@
1
- import { normalizeSuiAddress } from '@mysten/sui.js/utils';
2
- import { MD5 } from 'crypto-js';
3
-
4
- import { IntentionHelper, TxIntention } from '@/transactions/intention';
5
- import { UpdateAddressBookEntry } from '@/types/address-book';
6
- import { stringToBuffer } from '@/utils';
7
-
8
- export class MessageHelper {
9
- // Message used for MSafe creation
10
- static createMSafeMessage(msafeAddress: string): string {
11
- return `Create MSafe Account: ${msafeAddress}`;
12
- }
13
-
14
- static deCreateMSafeMessage(msg: string) {
15
- const regex = /Create MSafe Account: (.+)/;
16
- const matches = msg.match(regex);
17
- return matches ? matches[1] : undefined;
18
- }
19
-
20
- // Message to be used when user login. The timestamp string
21
- // is used to for extra validation.
22
- static welcomeMessage(timestamp: string): string {
23
- return `Welcome to MSafe. ${timestamp}`;
24
- }
25
-
26
- static deWelcomeMessage(msg: string): string | undefined {
27
- const regex = /Welcome to MSafe. (.+)/;
28
- const matches = msg.match(regex);
29
- return matches ? matches[1] : undefined;
30
- }
31
-
32
- static proposeIntentionMessage(data: ProposeIntentionData) {
33
- const { msafeAddress, intention, sn } = data;
34
- const intentionData = IntentionHelper.ser(intention);
35
- const msg: ProposeIntentionMessage = {
36
- intentionData,
37
- sequenceNumber: sn,
38
- msafeAddress,
39
- };
40
- return JSON.stringify(msg);
41
- }
42
-
43
- static deProposeIntentionMessage(s: string): ProposeIntentionData {
44
- const de = JSON.parse(s);
45
- if (
46
- !('intentionData' in de) ||
47
- typeof de.intentionData !== 'string' ||
48
- !('sequenceNumber' in de) ||
49
- typeof de.sequenceNumber !== 'number'
50
- ) {
51
- throw new Error('Invalid intention data');
52
- }
53
- const { msafeAddress, sequenceNumber, intentionData } = de;
54
- return {
55
- msafeAddress,
56
- sn: sequenceNumber,
57
- intention: IntentionHelper.de(intentionData),
58
- };
59
- }
60
-
61
- static updateAddressBookMessage(updates: UpdateAddressBookEntry[]) {
62
- const normalized = updates.map((update) => ({
63
- ...update,
64
- address: normalizeSuiAddress(update.address),
65
- }));
66
- function sortObjectKeys(obj: Record<string, any>): Record<string, any> {
67
- return Object.keys(obj)
68
- .sort()
69
- .reduce((result, key) => ({ ...result, [key]: obj[key] }), {} as Record<string, any>);
70
- }
71
-
72
- // Sort keys of each object in the updates array
73
- const sortedUpdates = normalized.map((update) => sortObjectKeys(update));
74
- const raw = JSON.stringify(sortedUpdates, null, 2);
75
- const encoded = stringToBuffer(raw);
76
- if (encoded.length <= 1024) {
77
- // BCS signing can handle this amount of data, directly return
78
- return raw;
79
- }
80
- const md5 = MD5(raw);
81
- return `Bulk address book update: ${md5}`;
82
- }
83
- }
84
-
85
- export interface ProposeIntentionData {
86
- msafeAddress: string;
87
- intention: TxIntention;
88
- sn: number;
89
- }
90
-
91
- export interface ProposeIntentionMessage {
92
- msafeAddress: string;
93
- intentionData: string;
94
- sequenceNumber: number;
95
- }
@@ -1,32 +0,0 @@
1
- import { PagedResult } from '@/types/pagination';
2
-
3
- export enum OpAddressBookType {
4
- Delete = 'delete',
5
- Upsert = 'upsert',
6
- }
7
-
8
- export type UpdateAddressBookEntry = DeleteAddressBookEntry | UpsertAddressBookEntry;
9
-
10
- export interface DeleteAddressBookEntry {
11
- opType: OpAddressBookType.Delete;
12
- address: string;
13
- }
14
-
15
- export interface UpsertAddressBookEntry {
16
- opType: OpAddressBookType.Upsert;
17
- address: string;
18
- addressName: string;
19
- remark?: string;
20
- }
21
-
22
- export type GetAddressBookResult = PagedResult<GetAddressBookResultEntry>;
23
-
24
- export interface GetAddressBookResultEntry {
25
- address: string;
26
-
27
- addressName: string;
28
-
29
- remark?: string;
30
-
31
- updatedAt: Date;
32
- }
@@ -1,19 +0,0 @@
1
- export type JWTToken = string;
2
-
3
- export interface PaginationOption {
4
- page?: number;
5
- limit?: 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,19 +0,0 @@
1
- export interface CreateMSafeAccountInfo {
2
- ownerWithWeight: {
3
- address: string;
4
- weight: number;
5
- }[];
6
- threshold: number;
7
- name: string;
8
- description?: string;
9
- creationNonce: number;
10
- }
11
-
12
- export interface CreatePermissionInfo {
13
- ownerWithWeight: {
14
- address: string;
15
- weight: number;
16
- }[];
17
- threshold: number;
18
- creationNonce: number;
19
- }
@@ -1,15 +0,0 @@
1
- export interface PagedResult<T> {
2
- data: T[];
3
-
4
- meta: PagedMeta;
5
- }
6
-
7
- export interface PagedMeta {
8
- page: number;
9
-
10
- limit: number;
11
-
12
- total: number;
13
-
14
- hasNext: boolean;
15
- }