@mysten/wallet-standard 0.11.5 → 0.12.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/CHANGELOG.md +20 -0
- package/dist/cjs/detect.d.ts +1 -5
- package/dist/cjs/detect.js +1 -5
- package/dist/cjs/detect.js.map +2 -2
- package/dist/cjs/features/index.d.ts +9 -2
- package/dist/cjs/features/index.js +3 -0
- package/dist/cjs/features/index.js.map +2 -2
- package/dist/cjs/features/suiReportTransactionEffects.d.ts +22 -0
- package/dist/cjs/features/suiReportTransactionEffects.js +17 -0
- package/dist/cjs/features/suiReportTransactionEffects.js.map +7 -0
- package/dist/cjs/features/suiSignAndExecuteTransaction.d.ts +26 -0
- package/dist/cjs/features/suiSignAndExecuteTransaction.js +17 -0
- package/dist/cjs/features/suiSignAndExecuteTransaction.js.map +7 -0
- package/dist/cjs/features/suiSignAndExecuteTransactionBlock.d.ts +5 -1
- package/dist/cjs/features/suiSignAndExecuteTransactionBlock.js.map +1 -1
- package/dist/cjs/features/suiSignMessage.d.ts +2 -0
- package/dist/cjs/features/suiSignMessage.js.map +1 -1
- package/dist/cjs/features/suiSignPersonalMessage.d.ts +2 -0
- package/dist/cjs/features/suiSignPersonalMessage.js.map +1 -1
- package/dist/cjs/features/suiSignTransaction.d.ts +32 -0
- package/dist/cjs/features/suiSignTransaction.js +17 -0
- package/dist/cjs/features/suiSignTransaction.js.map +7 -0
- package/dist/cjs/features/suiSignTransactionBlock.d.ts +8 -2
- package/dist/cjs/features/suiSignTransactionBlock.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.js +10 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.d.ts +148 -0
- package/dist/cjs/types.js +17 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/cjs/wallet.d.ts +7 -0
- package/dist/cjs/wallet.js +61 -0
- package/dist/cjs/wallet.js.map +2 -2
- package/dist/esm/detect.d.ts +1 -5
- package/dist/esm/detect.js +1 -5
- package/dist/esm/detect.js.map +2 -2
- package/dist/esm/features/index.d.ts +9 -2
- package/dist/esm/features/index.js +3 -0
- package/dist/esm/features/index.js.map +2 -2
- package/dist/esm/features/suiReportTransactionEffects.d.ts +22 -0
- package/dist/esm/features/suiReportTransactionEffects.js +1 -0
- package/dist/esm/features/suiReportTransactionEffects.js.map +7 -0
- package/dist/esm/features/suiSignAndExecuteTransaction.d.ts +26 -0
- package/dist/esm/features/suiSignAndExecuteTransaction.js +1 -0
- package/dist/esm/features/suiSignAndExecuteTransaction.js.map +7 -0
- package/dist/esm/features/suiSignAndExecuteTransactionBlock.d.ts +5 -1
- package/dist/esm/features/suiSignMessage.d.ts +2 -0
- package/dist/esm/features/suiSignPersonalMessage.d.ts +2 -0
- package/dist/esm/features/suiSignTransaction.d.ts +32 -0
- package/dist/esm/features/suiSignTransaction.js +1 -0
- package/dist/esm/features/suiSignTransaction.js.map +7 -0
- package/dist/esm/features/suiSignTransactionBlock.d.ts +8 -2
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/types.d.ts +148 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +7 -0
- package/dist/esm/wallet.d.ts +7 -0
- package/dist/esm/wallet.js +57 -0
- package/dist/esm/wallet.js.map +3 -3
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/detect.ts +1 -10
- package/src/features/index.ts +20 -11
- package/src/features/suiReportTransactionEffects.ts +30 -0
- package/src/features/suiSignAndExecuteTransaction.ts +35 -0
- package/src/features/suiSignAndExecuteTransactionBlock.ts +5 -1
- package/src/features/suiSignMessage.ts +2 -0
- package/src/features/suiSignPersonalMessage.ts +2 -0
- package/src/features/suiSignTransaction.ts +41 -0
- package/src/features/suiSignTransactionBlock.ts +8 -2
- package/src/index.ts +2 -1
- package/src/types.ts +170 -0
- package/src/wallet.ts +83 -0
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { Transaction } from '@mysten/sui/transactions';
|
|
5
5
|
import type { IdentifierString, WalletAccount } from '@wallet-standard/core';
|
|
6
6
|
|
|
7
7
|
/** The latest API version of the signTransactionBlock API. */
|
|
8
8
|
export type SuiSignTransactionBlockVersion = '1.0.0';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
+
* @deprecated Use `sui:signTransaction` instead.
|
|
12
|
+
*
|
|
11
13
|
* A Wallet Standard feature for signing a transaction, and returning the
|
|
12
14
|
* serialized transaction and transaction signature.
|
|
13
15
|
*/
|
|
@@ -16,17 +18,19 @@ export type SuiSignTransactionBlockFeature = {
|
|
|
16
18
|
'sui:signTransactionBlock': {
|
|
17
19
|
/** Version of the feature API. */
|
|
18
20
|
version: SuiSignTransactionBlockVersion;
|
|
21
|
+
/** @deprecated Use `sui:signTransaction` instead. */
|
|
19
22
|
signTransactionBlock: SuiSignTransactionBlockMethod;
|
|
20
23
|
};
|
|
21
24
|
};
|
|
22
25
|
|
|
26
|
+
/** @deprecated Use `sui:signTransaction` instead. */
|
|
23
27
|
export type SuiSignTransactionBlockMethod = (
|
|
24
28
|
input: SuiSignTransactionBlockInput,
|
|
25
29
|
) => Promise<SuiSignTransactionBlockOutput>;
|
|
26
30
|
|
|
27
31
|
/** Input for signing transactions. */
|
|
28
32
|
export interface SuiSignTransactionBlockInput {
|
|
29
|
-
transactionBlock:
|
|
33
|
+
transactionBlock: Transaction;
|
|
30
34
|
account: WalletAccount;
|
|
31
35
|
chain: IdentifierString;
|
|
32
36
|
}
|
|
@@ -35,6 +39,8 @@ export interface SuiSignTransactionBlockInput {
|
|
|
35
39
|
export interface SuiSignTransactionBlockOutput extends SignedTransactionBlock {}
|
|
36
40
|
|
|
37
41
|
export interface SignedTransactionBlock {
|
|
42
|
+
/** Transaction as base64 encoded bcs. */
|
|
38
43
|
transactionBlockBytes: string;
|
|
44
|
+
/** Base64 encoded signature */
|
|
39
45
|
signature: string;
|
|
40
46
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
export * from '@wallet-standard/core';
|
|
5
5
|
|
|
6
|
-
export type
|
|
6
|
+
export { type Wallet, signAndExecuteTransaction, signTransaction } from './wallet.js';
|
|
7
7
|
export * from './features/index.js';
|
|
8
8
|
export * from './detect.js';
|
|
9
9
|
export * from './chains.js';
|
|
10
|
+
export * from './types.js';
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/** Contains data related to the gas payment for a Transaction */
|
|
5
|
+
export interface GasData {
|
|
6
|
+
/** The budget set for this transaction */
|
|
7
|
+
budget: string | number | null;
|
|
8
|
+
/** The gas price used for this transaction */
|
|
9
|
+
price: string | number | null;
|
|
10
|
+
/** The owner of the gas coins used to fund the transactions, this is either the sender or the gas sponsor */
|
|
11
|
+
owner: string | null;
|
|
12
|
+
/** The list of SUI coins to fund the transaction */
|
|
13
|
+
payment: { objectId: string; version: string; digest: string }[] | null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Represent the serialized state of a partially built Transaction
|
|
18
|
+
* This format is designed to support transactions that have not been fully build
|
|
19
|
+
* allowing most properties to be omitted or set to null. It also supports
|
|
20
|
+
* unresolved object references, unresolved pure values, and Transaction Intents.
|
|
21
|
+
*/
|
|
22
|
+
export interface SerializedTransactionDataV2 {
|
|
23
|
+
version: 2;
|
|
24
|
+
/** The sender of the transaction */
|
|
25
|
+
sender: string | null | undefined;
|
|
26
|
+
/** The expiration of the transaction */
|
|
27
|
+
expiration: { Epoch: number } | { None: true } | null | undefined;
|
|
28
|
+
/** The gas data */
|
|
29
|
+
gasData: GasData;
|
|
30
|
+
/** The inputs to the transaction */
|
|
31
|
+
inputs: CallArg[];
|
|
32
|
+
/** The commands to execute */
|
|
33
|
+
commands: Command[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Represents an input to a Transaction, either as a fully resolved Object or Pure input
|
|
38
|
+
* or as an unresolved partial reference which needs to be resolved before the transaction
|
|
39
|
+
* can be serialized to bcs and executed.
|
|
40
|
+
*/
|
|
41
|
+
export type CallArg =
|
|
42
|
+
| {
|
|
43
|
+
Object: ObjectArg;
|
|
44
|
+
}
|
|
45
|
+
| {
|
|
46
|
+
Pure: PureArg;
|
|
47
|
+
}
|
|
48
|
+
| {
|
|
49
|
+
UnresolvedPure: UnresolvedPureArg;
|
|
50
|
+
}
|
|
51
|
+
| {
|
|
52
|
+
UnresolvedObject: UnresolvedObjectArg;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type ObjectArg =
|
|
56
|
+
| {
|
|
57
|
+
ImmOrOwnedObject: {
|
|
58
|
+
objectId: string;
|
|
59
|
+
version: string | number;
|
|
60
|
+
digest: string;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
| {
|
|
64
|
+
SharedObject: {
|
|
65
|
+
objectId: string;
|
|
66
|
+
initialSharedVersion: string;
|
|
67
|
+
mutable: boolean;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
| {
|
|
71
|
+
Receiving: {
|
|
72
|
+
objectId: string;
|
|
73
|
+
version: string | number;
|
|
74
|
+
digest: string;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export interface PureArg {
|
|
79
|
+
bytes: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Represents an un-serialized pure value.
|
|
84
|
+
* The correct bcs schema will need to be determined before this value can be serialized to bcs */
|
|
85
|
+
export interface UnresolvedPureArg {
|
|
86
|
+
value: unknown;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Represents an unresolved object reference. This allows objects to be referenced by only their ID.
|
|
91
|
+
* version and digest details may also be added to unresolved object references.
|
|
92
|
+
* To fully resolve a reference, the correct ObjectArg type needs to be determined based on the type of object,
|
|
93
|
+
* and how it used in the transaction (eg, is it used mutably if it's shared, and is it a receiving object if it's not shared)
|
|
94
|
+
*/
|
|
95
|
+
export interface UnresolvedObjectArg {
|
|
96
|
+
objectId: string;
|
|
97
|
+
version?: string | null | undefined;
|
|
98
|
+
digest?: string | null | undefined;
|
|
99
|
+
initialSharedVersion?: string | null | undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type Argument =
|
|
103
|
+
| {
|
|
104
|
+
GasCoin: true;
|
|
105
|
+
}
|
|
106
|
+
| {
|
|
107
|
+
Input: number;
|
|
108
|
+
}
|
|
109
|
+
| {
|
|
110
|
+
Result: number;
|
|
111
|
+
}
|
|
112
|
+
| {
|
|
113
|
+
NestedResult: [number, number];
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export type Command =
|
|
117
|
+
| {
|
|
118
|
+
MoveCall: {
|
|
119
|
+
package: string;
|
|
120
|
+
module: string;
|
|
121
|
+
function: string;
|
|
122
|
+
typeArguments: string[];
|
|
123
|
+
arguments: Argument[];
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
| {
|
|
127
|
+
TransferObjects: {
|
|
128
|
+
objects: Argument[];
|
|
129
|
+
address: Argument;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
| {
|
|
133
|
+
SplitCoins: {
|
|
134
|
+
coin: Argument;
|
|
135
|
+
amounts: Argument[];
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
| {
|
|
139
|
+
MergeCoins: {
|
|
140
|
+
destination: Argument;
|
|
141
|
+
sources: Argument[];
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
| {
|
|
145
|
+
Publish: {
|
|
146
|
+
modules: string[];
|
|
147
|
+
dependencies: string[];
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
| {
|
|
151
|
+
MakeMoveVec: {
|
|
152
|
+
type: string | null;
|
|
153
|
+
elements: Argument[];
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
| {
|
|
157
|
+
Upgrade: {
|
|
158
|
+
modules: string[];
|
|
159
|
+
dependencies: string[];
|
|
160
|
+
package: string;
|
|
161
|
+
ticket: Argument;
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
| {
|
|
165
|
+
$Intent: {
|
|
166
|
+
name: string;
|
|
167
|
+
inputs: Record<string, Argument | Argument[]>;
|
|
168
|
+
data: Record<string, unknown>;
|
|
169
|
+
};
|
|
170
|
+
};
|
package/src/wallet.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
5
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
6
|
+
import { fromB64, toB64 } from '@mysten/sui/utils';
|
|
7
|
+
import type { WalletWithFeatures } from '@wallet-standard/core';
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
SuiSignAndExecuteTransactionInput,
|
|
11
|
+
SuiSignTransactionInput,
|
|
12
|
+
SuiWalletFeatures,
|
|
13
|
+
} from './features/index.js';
|
|
14
|
+
|
|
4
15
|
declare module '@wallet-standard/core' {
|
|
5
16
|
export interface Wallet {
|
|
6
17
|
/**
|
|
@@ -10,6 +21,78 @@ declare module '@wallet-standard/core' {
|
|
|
10
21
|
*/
|
|
11
22
|
readonly id?: string;
|
|
12
23
|
}
|
|
24
|
+
|
|
25
|
+
export interface StandardConnectOutput {
|
|
26
|
+
supportedIntents?: string[];
|
|
27
|
+
}
|
|
13
28
|
}
|
|
14
29
|
|
|
15
30
|
export type { Wallet } from '@wallet-standard/core';
|
|
31
|
+
|
|
32
|
+
export async function signAndExecuteTransaction(
|
|
33
|
+
wallet: WalletWithFeatures<Partial<SuiWalletFeatures>>,
|
|
34
|
+
input: SuiSignAndExecuteTransactionInput,
|
|
35
|
+
) {
|
|
36
|
+
if (wallet.features['sui:signAndExecuteTransaction']) {
|
|
37
|
+
return wallet.features['sui:signAndExecuteTransaction'].signAndExecuteTransaction(input);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!wallet.features['sui:signAndExecuteTransactionBlock']) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`Provided wallet (${wallet.name}) does not support the signAndExecuteTransaction feature.`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const { signAndExecuteTransactionBlock } = wallet.features['sui:signAndExecuteTransactionBlock'];
|
|
47
|
+
|
|
48
|
+
const transactionBlock = Transaction.from(await input.transaction.toJSON());
|
|
49
|
+
const { digest, rawEffects, rawTransaction } = await signAndExecuteTransactionBlock({
|
|
50
|
+
...input,
|
|
51
|
+
transactionBlock,
|
|
52
|
+
options: {
|
|
53
|
+
showRawEffects: true,
|
|
54
|
+
showRawInput: true,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const [
|
|
59
|
+
{
|
|
60
|
+
txSignatures: [signature],
|
|
61
|
+
intentMessage: { value: bcsTransaction },
|
|
62
|
+
},
|
|
63
|
+
] = bcs.SenderSignedData.parse(fromB64(rawTransaction!));
|
|
64
|
+
|
|
65
|
+
const bytes = bcs.TransactionData.serialize(bcsTransaction).toBase64();
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
digest,
|
|
69
|
+
signature,
|
|
70
|
+
bytes,
|
|
71
|
+
effects: toB64(new Uint8Array(rawEffects!)),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function signTransaction(
|
|
76
|
+
wallet: WalletWithFeatures<Partial<SuiWalletFeatures>>,
|
|
77
|
+
input: SuiSignTransactionInput,
|
|
78
|
+
) {
|
|
79
|
+
if (wallet.features['sui:signTransaction']) {
|
|
80
|
+
return wallet.features['sui:signTransaction'].signTransaction(input);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!wallet.features['sui:signTransactionBlock']) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
`Provided wallet (${wallet.name}) does not support the signTransaction feature.`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const { signTransactionBlock } = wallet.features['sui:signTransactionBlock'];
|
|
90
|
+
|
|
91
|
+
const transaction = Transaction.from(await input.transaction.toJSON());
|
|
92
|
+
const { transactionBlockBytes, signature } = await signTransactionBlock({
|
|
93
|
+
...input,
|
|
94
|
+
transactionBlock: transaction,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
return { bytes: transactionBlockBytes, signature };
|
|
98
|
+
}
|