@dynamic-labs-sdk/sui 0.1.0-alpha.29 → 0.1.0-alpha.30
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 +8 -0
- package/README.md +4 -18
- package/_extends.cjs.js +19 -0
- package/_extends.esm.js +15 -0
- package/addSuiWalletStandardExtension.cjs.js +303 -0
- package/addSuiWalletStandardExtension.esm.js +301 -0
- package/addWaasSuiExtension.cjs.js +140 -0
- package/addWaasSuiExtension.esm.js +138 -0
- package/index.cjs.js +146 -20
- package/index.esm.js +141 -17
- package/package.json +13 -5
- package/src/SuiNetworkProvider.types.d.ts +8 -0
- package/src/SuiNetworkProvider.types.d.ts.map +1 -0
- package/src/SuiWalletAccount.types.d.ts +8 -0
- package/src/SuiWalletAccount.types.d.ts.map +1 -0
- package/src/SuiWalletProvider.types.d.ts +40 -0
- package/src/SuiWalletProvider.types.d.ts.map +1 -0
- package/src/addSuiExtension/addSuiExtension.d.ts +11 -0
- package/src/addSuiExtension/addSuiExtension.d.ts.map +1 -0
- package/src/addSuiExtension/index.d.ts +2 -0
- package/src/addSuiExtension/index.d.ts.map +1 -0
- package/src/errors/NotSuiProviderError/NotSuiProviderError.d.ts.map +1 -1
- package/src/exports/index.d.ts +9 -4
- package/src/exports/index.d.ts.map +1 -1
- package/src/exports/waas.d.ts +2 -0
- package/src/exports/waas.d.ts.map +1 -0
- package/src/exports/walletStandard.d.ts +2 -0
- package/src/exports/walletStandard.d.ts.map +1 -0
- package/src/getSuiClient/getSuiClient.d.ts +3 -3
- package/src/getSuiClient/getSuiClient.d.ts.map +1 -1
- package/src/isSuiNetworkProvider/index.d.ts +2 -0
- package/src/isSuiNetworkProvider/index.d.ts.map +1 -0
- package/src/isSuiNetworkProvider/isSuiNetworkProvider.d.ts +10 -0
- package/src/isSuiNetworkProvider/isSuiNetworkProvider.d.ts.map +1 -0
- package/src/isSuiWalletAccount/isSuiWalletAccount.d.ts +5 -4
- package/src/isSuiWalletAccount/isSuiWalletAccount.d.ts.map +1 -1
- package/src/isSuiWalletProvider/isSuiWalletProvider.d.ts +1 -5
- package/src/isSuiWalletProvider/isSuiWalletProvider.d.ts.map +1 -1
- package/src/registerSuiNetworkProviderBuilder/index.d.ts +2 -0
- package/src/registerSuiNetworkProviderBuilder/index.d.ts.map +1 -0
- package/src/registerSuiNetworkProviderBuilder/registerSuiNetworkProviderBuilder.d.ts +3 -0
- package/src/registerSuiNetworkProviderBuilder/registerSuiNetworkProviderBuilder.d.ts.map +1 -0
- package/src/signAndExecuteTransaction/index.d.ts +2 -0
- package/src/signAndExecuteTransaction/index.d.ts.map +1 -0
- package/src/signAndExecuteTransaction/signAndExecuteTransaction.d.ts +17 -0
- package/src/signAndExecuteTransaction/signAndExecuteTransaction.d.ts.map +1 -0
- package/src/signAndExecuteTransactionBlock/index.d.ts +2 -0
- package/src/signAndExecuteTransactionBlock/index.d.ts.map +1 -0
- package/src/signAndExecuteTransactionBlock/signAndExecuteTransactionBlock.d.ts +25 -0
- package/src/signAndExecuteTransactionBlock/signAndExecuteTransactionBlock.d.ts.map +1 -0
- package/src/signTransaction/index.d.ts +2 -0
- package/src/signTransaction/index.d.ts.map +1 -0
- package/src/signTransaction/signTransaction.d.ts +17 -0
- package/src/signTransaction/signTransaction.d.ts.map +1 -0
- package/src/signTransactionBlock/index.d.ts +2 -0
- package/src/signTransactionBlock/index.d.ts.map +1 -0
- package/src/signTransactionBlock/signTransactionBlock.d.ts +20 -0
- package/src/signTransactionBlock/signTransactionBlock.d.ts.map +1 -0
- package/src/utils/createSuiNetworkProvider/createSuiNetworkProvider.d.ts +4 -0
- package/src/utils/createSuiNetworkProvider/createSuiNetworkProvider.d.ts.map +1 -0
- package/src/utils/createSuiNetworkProvider/index.d.ts +2 -0
- package/src/utils/createSuiNetworkProvider/index.d.ts.map +1 -0
- package/src/utils/fetchSuiBalance/fetchSuiBalance.d.ts +5 -0
- package/src/utils/fetchSuiBalance/fetchSuiBalance.d.ts.map +1 -0
- package/src/utils/fetchSuiBalance/index.d.ts +2 -0
- package/src/utils/fetchSuiBalance/index.d.ts.map +1 -0
- package/src/waas/WaasSuiWalletProvider.types.d.ts +4 -0
- package/src/waas/WaasSuiWalletProvider.types.d.ts.map +1 -0
- package/src/waas/addWaasSuiExtension/addWaasSuiExtension.d.ts +11 -0
- package/src/waas/addWaasSuiExtension/addWaasSuiExtension.d.ts.map +1 -0
- package/src/waas/addWaasSuiExtension/index.d.ts +2 -0
- package/src/waas/addWaasSuiExtension/index.d.ts.map +1 -0
- package/src/waas/utils/createWalletProviderForWaasSui/createWalletProviderForWaasSui.d.ts +4 -0
- package/src/waas/utils/createWalletProviderForWaasSui/createWalletProviderForWaasSui.d.ts.map +1 -0
- package/src/waas/utils/createWalletProviderForWaasSui/index.d.ts +2 -0
- package/src/waas/utils/createWalletProviderForWaasSui/index.d.ts.map +1 -0
- package/src/walletStandard/addSuiWalletStandardExtension/addSuiWalletStandardExtension.d.ts +11 -0
- package/src/walletStandard/addSuiWalletStandardExtension/addSuiWalletStandardExtension.d.ts.map +1 -0
- package/src/walletStandard/addSuiWalletStandardExtension/index.d.ts +2 -0
- package/src/walletStandard/addSuiWalletStandardExtension/index.d.ts.map +1 -0
- package/src/walletStandard/utils/createWalletProviderFromSuiStandardWallet/createWalletProviderFromSuiStandardWallet.d.ts +10 -0
- package/src/walletStandard/utils/createWalletProviderFromSuiStandardWallet/createWalletProviderFromSuiStandardWallet.d.ts.map +1 -0
- package/src/walletStandard/utils/createWalletProviderFromSuiStandardWallet/index.d.ts +2 -0
- package/src/walletStandard/utils/createWalletProviderFromSuiStandardWallet/index.d.ts.map +1 -0
- package/waas.cjs.d.ts +1 -0
- package/waas.cjs.js +14 -0
- package/waas.esm.d.ts +1 -0
- package/waas.esm.js +10 -0
- package/walletStandard.cjs.d.ts +1 -0
- package/walletStandard.cjs.js +15 -0
- package/walletStandard.esm.d.ts +1 -0
- package/walletStandard.esm.js +11 -0
- package/src/types/SuiClient.types.d.ts +0 -29
- package/src/types/SuiClient.types.d.ts.map +0 -1
- package/src/types/SuiWalletFeatures.types.d.ts +0 -32
- package/src/types/SuiWalletFeatures.types.d.ts.map +0 -1
- package/src/types/SuiWalletProvider.types.d.ts +0 -8
- package/src/types/SuiWalletProvider.types.d.ts.map +0 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@dynamic-labs-sdk/client/core');
|
|
4
|
+
var _extends = require('./_extends.cjs.js');
|
|
5
|
+
var client = require('@dynamic-labs-sdk/client');
|
|
6
|
+
var core$1 = require('@dynamic-labs-sdk/client/waas/core');
|
|
7
|
+
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
8
|
+
var client$1 = require('@mysten/sui/client');
|
|
9
|
+
|
|
10
|
+
const createWalletProviderForWaasSui = (sdkClient)=>{
|
|
11
|
+
const chain = 'SUI';
|
|
12
|
+
const walletProviderType = sdkApiCore.WalletProviderEnum.EmbeddedWallet;
|
|
13
|
+
const key = core.formatWalletProviderKey({
|
|
14
|
+
chain,
|
|
15
|
+
displayName: core$1.DYNAMIC_WAAS_METADATA.displayName,
|
|
16
|
+
walletProviderType
|
|
17
|
+
});
|
|
18
|
+
const waasProvider = core$1.createWaasProvider({
|
|
19
|
+
chain,
|
|
20
|
+
sdkClient
|
|
21
|
+
});
|
|
22
|
+
const getActiveNetworkId = async ()=>core.getActiveNetworkIdFromLastKnownRegistry({
|
|
23
|
+
client: sdkClient,
|
|
24
|
+
walletProviderKey: key
|
|
25
|
+
});
|
|
26
|
+
const getSuiClient = async ({ walletAccount })=>{
|
|
27
|
+
var _activeNetworkData_networkData;
|
|
28
|
+
const activeNetworkData = await client.getActiveNetworkData({
|
|
29
|
+
walletAccount
|
|
30
|
+
}, sdkClient);
|
|
31
|
+
core.assertDefined(activeNetworkData, 'No active network data found');
|
|
32
|
+
const url = (_activeNetworkData_networkData = activeNetworkData.networkData) == null ? void 0 : _activeNetworkData_networkData.rpcUrls.http[0];
|
|
33
|
+
core.assertDefined(url, 'No RPC URL found for active network');
|
|
34
|
+
return new client$1.SuiClient({
|
|
35
|
+
url
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
const switchActiveNetwork = async ({ networkId })=>core.switchActiveNetworkInLastKnownRegistry({
|
|
39
|
+
client: sdkClient,
|
|
40
|
+
networkId,
|
|
41
|
+
walletProviderKey: key
|
|
42
|
+
});
|
|
43
|
+
const getConnectedAddresses = async ()=>{
|
|
44
|
+
const waasSolanaAddresses = core$1.getAllUserWaasAddressesForChain({
|
|
45
|
+
chain
|
|
46
|
+
}, sdkClient);
|
|
47
|
+
return {
|
|
48
|
+
addresses: waasSolanaAddresses
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
const signAndExecuteTransaction = async ({ transaction, walletAccount })=>{
|
|
52
|
+
var _response_effects;
|
|
53
|
+
const { bytes, signature } = await signTransaction({
|
|
54
|
+
transaction,
|
|
55
|
+
walletAccount
|
|
56
|
+
});
|
|
57
|
+
const suiClient = await getSuiClient({
|
|
58
|
+
walletAccount
|
|
59
|
+
});
|
|
60
|
+
const response = await suiClient.executeTransactionBlock({
|
|
61
|
+
signature,
|
|
62
|
+
transactionBlock: bytes
|
|
63
|
+
});
|
|
64
|
+
var _response_effects_toString;
|
|
65
|
+
return _extends._extends({}, response, {
|
|
66
|
+
bytes,
|
|
67
|
+
effects: (_response_effects_toString = (_response_effects = response.effects) == null ? void 0 : _response_effects.toString()) != null ? _response_effects_toString : '',
|
|
68
|
+
signature
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const signTransaction = async ({ transaction, walletAccount })=>{
|
|
72
|
+
const suiClient = await getSuiClient({
|
|
73
|
+
walletAccount
|
|
74
|
+
});
|
|
75
|
+
const txBytes = await transaction.build({
|
|
76
|
+
client: suiClient
|
|
77
|
+
});
|
|
78
|
+
const txBytesBase64 = core.getBuffer().from(txBytes).toString('base64');
|
|
79
|
+
const txString = core.getBuffer().from(txBytes).toString('hex');
|
|
80
|
+
const { signature } = await waasProvider.signSerializedTransaction({
|
|
81
|
+
serializedTransaction: txString,
|
|
82
|
+
walletAccount
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
bytes: txBytesBase64,
|
|
86
|
+
signature
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
const signMessage = async ({ message, walletAccount })=>{
|
|
90
|
+
core.assertDefined(walletAccount, 'Wallet account is required');
|
|
91
|
+
return waasProvider.signMessage({
|
|
92
|
+
message,
|
|
93
|
+
walletAccount
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
return _extends._extends({}, waasProvider, {
|
|
97
|
+
chain,
|
|
98
|
+
getActiveNetworkId,
|
|
99
|
+
getConnectedAddresses,
|
|
100
|
+
getSuiClient,
|
|
101
|
+
groupKey: core.formatWalletProviderGroupKey(core$1.DYNAMIC_WAAS_METADATA.displayName),
|
|
102
|
+
key,
|
|
103
|
+
metadata: {
|
|
104
|
+
displayName: core$1.DYNAMIC_WAAS_METADATA.displayName,
|
|
105
|
+
icon: core$1.DYNAMIC_WAAS_METADATA.icon
|
|
106
|
+
},
|
|
107
|
+
signAndExecuteTransaction,
|
|
108
|
+
signMessage,
|
|
109
|
+
signTransaction,
|
|
110
|
+
switchActiveNetwork,
|
|
111
|
+
walletProviderType
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const WAAS_SUI_EXTENSION_KEY = 'waasSui';
|
|
116
|
+
/**
|
|
117
|
+
* Adds the Dynamic WaaS (Wallet as a Service) Sui extension to the Dynamic client.
|
|
118
|
+
*
|
|
119
|
+
* This extension enables embedded wallet functionality for Sui blockchain,
|
|
120
|
+
* allowing users to have wallets managed by Dynamic's infrastructure.
|
|
121
|
+
*
|
|
122
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
123
|
+
*/ const addWaasSuiExtension = (client = core.getDefaultClient())=>{
|
|
124
|
+
if (core.hasExtension({
|
|
125
|
+
extensionKey: WAAS_SUI_EXTENSION_KEY
|
|
126
|
+
}, client)) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
core.registerExtension({
|
|
130
|
+
extensionKey: WAAS_SUI_EXTENSION_KEY
|
|
131
|
+
}, client);
|
|
132
|
+
const walletProviderRegistry = core.getWalletProviderRegistry(client);
|
|
133
|
+
const walletProvider = createWalletProviderForWaasSui(client);
|
|
134
|
+
walletProviderRegistry.register({
|
|
135
|
+
priority: core.WalletProviderPriority.WALLET_SDK,
|
|
136
|
+
walletProvider
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
exports.addWaasSuiExtension = addWaasSuiExtension;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { formatWalletProviderKey, formatWalletProviderGroupKey, switchActiveNetworkInLastKnownRegistry, getActiveNetworkIdFromLastKnownRegistry, getBuffer, assertDefined, getDefaultClient, hasExtension, registerExtension, getWalletProviderRegistry, WalletProviderPriority } from '@dynamic-labs-sdk/client/core';
|
|
2
|
+
import { _ as _extends } from './_extends.esm.js';
|
|
3
|
+
import { getActiveNetworkData } from '@dynamic-labs-sdk/client';
|
|
4
|
+
import { DYNAMIC_WAAS_METADATA, createWaasProvider, getAllUserWaasAddressesForChain } from '@dynamic-labs-sdk/client/waas/core';
|
|
5
|
+
import { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';
|
|
6
|
+
import { SuiClient } from '@mysten/sui/client';
|
|
7
|
+
|
|
8
|
+
const createWalletProviderForWaasSui = (sdkClient)=>{
|
|
9
|
+
const chain = 'SUI';
|
|
10
|
+
const walletProviderType = WalletProviderEnum.EmbeddedWallet;
|
|
11
|
+
const key = formatWalletProviderKey({
|
|
12
|
+
chain,
|
|
13
|
+
displayName: DYNAMIC_WAAS_METADATA.displayName,
|
|
14
|
+
walletProviderType
|
|
15
|
+
});
|
|
16
|
+
const waasProvider = createWaasProvider({
|
|
17
|
+
chain,
|
|
18
|
+
sdkClient
|
|
19
|
+
});
|
|
20
|
+
const getActiveNetworkId = async ()=>getActiveNetworkIdFromLastKnownRegistry({
|
|
21
|
+
client: sdkClient,
|
|
22
|
+
walletProviderKey: key
|
|
23
|
+
});
|
|
24
|
+
const getSuiClient = async ({ walletAccount })=>{
|
|
25
|
+
var _activeNetworkData_networkData;
|
|
26
|
+
const activeNetworkData = await getActiveNetworkData({
|
|
27
|
+
walletAccount
|
|
28
|
+
}, sdkClient);
|
|
29
|
+
assertDefined(activeNetworkData, 'No active network data found');
|
|
30
|
+
const url = (_activeNetworkData_networkData = activeNetworkData.networkData) == null ? void 0 : _activeNetworkData_networkData.rpcUrls.http[0];
|
|
31
|
+
assertDefined(url, 'No RPC URL found for active network');
|
|
32
|
+
return new SuiClient({
|
|
33
|
+
url
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
const switchActiveNetwork = async ({ networkId })=>switchActiveNetworkInLastKnownRegistry({
|
|
37
|
+
client: sdkClient,
|
|
38
|
+
networkId,
|
|
39
|
+
walletProviderKey: key
|
|
40
|
+
});
|
|
41
|
+
const getConnectedAddresses = async ()=>{
|
|
42
|
+
const waasSolanaAddresses = getAllUserWaasAddressesForChain({
|
|
43
|
+
chain
|
|
44
|
+
}, sdkClient);
|
|
45
|
+
return {
|
|
46
|
+
addresses: waasSolanaAddresses
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const signAndExecuteTransaction = async ({ transaction, walletAccount })=>{
|
|
50
|
+
var _response_effects;
|
|
51
|
+
const { bytes, signature } = await signTransaction({
|
|
52
|
+
transaction,
|
|
53
|
+
walletAccount
|
|
54
|
+
});
|
|
55
|
+
const suiClient = await getSuiClient({
|
|
56
|
+
walletAccount
|
|
57
|
+
});
|
|
58
|
+
const response = await suiClient.executeTransactionBlock({
|
|
59
|
+
signature,
|
|
60
|
+
transactionBlock: bytes
|
|
61
|
+
});
|
|
62
|
+
var _response_effects_toString;
|
|
63
|
+
return _extends({}, response, {
|
|
64
|
+
bytes,
|
|
65
|
+
effects: (_response_effects_toString = (_response_effects = response.effects) == null ? void 0 : _response_effects.toString()) != null ? _response_effects_toString : '',
|
|
66
|
+
signature
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
const signTransaction = async ({ transaction, walletAccount })=>{
|
|
70
|
+
const suiClient = await getSuiClient({
|
|
71
|
+
walletAccount
|
|
72
|
+
});
|
|
73
|
+
const txBytes = await transaction.build({
|
|
74
|
+
client: suiClient
|
|
75
|
+
});
|
|
76
|
+
const txBytesBase64 = getBuffer().from(txBytes).toString('base64');
|
|
77
|
+
const txString = getBuffer().from(txBytes).toString('hex');
|
|
78
|
+
const { signature } = await waasProvider.signSerializedTransaction({
|
|
79
|
+
serializedTransaction: txString,
|
|
80
|
+
walletAccount
|
|
81
|
+
});
|
|
82
|
+
return {
|
|
83
|
+
bytes: txBytesBase64,
|
|
84
|
+
signature
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
const signMessage = async ({ message, walletAccount })=>{
|
|
88
|
+
assertDefined(walletAccount, 'Wallet account is required');
|
|
89
|
+
return waasProvider.signMessage({
|
|
90
|
+
message,
|
|
91
|
+
walletAccount
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
return _extends({}, waasProvider, {
|
|
95
|
+
chain,
|
|
96
|
+
getActiveNetworkId,
|
|
97
|
+
getConnectedAddresses,
|
|
98
|
+
getSuiClient,
|
|
99
|
+
groupKey: formatWalletProviderGroupKey(DYNAMIC_WAAS_METADATA.displayName),
|
|
100
|
+
key,
|
|
101
|
+
metadata: {
|
|
102
|
+
displayName: DYNAMIC_WAAS_METADATA.displayName,
|
|
103
|
+
icon: DYNAMIC_WAAS_METADATA.icon
|
|
104
|
+
},
|
|
105
|
+
signAndExecuteTransaction,
|
|
106
|
+
signMessage,
|
|
107
|
+
signTransaction,
|
|
108
|
+
switchActiveNetwork,
|
|
109
|
+
walletProviderType
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const WAAS_SUI_EXTENSION_KEY = 'waasSui';
|
|
114
|
+
/**
|
|
115
|
+
* Adds the Dynamic WaaS (Wallet as a Service) Sui extension to the Dynamic client.
|
|
116
|
+
*
|
|
117
|
+
* This extension enables embedded wallet functionality for Sui blockchain,
|
|
118
|
+
* allowing users to have wallets managed by Dynamic's infrastructure.
|
|
119
|
+
*
|
|
120
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
121
|
+
*/ const addWaasSuiExtension = (client = getDefaultClient())=>{
|
|
122
|
+
if (hasExtension({
|
|
123
|
+
extensionKey: WAAS_SUI_EXTENSION_KEY
|
|
124
|
+
}, client)) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
registerExtension({
|
|
128
|
+
extensionKey: WAAS_SUI_EXTENSION_KEY
|
|
129
|
+
}, client);
|
|
130
|
+
const walletProviderRegistry = getWalletProviderRegistry(client);
|
|
131
|
+
const walletProvider = createWalletProviderForWaasSui(client);
|
|
132
|
+
walletProviderRegistry.register({
|
|
133
|
+
priority: WalletProviderPriority.WALLET_SDK,
|
|
134
|
+
walletProvider
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export { addWaasSuiExtension as a };
|
package/index.cjs.js
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var assertPackageVersion = require('@dynamic-labs-sdk/assert-package-version');
|
|
4
|
-
var
|
|
5
|
-
var client = require('@dynamic-labs-sdk/client');
|
|
4
|
+
var _extends = require('./_extends.cjs.js');
|
|
6
5
|
var core = require('@dynamic-labs-sdk/client/core');
|
|
6
|
+
var addWaasSuiExtension = require('./addWaasSuiExtension.cjs.js');
|
|
7
|
+
var addSuiWalletStandardExtension = require('./addSuiWalletStandardExtension.cjs.js');
|
|
8
|
+
var client = require('@dynamic-labs-sdk/client');
|
|
9
|
+
require('@dynamic-labs-sdk/client/waas/core');
|
|
10
|
+
require('@dynamic-labs/sdk-api-core');
|
|
11
|
+
require('@mysten/sui/client');
|
|
12
|
+
require('@mysten/wallet-standard');
|
|
13
|
+
require('@mysten/sui/utils');
|
|
7
14
|
|
|
8
|
-
|
|
9
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Adds the Sui extension to the Dynamic client.
|
|
17
|
+
*
|
|
18
|
+
* This is a convenience function that adds both the Sui Wallet Standard extension
|
|
19
|
+
* and the Dynamic WaaS Sui extension, enabling support for all Sui wallet types
|
|
20
|
+
* including standard wallets and embedded wallets managed by Dynamic's infrastructure.
|
|
21
|
+
*
|
|
22
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
23
|
+
*/ const addSuiExtension = (client = core.getDefaultClient())=>{
|
|
24
|
+
addSuiWalletStandardExtension.addSuiWalletStandardExtension(client);
|
|
25
|
+
addWaasSuiExtension.addWaasSuiExtension(client);
|
|
26
|
+
};
|
|
10
27
|
|
|
11
28
|
class NotSuiProviderError extends client.BaseError {
|
|
12
29
|
constructor(params){
|
|
@@ -15,16 +32,13 @@ class NotSuiProviderError extends client.BaseError {
|
|
|
15
32
|
code: 'not_sui_provider_error',
|
|
16
33
|
docsUrl: null,
|
|
17
34
|
name: 'NotSuiProviderError',
|
|
18
|
-
shortMessage: 'Provider is not a
|
|
35
|
+
shortMessage: 'Provider is not a Sui wallet provider'
|
|
19
36
|
});
|
|
20
37
|
this.providerKey = params.providerKey;
|
|
21
38
|
}
|
|
22
39
|
}
|
|
23
40
|
|
|
24
|
-
|
|
25
|
-
* Type guard utility to check if a WalletProvider is a SUI wallet provider.
|
|
26
|
-
* Returns true if the provider's chain is 'SUI'.
|
|
27
|
-
*/ const isSuiWalletProvider = (provider)=>{
|
|
41
|
+
const isSuiWalletProvider = (provider)=>{
|
|
28
42
|
return provider.chain === 'SUI';
|
|
29
43
|
};
|
|
30
44
|
|
|
@@ -44,24 +58,136 @@ class NotSuiProviderError extends client.BaseError {
|
|
|
44
58
|
providerKey: provider.key
|
|
45
59
|
});
|
|
46
60
|
}
|
|
47
|
-
return provider.getSuiClient(
|
|
61
|
+
return provider.getSuiClient({
|
|
62
|
+
walletAccount
|
|
63
|
+
});
|
|
48
64
|
};
|
|
49
65
|
|
|
50
66
|
/**
|
|
51
|
-
* Type guard
|
|
67
|
+
* Type guard function to check if a network provider is a Sui network provider.
|
|
52
68
|
*
|
|
53
|
-
* @param
|
|
54
|
-
* @returns True if the
|
|
55
|
-
*/ const
|
|
56
|
-
|
|
69
|
+
* @param networkProvider - The network provider to check.
|
|
70
|
+
* @returns True if the network provider is a Sui network provider, false otherwise.
|
|
71
|
+
*/ const isSuiNetworkProvider = (networkProvider)=>networkProvider.chain === 'SUI';
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Type guard function to check if a wallet account is a Sui wallet account.
|
|
75
|
+
*
|
|
76
|
+
* @param walletAccount - The wallet account to check.
|
|
77
|
+
* @returns True if the wallet account is a Sui wallet account, false otherwise.
|
|
78
|
+
*/ const isSuiWalletAccount = (walletAccount)=>walletAccount.chain === 'SUI';
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Signs and executes a Sui transaction
|
|
82
|
+
* @param params.transaction - The transaction to sign and execute
|
|
83
|
+
* @param params.walletAccount - The wallet account to sign the transaction with
|
|
84
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
85
|
+
* @returns An object containing the signature and transaction bytes
|
|
86
|
+
*/ const signAndExecuteTransaction = async ({ walletAccount, transaction }, client$1 = client.getDefaultClient())=>{
|
|
87
|
+
const provider = core.getWalletProviderFromWalletAccount({
|
|
88
|
+
walletAccount
|
|
89
|
+
}, client$1);
|
|
90
|
+
if (!isSuiWalletProvider(provider)) {
|
|
91
|
+
throw new NotSuiProviderError({
|
|
92
|
+
providerKey: provider.key
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
transaction.setSender(walletAccount.address);
|
|
96
|
+
return provider.signAndExecuteTransaction({
|
|
97
|
+
transaction,
|
|
98
|
+
walletAccount
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @deprecated Use signAndExecuteTransaction instead
|
|
104
|
+
*
|
|
105
|
+
* Signs and executes a Sui transaction block
|
|
106
|
+
*
|
|
107
|
+
* @param params.transactionBlock - The transaction block to sign and execute
|
|
108
|
+
* @param params.walletAccount - The wallet account to sign the transaction with
|
|
109
|
+
* @param [params.options] - The fields to return in the execution response (e.g., transaction, effects, events, etc).
|
|
110
|
+
* By default, only the transaction digest will be returned.
|
|
111
|
+
* @param [params.requestType] - The request type to use for the transaction execution
|
|
112
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
113
|
+
* @returns An object containing signature result
|
|
114
|
+
*/ const signAndExecuteTransactionBlock = async ({ walletAccount, transactionBlock, options, requestType }, client$1 = client.getDefaultClient())=>{
|
|
115
|
+
const provider = core.getWalletProviderFromWalletAccount({
|
|
116
|
+
walletAccount
|
|
117
|
+
}, client$1);
|
|
118
|
+
if (!isSuiWalletProvider(provider)) {
|
|
119
|
+
throw new NotSuiProviderError({
|
|
120
|
+
providerKey: provider.key
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (!provider.signAndExecuteTransactionBlock) {
|
|
124
|
+
throw new core.MethodNotImplementedError('signAndExecuteTransactionBlock');
|
|
125
|
+
}
|
|
126
|
+
transactionBlock.setSender(walletAccount.address);
|
|
127
|
+
return provider.signAndExecuteTransactionBlock({
|
|
128
|
+
options,
|
|
129
|
+
requestType,
|
|
130
|
+
transactionBlock,
|
|
131
|
+
walletAccount
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Signs a Sui transaction
|
|
137
|
+
* @param params.transaction - The transaction to sign
|
|
138
|
+
* @param params.walletAccount - The wallet account to sign the transaction with
|
|
139
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
140
|
+
* @returns An object containing the signature and transaction bytes
|
|
141
|
+
*/ const signTransaction = async ({ walletAccount, transaction }, client$1 = client.getDefaultClient())=>{
|
|
142
|
+
const provider = core.getWalletProviderFromWalletAccount({
|
|
143
|
+
walletAccount
|
|
144
|
+
}, client$1);
|
|
145
|
+
if (!isSuiWalletProvider(provider)) {
|
|
146
|
+
throw new NotSuiProviderError({
|
|
147
|
+
providerKey: provider.key
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return provider.signTransaction({
|
|
151
|
+
transaction,
|
|
152
|
+
walletAccount
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @deprecated Use signTransaction instead
|
|
158
|
+
*
|
|
159
|
+
* Signs a Sui transaction block
|
|
160
|
+
*
|
|
161
|
+
* @param params.transactionBlock - The transaction block to sign
|
|
162
|
+
* @param params.walletAccount - The wallet account to sign the transaction with
|
|
163
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
164
|
+
* @returns An object containing the signature and transaction block bytes
|
|
165
|
+
*/ const signTransactionBlock = async ({ walletAccount, transactionBlock }, client$1 = client.getDefaultClient())=>{
|
|
166
|
+
const provider = core.getWalletProviderFromWalletAccount({
|
|
167
|
+
walletAccount
|
|
168
|
+
}, client$1);
|
|
169
|
+
if (!isSuiWalletProvider(provider)) {
|
|
170
|
+
throw new NotSuiProviderError({
|
|
171
|
+
providerKey: provider.key
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
if (!provider.signTransactionBlock) {
|
|
175
|
+
throw new core.MethodNotImplementedError('signTransactionBlock');
|
|
176
|
+
}
|
|
177
|
+
return provider.signTransactionBlock({
|
|
178
|
+
transactionBlock,
|
|
179
|
+
walletAccount
|
|
180
|
+
});
|
|
57
181
|
};
|
|
58
182
|
|
|
59
|
-
assertPackageVersion.assertPackageVersion(name, version);
|
|
183
|
+
assertPackageVersion.assertPackageVersion(_extends.name, _extends.version);
|
|
60
184
|
|
|
61
|
-
Object.defineProperty(exports, "WalletProviderEnum", {
|
|
62
|
-
enumerable: true,
|
|
63
|
-
get: function () { return sdkApiCore.WalletProviderEnum; }
|
|
64
|
-
});
|
|
65
185
|
exports.NotSuiProviderError = NotSuiProviderError;
|
|
186
|
+
exports.addSuiExtension = addSuiExtension;
|
|
66
187
|
exports.getSuiClient = getSuiClient;
|
|
188
|
+
exports.isSuiNetworkProvider = isSuiNetworkProvider;
|
|
67
189
|
exports.isSuiWalletAccount = isSuiWalletAccount;
|
|
190
|
+
exports.signAndExecuteTransaction = signAndExecuteTransaction;
|
|
191
|
+
exports.signAndExecuteTransactionBlock = signAndExecuteTransactionBlock;
|
|
192
|
+
exports.signTransaction = signTransaction;
|
|
193
|
+
exports.signTransactionBlock = signTransactionBlock;
|
package/index.esm.js
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { n as name, v as version } from './_extends.esm.js';
|
|
3
|
+
import { getDefaultClient, getWalletProviderFromWalletAccount, MethodNotImplementedError } from '@dynamic-labs-sdk/client/core';
|
|
4
|
+
import { a as addWaasSuiExtension } from './addWaasSuiExtension.esm.js';
|
|
5
|
+
import { a as addSuiWalletStandardExtension } from './addSuiWalletStandardExtension.esm.js';
|
|
6
|
+
import { BaseError, getDefaultClient as getDefaultClient$1 } from '@dynamic-labs-sdk/client';
|
|
7
|
+
import '@dynamic-labs-sdk/client/waas/core';
|
|
8
|
+
import '@dynamic-labs/sdk-api-core';
|
|
9
|
+
import '@mysten/sui/client';
|
|
10
|
+
import '@mysten/wallet-standard';
|
|
11
|
+
import '@mysten/sui/utils';
|
|
5
12
|
|
|
6
|
-
|
|
7
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Adds the Sui extension to the Dynamic client.
|
|
15
|
+
*
|
|
16
|
+
* This is a convenience function that adds both the Sui Wallet Standard extension
|
|
17
|
+
* and the Dynamic WaaS Sui extension, enabling support for all Sui wallet types
|
|
18
|
+
* including standard wallets and embedded wallets managed by Dynamic's infrastructure.
|
|
19
|
+
*
|
|
20
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
21
|
+
*/ const addSuiExtension = (client = getDefaultClient())=>{
|
|
22
|
+
addSuiWalletStandardExtension(client);
|
|
23
|
+
addWaasSuiExtension(client);
|
|
24
|
+
};
|
|
8
25
|
|
|
9
26
|
class NotSuiProviderError extends BaseError {
|
|
10
27
|
constructor(params){
|
|
@@ -13,16 +30,13 @@ class NotSuiProviderError extends BaseError {
|
|
|
13
30
|
code: 'not_sui_provider_error',
|
|
14
31
|
docsUrl: null,
|
|
15
32
|
name: 'NotSuiProviderError',
|
|
16
|
-
shortMessage: 'Provider is not a
|
|
33
|
+
shortMessage: 'Provider is not a Sui wallet provider'
|
|
17
34
|
});
|
|
18
35
|
this.providerKey = params.providerKey;
|
|
19
36
|
}
|
|
20
37
|
}
|
|
21
38
|
|
|
22
|
-
|
|
23
|
-
* Type guard utility to check if a WalletProvider is a SUI wallet provider.
|
|
24
|
-
* Returns true if the provider's chain is 'SUI'.
|
|
25
|
-
*/ const isSuiWalletProvider = (provider)=>{
|
|
39
|
+
const isSuiWalletProvider = (provider)=>{
|
|
26
40
|
return provider.chain === 'SUI';
|
|
27
41
|
};
|
|
28
42
|
|
|
@@ -42,18 +56,128 @@ class NotSuiProviderError extends BaseError {
|
|
|
42
56
|
providerKey: provider.key
|
|
43
57
|
});
|
|
44
58
|
}
|
|
45
|
-
return provider.getSuiClient(
|
|
59
|
+
return provider.getSuiClient({
|
|
60
|
+
walletAccount
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Type guard function to check if a network provider is a Sui network provider.
|
|
66
|
+
*
|
|
67
|
+
* @param networkProvider - The network provider to check.
|
|
68
|
+
* @returns True if the network provider is a Sui network provider, false otherwise.
|
|
69
|
+
*/ const isSuiNetworkProvider = (networkProvider)=>networkProvider.chain === 'SUI';
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Type guard function to check if a wallet account is a Sui wallet account.
|
|
73
|
+
*
|
|
74
|
+
* @param walletAccount - The wallet account to check.
|
|
75
|
+
* @returns True if the wallet account is a Sui wallet account, false otherwise.
|
|
76
|
+
*/ const isSuiWalletAccount = (walletAccount)=>walletAccount.chain === 'SUI';
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Signs and executes a Sui transaction
|
|
80
|
+
* @param params.transaction - The transaction to sign and execute
|
|
81
|
+
* @param params.walletAccount - The wallet account to sign the transaction with
|
|
82
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
83
|
+
* @returns An object containing the signature and transaction bytes
|
|
84
|
+
*/ const signAndExecuteTransaction = async ({ walletAccount, transaction }, client = getDefaultClient$1())=>{
|
|
85
|
+
const provider = getWalletProviderFromWalletAccount({
|
|
86
|
+
walletAccount
|
|
87
|
+
}, client);
|
|
88
|
+
if (!isSuiWalletProvider(provider)) {
|
|
89
|
+
throw new NotSuiProviderError({
|
|
90
|
+
providerKey: provider.key
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
transaction.setSender(walletAccount.address);
|
|
94
|
+
return provider.signAndExecuteTransaction({
|
|
95
|
+
transaction,
|
|
96
|
+
walletAccount
|
|
97
|
+
});
|
|
46
98
|
};
|
|
47
99
|
|
|
48
100
|
/**
|
|
49
|
-
*
|
|
101
|
+
* @deprecated Use signAndExecuteTransaction instead
|
|
50
102
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
|
|
54
|
-
|
|
103
|
+
* Signs and executes a Sui transaction block
|
|
104
|
+
*
|
|
105
|
+
* @param params.transactionBlock - The transaction block to sign and execute
|
|
106
|
+
* @param params.walletAccount - The wallet account to sign the transaction with
|
|
107
|
+
* @param [params.options] - The fields to return in the execution response (e.g., transaction, effects, events, etc).
|
|
108
|
+
* By default, only the transaction digest will be returned.
|
|
109
|
+
* @param [params.requestType] - The request type to use for the transaction execution
|
|
110
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
111
|
+
* @returns An object containing signature result
|
|
112
|
+
*/ const signAndExecuteTransactionBlock = async ({ walletAccount, transactionBlock, options, requestType }, client = getDefaultClient$1())=>{
|
|
113
|
+
const provider = getWalletProviderFromWalletAccount({
|
|
114
|
+
walletAccount
|
|
115
|
+
}, client);
|
|
116
|
+
if (!isSuiWalletProvider(provider)) {
|
|
117
|
+
throw new NotSuiProviderError({
|
|
118
|
+
providerKey: provider.key
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (!provider.signAndExecuteTransactionBlock) {
|
|
122
|
+
throw new MethodNotImplementedError('signAndExecuteTransactionBlock');
|
|
123
|
+
}
|
|
124
|
+
transactionBlock.setSender(walletAccount.address);
|
|
125
|
+
return provider.signAndExecuteTransactionBlock({
|
|
126
|
+
options,
|
|
127
|
+
requestType,
|
|
128
|
+
transactionBlock,
|
|
129
|
+
walletAccount
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Signs a Sui transaction
|
|
135
|
+
* @param params.transaction - The transaction to sign
|
|
136
|
+
* @param params.walletAccount - The wallet account to sign the transaction with
|
|
137
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
138
|
+
* @returns An object containing the signature and transaction bytes
|
|
139
|
+
*/ const signTransaction = async ({ walletAccount, transaction }, client = getDefaultClient$1())=>{
|
|
140
|
+
const provider = getWalletProviderFromWalletAccount({
|
|
141
|
+
walletAccount
|
|
142
|
+
}, client);
|
|
143
|
+
if (!isSuiWalletProvider(provider)) {
|
|
144
|
+
throw new NotSuiProviderError({
|
|
145
|
+
providerKey: provider.key
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return provider.signTransaction({
|
|
149
|
+
transaction,
|
|
150
|
+
walletAccount
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @deprecated Use signTransaction instead
|
|
156
|
+
*
|
|
157
|
+
* Signs a Sui transaction block
|
|
158
|
+
*
|
|
159
|
+
* @param params.transactionBlock - The transaction block to sign
|
|
160
|
+
* @param params.walletAccount - The wallet account to sign the transaction with
|
|
161
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
162
|
+
* @returns An object containing the signature and transaction block bytes
|
|
163
|
+
*/ const signTransactionBlock = async ({ walletAccount, transactionBlock }, client = getDefaultClient$1())=>{
|
|
164
|
+
const provider = getWalletProviderFromWalletAccount({
|
|
165
|
+
walletAccount
|
|
166
|
+
}, client);
|
|
167
|
+
if (!isSuiWalletProvider(provider)) {
|
|
168
|
+
throw new NotSuiProviderError({
|
|
169
|
+
providerKey: provider.key
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
if (!provider.signTransactionBlock) {
|
|
173
|
+
throw new MethodNotImplementedError('signTransactionBlock');
|
|
174
|
+
}
|
|
175
|
+
return provider.signTransactionBlock({
|
|
176
|
+
transactionBlock,
|
|
177
|
+
walletAccount
|
|
178
|
+
});
|
|
55
179
|
};
|
|
56
180
|
|
|
57
181
|
assertPackageVersion(name, version);
|
|
58
182
|
|
|
59
|
-
export { NotSuiProviderError, getSuiClient, isSuiWalletAccount };
|
|
183
|
+
export { NotSuiProviderError, addSuiExtension, getSuiClient, isSuiNetworkProvider, isSuiWalletAccount, signAndExecuteTransaction, signAndExecuteTransactionBlock, signTransaction, signTransactionBlock };
|