@msafe/sui3-sdk 0.0.17 → 0.0.18
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.
- package/dist/index.cjs +58 -219
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -38
- package/dist/index.d.ts +4 -38
- package/dist/index.js +61 -219
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/src/backend/BackendImpl.ts +1 -1
- package/src/backend/interface.ts +1 -2
- package/src/core/MSafeAccount.ts +7 -11
- package/src/index.ts +0 -1
- package/src/types/msafe.ts +1 -3
- package/src/transactions/coin-transfer.ts +0 -64
- package/src/transactions/index.ts +0 -3
- package/src/transactions/intention.ts +0 -63
- package/src/transactions/object-transfer.ts +0 -66
- package/src/transactions/reject.ts +0 -17
- package/src/transactions/stream.ts +0 -1
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { SuiClient } from '@mysten/sui.js/client';
|
|
2
|
-
|
|
3
|
-
import { buildCoinTransferTxb, IntentionCoinTransfer } from '@/transactions/coin-transfer';
|
|
4
|
-
import { buildObjectTransferTxb, IntentionObjectTransfer } from '@/transactions/object-transfer';
|
|
5
|
-
import { buildRejectTxb } from '@/transactions/reject';
|
|
6
|
-
|
|
7
|
-
export type TxIntention = IntentionObjectTransfer | IntentionCoinTransfer;
|
|
8
|
-
|
|
9
|
-
// TODO: Refactor later
|
|
10
|
-
export class IntentionHelper {
|
|
11
|
-
static ser(intention: TxIntention) {
|
|
12
|
-
return JSON.stringify(intention);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
static de(val: string): TxIntention {
|
|
16
|
-
const intention = JSON.parse(val);
|
|
17
|
-
if (typeof intention !== 'object' || !('txType' in intention)) {
|
|
18
|
-
throw new Error(`Failed to deserialize intention: ${val}`);
|
|
19
|
-
}
|
|
20
|
-
return JSON.parse(val);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// TODO: Add gas option here.
|
|
24
|
-
static buildTxb(input: { suiClient: SuiClient; intention: TxIntention; sender: string }) {
|
|
25
|
-
switch (input.intention.txType) {
|
|
26
|
-
case 'CoinTransfer':
|
|
27
|
-
return buildCoinTransferTxb({
|
|
28
|
-
suiClient: input.suiClient,
|
|
29
|
-
sender: input.sender,
|
|
30
|
-
intention: input.intention as IntentionCoinTransfer,
|
|
31
|
-
});
|
|
32
|
-
case 'ObjectTransfer':
|
|
33
|
-
return buildObjectTransferTxb({
|
|
34
|
-
suiClient: input.suiClient,
|
|
35
|
-
sender: input.sender,
|
|
36
|
-
intention: input.intention as IntentionObjectTransfer,
|
|
37
|
-
});
|
|
38
|
-
default:
|
|
39
|
-
throw new Error(`Unknown tx type: ${input.intention}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
static getTxType(intention: TxIntention) {
|
|
44
|
-
switch (intention.txType) {
|
|
45
|
-
case 'CoinTransfer':
|
|
46
|
-
return {
|
|
47
|
-
txType: 'CoinTransfer',
|
|
48
|
-
txSubType: 'CoinTransfer',
|
|
49
|
-
};
|
|
50
|
-
case 'ObjectTransfer':
|
|
51
|
-
return {
|
|
52
|
-
txType: 'ObjectTransfer',
|
|
53
|
-
txSubType: 'ObjectTransfer',
|
|
54
|
-
};
|
|
55
|
-
default:
|
|
56
|
-
throw new Error('Unknown intention type');
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
static buildRejectTransaction(input: { msafeAddress: string; payloadToReject: string }) {
|
|
61
|
-
return buildRejectTxb({ sender: input.msafeAddress, payloadToReject: input.payloadToReject });
|
|
62
|
-
}
|
|
63
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { SuiClient } from '@mysten/sui.js/client';
|
|
2
|
-
import type { SuiObjectResponse } from '@mysten/sui.js/src/client/types';
|
|
3
|
-
import { TransactionBlock } from '@mysten/sui.js/transactions';
|
|
4
|
-
|
|
5
|
-
import { Formatter } from '@/utils/format';
|
|
6
|
-
|
|
7
|
-
export interface IntentionObjectTransfer {
|
|
8
|
-
txType: 'ObjectTransfer';
|
|
9
|
-
receiver: string;
|
|
10
|
-
objectId: string;
|
|
11
|
-
objectType: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function buildObjectTransferTxb(input: {
|
|
15
|
-
suiClient: SuiClient;
|
|
16
|
-
sender: string;
|
|
17
|
-
intention: IntentionObjectTransfer;
|
|
18
|
-
}) {
|
|
19
|
-
await validateObjectTransfer(input);
|
|
20
|
-
|
|
21
|
-
const txb = new TransactionBlock();
|
|
22
|
-
txb.transferObjects([txb.object(input.intention.objectId)], txb.pure(input.intention.receiver));
|
|
23
|
-
txb.setSender(input.sender);
|
|
24
|
-
|
|
25
|
-
return txb;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async function validateObjectTransfer(input: {
|
|
29
|
-
suiClient: SuiClient;
|
|
30
|
-
sender: string;
|
|
31
|
-
intention: IntentionObjectTransfer;
|
|
32
|
-
}) {
|
|
33
|
-
const { suiClient, sender, intention } = input;
|
|
34
|
-
const obj = await suiClient.getObject({
|
|
35
|
-
id: intention.objectId,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
if (obj.data === undefined) {
|
|
39
|
-
throw new Error('Object not found');
|
|
40
|
-
}
|
|
41
|
-
if (!obj.data?.type) {
|
|
42
|
-
throw new Error('Object type is null');
|
|
43
|
-
}
|
|
44
|
-
if (!Formatter.isSuiStructEqual(obj.data.type, intention.objectType)) {
|
|
45
|
-
throw new Error('Object type not expected');
|
|
46
|
-
}
|
|
47
|
-
if (Formatter.isCoinObjectType(obj.data.type)) {
|
|
48
|
-
throw new Error('Can not transfer coin object in Object Transfer transactions');
|
|
49
|
-
}
|
|
50
|
-
const addressOwner = getAddressOwner(obj);
|
|
51
|
-
if (!Formatter.isSuiAddressEqual(addressOwner, sender)) {
|
|
52
|
-
throw new Error('Object owner not match');
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function getAddressOwner(object: SuiObjectResponse) {
|
|
57
|
-
const owner = object.data?.owner;
|
|
58
|
-
if (!owner) {
|
|
59
|
-
throw new Error('Object Owner not found');
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (typeof owner !== 'object' || !('AddressOwner' in owner)) {
|
|
63
|
-
throw new Error('Invalid object owner');
|
|
64
|
-
}
|
|
65
|
-
return owner.AddressOwner;
|
|
66
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { TransactionBlock } from '@mysten/sui.js/transactions';
|
|
2
|
-
|
|
3
|
-
import { HexToUint8Array } from '@/utils/buffer';
|
|
4
|
-
|
|
5
|
-
export async function buildRejectTxb(input: { sender: string; payloadToReject: string }) {
|
|
6
|
-
const approveTxb = TransactionBlock.from(HexToUint8Array(input.payloadToReject) as Uint8Array);
|
|
7
|
-
const gasPayment = approveTxb.blockData.gasConfig.payment;
|
|
8
|
-
if (!gasPayment) {
|
|
9
|
-
throw new Error('No gas payment found for approve payload');
|
|
10
|
-
}
|
|
11
|
-
// Reject transaction is an empty transaction block with the same gas payment as the
|
|
12
|
-
// transaction to be rejected.
|
|
13
|
-
const txb = new TransactionBlock();
|
|
14
|
-
txb.setGasPayment(gasPayment);
|
|
15
|
-
txb.setSender(input.sender);
|
|
16
|
-
return txb;
|
|
17
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// TODO: Stream related transactions.
|