@dynamic-labs/sui 4.9.6
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 +5162 -0
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/_virtual/_tslib.cjs +36 -0
- package/_virtual/_tslib.js +32 -0
- package/package.cjs +8 -0
- package/package.js +4 -0
- package/package.json +32 -0
- package/src/SuiWalletConnector.cjs +142 -0
- package/src/SuiWalletConnector.d.ts +33 -0
- package/src/SuiWalletConnector.js +138 -0
- package/src/index.cjs +18 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +13 -0
- package/src/types.d.ts +12 -0
- package/src/wallet/SuiWallet.cjs +25 -0
- package/src/wallet/SuiWallet.d.ts +11 -0
- package/src/wallet/SuiWallet.js +21 -0
- package/src/wallet/index.d.ts +1 -0
- package/src/wallets/injected/fetchSuiInjectedWalletConnectors.cjs +28 -0
- package/src/wallets/injected/fetchSuiInjectedWalletConnectors.d.ts +2 -0
- package/src/wallets/injected/fetchSuiInjectedWalletConnectors.js +24 -0
- package/src/wallets/injected/index.d.ts +1 -0
- package/src/wallets/injected/injected.cjs +18 -0
- package/src/wallets/injected/injected.d.ts +6 -0
- package/src/wallets/injected/injected.js +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Dynamic Labs, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# SUI Package
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
/******************************************************************************
|
|
7
|
+
Copyright (c) Microsoft Corporation.
|
|
8
|
+
|
|
9
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
+
purpose with or without fee is hereby granted.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
+
***************************************************************************** */
|
|
20
|
+
|
|
21
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
32
|
+
var e = new Error(message);
|
|
33
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.__awaiter = __awaiter;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
/******************************************************************************
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
9
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
10
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
11
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
12
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
+
***************************************************************************** */
|
|
16
|
+
|
|
17
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
28
|
+
var e = new Error(message);
|
|
29
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { __awaiter };
|
package/package.cjs
ADDED
package/package.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dynamic-labs/sui",
|
|
3
|
+
"version": "4.9.6",
|
|
4
|
+
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
5
|
+
"author": "Dynamic Labs, Inc.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./src/index.cjs",
|
|
8
|
+
"module": "./src/index.js",
|
|
9
|
+
"types": "./src/index.d.ts",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./src/index.d.ts",
|
|
14
|
+
"import": "./src/index.js",
|
|
15
|
+
"require": "./src/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://www.dynamic.xyz/",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@dynamic-labs/sdk-api-core": "0.0.644",
|
|
22
|
+
"@mysten/wallet-standard": "0.13.29",
|
|
23
|
+
"text-encoding": "0.7.0",
|
|
24
|
+
"@dynamic-labs/assert-package-version": "4.9.6",
|
|
25
|
+
"@dynamic-labs/logger": "4.9.6",
|
|
26
|
+
"@dynamic-labs/rpc-providers": "4.9.6",
|
|
27
|
+
"@dynamic-labs/utils": "4.9.6",
|
|
28
|
+
"@dynamic-labs/wallet-book": "4.9.6",
|
|
29
|
+
"@dynamic-labs/wallet-connector-core": "4.9.6"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {}
|
|
32
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../_virtual/_tslib.cjs');
|
|
7
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
+
var utils = require('@dynamic-labs/utils');
|
|
9
|
+
var logger = require('@dynamic-labs/logger');
|
|
10
|
+
var SuiWallet = require('./wallet/SuiWallet.cjs');
|
|
11
|
+
|
|
12
|
+
class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
13
|
+
constructor(name, opts) {
|
|
14
|
+
super(opts);
|
|
15
|
+
this.name = 'Sui';
|
|
16
|
+
this.ChainWallet = SuiWallet.SuiWallet;
|
|
17
|
+
this.connectedChain = 'SUI';
|
|
18
|
+
this.supportedChains = ['SUI'];
|
|
19
|
+
/** required for metamask snap integration as MM snaps don't have event listeners */
|
|
20
|
+
this.canSetEventListeners = true;
|
|
21
|
+
this.name = name;
|
|
22
|
+
this.wallet = opts.wallet;
|
|
23
|
+
this.chainRpcProviders = opts.chainRpcProviders;
|
|
24
|
+
this.logger = new logger.Logger(this.name);
|
|
25
|
+
}
|
|
26
|
+
/** Helper to return the wallet features */
|
|
27
|
+
getFeatures() {
|
|
28
|
+
var _a;
|
|
29
|
+
return (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.features;
|
|
30
|
+
}
|
|
31
|
+
/** Connect to the wallet using the standard:connect feature */
|
|
32
|
+
connect() {
|
|
33
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
var _a;
|
|
35
|
+
if (this.account) {
|
|
36
|
+
// Account is already connected
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const connectFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['standard:connect'];
|
|
40
|
+
if (!connectFeature) {
|
|
41
|
+
throw new utils.DynamicError('Wallet does not support standard:connect');
|
|
42
|
+
}
|
|
43
|
+
this.logger.debug('[connect] Creating new connection');
|
|
44
|
+
try {
|
|
45
|
+
const response = yield connectFeature.connect();
|
|
46
|
+
this.logger.debug(`[connect] Connection returned accounts: ${response === null || response === void 0 ? void 0 : response.accounts.length}`);
|
|
47
|
+
this.account = response === null || response === void 0 ? void 0 : response.accounts[0];
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
this.logger.error(error);
|
|
51
|
+
throw new utils.DynamicError('Connection failed');
|
|
52
|
+
}
|
|
53
|
+
this.setupEventListeners();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/** Get the wallet address by connecting to the current account */
|
|
57
|
+
getAddress() {
|
|
58
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
this.logger.debug('[getAddress] called, attempting to obtain the account address');
|
|
60
|
+
yield this.connect();
|
|
61
|
+
if (!this.account) {
|
|
62
|
+
throw new utils.DynamicError('No account found');
|
|
63
|
+
}
|
|
64
|
+
return this.account.address;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
getNetwork() {
|
|
68
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
var _a;
|
|
70
|
+
if (!((_a = this.account) === null || _a === void 0 ? void 0 : _a.chains[0])) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
return this.account.chains[0];
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
getBalance(address) {
|
|
77
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
// Make RPC call to get balance
|
|
79
|
+
return address;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
signMessage(messageToSign) {
|
|
83
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
var _a;
|
|
85
|
+
this.logger.debug('[signMessage] called, attempting to sign a message');
|
|
86
|
+
const signFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['sui:signPersonalMessage'];
|
|
87
|
+
if (!signFeature) {
|
|
88
|
+
throw new utils.DynamicError('Wallet does not support sui:signPersonalMessage');
|
|
89
|
+
}
|
|
90
|
+
yield this.connect();
|
|
91
|
+
if (!this.account) {
|
|
92
|
+
throw new utils.DynamicError('[signMessage] No account found');
|
|
93
|
+
}
|
|
94
|
+
let output;
|
|
95
|
+
try {
|
|
96
|
+
output = yield signFeature.signPersonalMessage({
|
|
97
|
+
account: this.account,
|
|
98
|
+
message: new TextEncoder().encode(messageToSign),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
this.logger.error(error);
|
|
103
|
+
throw new utils.DynamicError('An error occured during signing');
|
|
104
|
+
}
|
|
105
|
+
if (!output || !output.signature) {
|
|
106
|
+
throw new utils.DynamicError('[signMessage] Failed to sign message');
|
|
107
|
+
}
|
|
108
|
+
this.logger.debug(`[signMessage] Signed message: ${output.signature}`);
|
|
109
|
+
return output.signature;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
getWalletAccount() {
|
|
113
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
return this.account;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
// Stub method
|
|
118
|
+
getProvider() {
|
|
119
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
return 'getProvider not implemented';
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
endSession() {
|
|
124
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
var _a;
|
|
126
|
+
this.teardownEventListeners();
|
|
127
|
+
this.account = undefined;
|
|
128
|
+
const disconnectFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['standard:disconnect'];
|
|
129
|
+
if (disconnectFeature) {
|
|
130
|
+
yield disconnectFeature.disconnect();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (this.wallet.disconnect) {
|
|
134
|
+
yield this.wallet.disconnect();
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
throw new utils.DynamicError('Wallet does not support disconnect');
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
exports.SuiWalletConnector = SuiWalletConnector;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SuiWalletFeatures, WalletAccount, WalletWithFeatures } from '@mysten/wallet-standard';
|
|
2
|
+
import { Chain, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { Logger } from '@dynamic-labs/logger';
|
|
4
|
+
import { SuiWallet } from './wallet/SuiWallet';
|
|
5
|
+
import { SuiWalletConnectorProps } from './types';
|
|
6
|
+
export declare abstract class SuiWalletConnector extends WalletConnectorBase<typeof SuiWallet> {
|
|
7
|
+
name: string;
|
|
8
|
+
ChainWallet: typeof SuiWallet;
|
|
9
|
+
connectedChain: Chain;
|
|
10
|
+
supportedChains: Chain[];
|
|
11
|
+
/** required for metamask snap integration as MM snaps don't have event listeners */
|
|
12
|
+
canSetEventListeners: boolean;
|
|
13
|
+
/** Sui wallet instance */
|
|
14
|
+
wallet: WalletWithFeatures<SuiWalletFeatures> | undefined;
|
|
15
|
+
/** Tracks the active wallet account */
|
|
16
|
+
protected account: WalletAccount | undefined;
|
|
17
|
+
/** Dynamic logger */
|
|
18
|
+
logger: Logger;
|
|
19
|
+
constructor(name: string, opts: SuiWalletConnectorProps);
|
|
20
|
+
/** Helper to return the wallet features */
|
|
21
|
+
protected getFeatures(): SuiWalletFeatures | undefined;
|
|
22
|
+
/** Connect to the wallet using the standard:connect feature */
|
|
23
|
+
connect(): Promise<void>;
|
|
24
|
+
/** Get the wallet address by connecting to the current account */
|
|
25
|
+
getAddress(): Promise<string | undefined>;
|
|
26
|
+
getNetwork(): Promise<`${string}:${string}` | undefined>;
|
|
27
|
+
getBalance(address: string): Promise<string | undefined>;
|
|
28
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
29
|
+
getWalletAccount(): Promise<WalletAccount | undefined>;
|
|
30
|
+
getProvider(): Promise<string>;
|
|
31
|
+
endSession(): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
export type SuiWalletConnectorType = SuiWalletConnector;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../_virtual/_tslib.js';
|
|
3
|
+
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
5
|
+
import { Logger } from '@dynamic-labs/logger';
|
|
6
|
+
import { SuiWallet } from './wallet/SuiWallet.js';
|
|
7
|
+
|
|
8
|
+
class SuiWalletConnector extends WalletConnectorBase {
|
|
9
|
+
constructor(name, opts) {
|
|
10
|
+
super(opts);
|
|
11
|
+
this.name = 'Sui';
|
|
12
|
+
this.ChainWallet = SuiWallet;
|
|
13
|
+
this.connectedChain = 'SUI';
|
|
14
|
+
this.supportedChains = ['SUI'];
|
|
15
|
+
/** required for metamask snap integration as MM snaps don't have event listeners */
|
|
16
|
+
this.canSetEventListeners = true;
|
|
17
|
+
this.name = name;
|
|
18
|
+
this.wallet = opts.wallet;
|
|
19
|
+
this.chainRpcProviders = opts.chainRpcProviders;
|
|
20
|
+
this.logger = new Logger(this.name);
|
|
21
|
+
}
|
|
22
|
+
/** Helper to return the wallet features */
|
|
23
|
+
getFeatures() {
|
|
24
|
+
var _a;
|
|
25
|
+
return (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.features;
|
|
26
|
+
}
|
|
27
|
+
/** Connect to the wallet using the standard:connect feature */
|
|
28
|
+
connect() {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
var _a;
|
|
31
|
+
if (this.account) {
|
|
32
|
+
// Account is already connected
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const connectFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['standard:connect'];
|
|
36
|
+
if (!connectFeature) {
|
|
37
|
+
throw new DynamicError('Wallet does not support standard:connect');
|
|
38
|
+
}
|
|
39
|
+
this.logger.debug('[connect] Creating new connection');
|
|
40
|
+
try {
|
|
41
|
+
const response = yield connectFeature.connect();
|
|
42
|
+
this.logger.debug(`[connect] Connection returned accounts: ${response === null || response === void 0 ? void 0 : response.accounts.length}`);
|
|
43
|
+
this.account = response === null || response === void 0 ? void 0 : response.accounts[0];
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
this.logger.error(error);
|
|
47
|
+
throw new DynamicError('Connection failed');
|
|
48
|
+
}
|
|
49
|
+
this.setupEventListeners();
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/** Get the wallet address by connecting to the current account */
|
|
53
|
+
getAddress() {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
this.logger.debug('[getAddress] called, attempting to obtain the account address');
|
|
56
|
+
yield this.connect();
|
|
57
|
+
if (!this.account) {
|
|
58
|
+
throw new DynamicError('No account found');
|
|
59
|
+
}
|
|
60
|
+
return this.account.address;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
getNetwork() {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
var _a;
|
|
66
|
+
if (!((_a = this.account) === null || _a === void 0 ? void 0 : _a.chains[0])) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
return this.account.chains[0];
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
getBalance(address) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
// Make RPC call to get balance
|
|
75
|
+
return address;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
signMessage(messageToSign) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
var _a;
|
|
81
|
+
this.logger.debug('[signMessage] called, attempting to sign a message');
|
|
82
|
+
const signFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['sui:signPersonalMessage'];
|
|
83
|
+
if (!signFeature) {
|
|
84
|
+
throw new DynamicError('Wallet does not support sui:signPersonalMessage');
|
|
85
|
+
}
|
|
86
|
+
yield this.connect();
|
|
87
|
+
if (!this.account) {
|
|
88
|
+
throw new DynamicError('[signMessage] No account found');
|
|
89
|
+
}
|
|
90
|
+
let output;
|
|
91
|
+
try {
|
|
92
|
+
output = yield signFeature.signPersonalMessage({
|
|
93
|
+
account: this.account,
|
|
94
|
+
message: new TextEncoder().encode(messageToSign),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
this.logger.error(error);
|
|
99
|
+
throw new DynamicError('An error occured during signing');
|
|
100
|
+
}
|
|
101
|
+
if (!output || !output.signature) {
|
|
102
|
+
throw new DynamicError('[signMessage] Failed to sign message');
|
|
103
|
+
}
|
|
104
|
+
this.logger.debug(`[signMessage] Signed message: ${output.signature}`);
|
|
105
|
+
return output.signature;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
getWalletAccount() {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
return this.account;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
// Stub method
|
|
114
|
+
getProvider() {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
return 'getProvider not implemented';
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
endSession() {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
var _a;
|
|
122
|
+
this.teardownEventListeners();
|
|
123
|
+
this.account = undefined;
|
|
124
|
+
const disconnectFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['standard:disconnect'];
|
|
125
|
+
if (disconnectFeature) {
|
|
126
|
+
yield disconnectFeature.disconnect();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (this.wallet.disconnect) {
|
|
130
|
+
yield this.wallet.disconnect();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
throw new DynamicError('Wallet does not support disconnect');
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export { SuiWalletConnector };
|
package/src/index.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var assertPackageVersion = require('@dynamic-labs/assert-package-version');
|
|
7
|
+
var _package = require('../package.cjs');
|
|
8
|
+
var fetchSuiInjectedWalletConnectors = require('./wallets/injected/fetchSuiInjectedWalletConnectors.cjs');
|
|
9
|
+
var SuiWalletConnector = require('./SuiWalletConnector.cjs');
|
|
10
|
+
|
|
11
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
12
|
+
assertPackageVersion.assertPackageVersion('@dynamic-labs/sui', _package.version);
|
|
13
|
+
const SuiWalletConnectors = () => [
|
|
14
|
+
...fetchSuiInjectedWalletConnectors.fetchSuiInjectedWalletConnectors(),
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
exports.SuiWalletConnector = SuiWalletConnector.SuiWalletConnector;
|
|
18
|
+
exports.SuiWalletConnectors = SuiWalletConnectors;
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
|
|
3
|
+
import { version } from '../package.js';
|
|
4
|
+
import { fetchSuiInjectedWalletConnectors } from './wallets/injected/fetchSuiInjectedWalletConnectors.js';
|
|
5
|
+
export { SuiWalletConnector } from './SuiWalletConnector.js';
|
|
6
|
+
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
8
|
+
assertPackageVersion('@dynamic-labs/sui', version);
|
|
9
|
+
const SuiWalletConnectors = () => [
|
|
10
|
+
...fetchSuiInjectedWalletConnectors(),
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
export { SuiWalletConnectors };
|
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WalletWithFeatures, SuiWalletFeatures } from '@mysten/wallet-standard';
|
|
2
|
+
import { IChainRpcProviders } from '@dynamic-labs/rpc-providers';
|
|
3
|
+
import { NetworkConfiguration } from '@dynamic-labs/sdk-api-core';
|
|
4
|
+
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
5
|
+
import { WalletMetadata } from '@dynamic-labs/wallet-connector-core';
|
|
6
|
+
export type SuiWalletConnectorProps = {
|
|
7
|
+
chainRpcProviders: IChainRpcProviders;
|
|
8
|
+
suiNetworks: NetworkConfiguration[];
|
|
9
|
+
walletBook: WalletBookSchema;
|
|
10
|
+
metadata?: WalletMetadata;
|
|
11
|
+
wallet: WalletWithFeatures<SuiWalletFeatures>;
|
|
12
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
+
|
|
9
|
+
class SuiWallet extends walletConnectorCore.Wallet {
|
|
10
|
+
/**
|
|
11
|
+
* Sends the native balance of the wallet to the given address.
|
|
12
|
+
* @param amount - The amount of balance
|
|
13
|
+
* @param toAddress - The address to send the balance to.
|
|
14
|
+
* @returns The signature of the sent transaction.
|
|
15
|
+
*/
|
|
16
|
+
sendBalance() {
|
|
17
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
// Currently does nothing
|
|
19
|
+
yield this._connector.connect();
|
|
20
|
+
return '';
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.SuiWallet = SuiWallet;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
import { SuiWalletConnector } from '../SuiWalletConnector';
|
|
3
|
+
export declare class SuiWallet extends Wallet<SuiWalletConnector> {
|
|
4
|
+
/**
|
|
5
|
+
* Sends the native balance of the wallet to the given address.
|
|
6
|
+
* @param amount - The amount of balance
|
|
7
|
+
* @param toAddress - The address to send the balance to.
|
|
8
|
+
* @returns The signature of the sent transaction.
|
|
9
|
+
*/
|
|
10
|
+
sendBalance(): Promise<string>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
import { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
|
|
5
|
+
class SuiWallet extends Wallet {
|
|
6
|
+
/**
|
|
7
|
+
* Sends the native balance of the wallet to the given address.
|
|
8
|
+
* @param amount - The amount of balance
|
|
9
|
+
* @param toAddress - The address to send the balance to.
|
|
10
|
+
* @returns The signature of the sent transaction.
|
|
11
|
+
*/
|
|
12
|
+
sendBalance() {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
// Currently does nothing
|
|
15
|
+
yield this._connector.connect();
|
|
16
|
+
return '';
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { SuiWallet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SuiWallet';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var walletStandard = require('@mysten/wallet-standard');
|
|
7
|
+
var injected = require('./injected.cjs');
|
|
8
|
+
|
|
9
|
+
const fetchSuiInjectedWalletConnectors = () => {
|
|
10
|
+
const walletStandardWallets = walletStandard.getWallets().get();
|
|
11
|
+
// Wallet standard wallets don't always have injectedConfig from wallet book,
|
|
12
|
+
// so we filter them by checking if they support critical sui features.
|
|
13
|
+
const walletStandardConnectors = walletStandardWallets
|
|
14
|
+
.filter((wallet) => { var _a; return (_a = wallet.features) === null || _a === void 0 ? void 0 : _a['sui:signPersonalMessage']; })
|
|
15
|
+
.map((wallet) => class extends injected.Injected {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
constructor(props) {
|
|
18
|
+
super(wallet.name, Object.assign({ metadata: {
|
|
19
|
+
icon: wallet.icon,
|
|
20
|
+
id: wallet.name,
|
|
21
|
+
name: wallet.name,
|
|
22
|
+
}, name: wallet.name, wallet: wallet }, props));
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return [...walletStandardConnectors];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
exports.fetchSuiInjectedWalletConnectors = fetchSuiInjectedWalletConnectors;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { getWallets } from '@mysten/wallet-standard';
|
|
3
|
+
import { Injected } from './injected.js';
|
|
4
|
+
|
|
5
|
+
const fetchSuiInjectedWalletConnectors = () => {
|
|
6
|
+
const walletStandardWallets = getWallets().get();
|
|
7
|
+
// Wallet standard wallets don't always have injectedConfig from wallet book,
|
|
8
|
+
// so we filter them by checking if they support critical sui features.
|
|
9
|
+
const walletStandardConnectors = walletStandardWallets
|
|
10
|
+
.filter((wallet) => { var _a; return (_a = wallet.features) === null || _a === void 0 ? void 0 : _a['sui:signPersonalMessage']; })
|
|
11
|
+
.map((wallet) => class extends Injected {
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
+
constructor(props) {
|
|
14
|
+
super(wallet.name, Object.assign({ metadata: {
|
|
15
|
+
icon: wallet.icon,
|
|
16
|
+
id: wallet.name,
|
|
17
|
+
name: wallet.name,
|
|
18
|
+
}, name: wallet.name, wallet: wallet }, props));
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return [...walletStandardConnectors];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { fetchSuiInjectedWalletConnectors };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './injected';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var SuiWalletConnector = require('../../SuiWalletConnector.cjs');
|
|
7
|
+
|
|
8
|
+
class Injected extends SuiWalletConnector.SuiWalletConnector {
|
|
9
|
+
constructor(name, props) {
|
|
10
|
+
super(name, props);
|
|
11
|
+
}
|
|
12
|
+
// Injected wallets are always already installed on browser
|
|
13
|
+
isInstalledOnBrowser() {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.Injected = Injected;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SuiWalletConnector } from '../../SuiWalletConnector';
|
|
2
|
+
import { SuiWalletConnectorProps } from '../../types';
|
|
3
|
+
export declare class Injected extends SuiWalletConnector {
|
|
4
|
+
constructor(name: string, props: SuiWalletConnectorProps);
|
|
5
|
+
isInstalledOnBrowser(): boolean;
|
|
6
|
+
}
|