@scallop-io/sui-kit 2.0.1 → 2.2.0
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/README.md +6 -6
- package/dist/index.cjs +11 -11
- package/dist/index.d.cts +69 -69
- package/dist/index.d.ts +69 -69
- package/dist/index.js +7 -7
- package/package.json +164 -161
- package/src/index.ts +11 -11
- package/src/libs/multiSig/client.ts +35 -35
- package/src/libs/multiSig/index.ts +1 -1
- package/src/libs/multiSig/publickey.ts +8 -8
- package/src/libs/suiAccountManager/crypto.ts +4 -4
- package/src/libs/suiAccountManager/index.ts +82 -82
- package/src/libs/suiAccountManager/keypair.ts +13 -13
- package/src/libs/suiAccountManager/util.ts +20 -20
- package/src/libs/suiInteractor/index.ts +6 -6
- package/src/libs/suiInteractor/suiInteractor.ts +279 -272
- package/src/libs/suiInteractor/util.ts +6 -6
- package/src/libs/suiModel/index.ts +2 -2
- package/src/libs/suiModel/suiOwnedObject.ts +57 -57
- package/src/libs/suiModel/suiSharedObject.ts +27 -27
- package/src/libs/suiTxBuilder/index.ts +303 -302
- package/src/libs/suiTxBuilder/util.ts +185 -183
- package/src/suiKit.ts +422 -410
- package/src/types/index.ts +71 -76
|
@@ -1,69 +1,69 @@
|
|
|
1
1
|
// TODO: I think we can remove this file or update to NormalizedCallArg
|
|
2
|
-
import type { SuiClientTypes } from
|
|
3
|
-
import type { CallArg } from
|
|
2
|
+
import type { SuiClientTypes } from "@mysten/sui/client";
|
|
3
|
+
import type { CallArg } from "@mysten/sui/transactions";
|
|
4
4
|
|
|
5
5
|
// Transaction result type with effects
|
|
6
6
|
type TransactionResultWithEffects = SuiClientTypes.TransactionResult<{
|
|
7
|
-
|
|
7
|
+
effects: true;
|
|
8
8
|
}>;
|
|
9
9
|
|
|
10
10
|
export class SuiOwnedObject {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
public readonly objectId: string;
|
|
12
|
+
public version?: string;
|
|
13
|
+
public digest?: string;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
constructor(param: { objectId: string; version?: string; digest?: string }) {
|
|
16
|
+
this.objectId = param.objectId;
|
|
17
|
+
this.version = param.version;
|
|
18
|
+
this.digest = param.digest;
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Check if the object is fully initialized.
|
|
23
|
+
* So that when it's used as an input, it won't be necessary to fetch from fullnode again.
|
|
24
|
+
* Which can save time when sending transactions.
|
|
25
|
+
*/
|
|
26
|
+
isFullObject(): boolean {
|
|
27
|
+
return !!this.version && !!this.digest;
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
30
|
+
asCallArg(): CallArg | string {
|
|
31
|
+
if (!this.version || !this.digest) {
|
|
32
|
+
return this.objectId;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
$kind: "Object",
|
|
36
|
+
Object: {
|
|
37
|
+
$kind: "ImmOrOwnedObject",
|
|
38
|
+
ImmOrOwnedObject: {
|
|
39
|
+
objectId: this.objectId,
|
|
40
|
+
version: this.version,
|
|
41
|
+
digest: this.digest,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Update object version & digest based on the transaction response.
|
|
49
|
+
* @param txResponse
|
|
50
|
+
*/
|
|
51
|
+
updateFromTxResponse(txResponse: TransactionResultWithEffects) {
|
|
52
|
+
const tx = txResponse.Transaction ?? txResponse.FailedTransaction;
|
|
53
|
+
if (!tx) {
|
|
54
|
+
throw new Error("Bad transaction response!");
|
|
55
|
+
}
|
|
56
|
+
const effects = tx.effects;
|
|
57
|
+
if (!effects) {
|
|
58
|
+
throw new Error("Transaction response has no effects!");
|
|
59
|
+
}
|
|
60
|
+
for (const change of effects.changedObjects) {
|
|
61
|
+
if (change.objectId === this.objectId && change.outputDigest) {
|
|
62
|
+
this.digest = change.outputDigest;
|
|
63
|
+
this.version = change.outputVersion ?? undefined;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
throw new Error("Could not find object in transaction response!");
|
|
68
|
+
}
|
|
69
69
|
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
// TODO: I think we can remove this file or update to NormalizedCallArg
|
|
2
|
-
import type { CallArg } from
|
|
2
|
+
import type { CallArg } from "@mysten/sui/transactions";
|
|
3
3
|
|
|
4
4
|
export class SuiSharedObject {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
public readonly objectId: string;
|
|
6
|
+
public initialSharedVersion?: string;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
constructor(param: {
|
|
9
|
+
objectId: string;
|
|
10
|
+
initialSharedVersion?: string;
|
|
11
|
+
mutable?: boolean;
|
|
12
|
+
}) {
|
|
13
|
+
this.objectId = param.objectId;
|
|
14
|
+
this.initialSharedVersion = param.initialSharedVersion;
|
|
15
|
+
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
17
|
+
asCallArg(mutable: boolean = false): CallArg | string {
|
|
18
|
+
if (!this.initialSharedVersion) {
|
|
19
|
+
return this.objectId;
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
$kind: "Object",
|
|
23
|
+
Object: {
|
|
24
|
+
$kind: "SharedObject",
|
|
25
|
+
SharedObject: {
|
|
26
|
+
objectId: this.objectId,
|
|
27
|
+
initialSharedVersion: this.initialSharedVersion,
|
|
28
|
+
mutable,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
33
|
}
|