@onekeyfe/onekey-sui-provider 1.1.24 → 1.1.26

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.
@@ -7,6 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { bytesToHex } from '@noble/hashes/utils';
10
11
  import { getOrCreateExtInjectedJsBridge } from '@onekeyfe/extension-bridge-injected';
11
12
  import { ProviderSuiBase } from './ProviderSuiBase';
12
13
  import { web3Errors } from '@onekeyfe/cross-inpage-provider-errors';
@@ -49,8 +50,8 @@ class ProviderSui extends ProviderSuiBase {
49
50
  if (options.emit && this.isConnectionStatusChanged('connected')) {
50
51
  this.connectionStatus = 'connected';
51
52
  const address = account !== null && account !== void 0 ? account : null;
52
- this.emit('connect', address);
53
- this.emit('accountChanged', address);
53
+ this.emit('connect', address.address);
54
+ this.emit('accountChanged', address.address);
54
55
  }
55
56
  }
56
57
  _handleDisconnected(options = { emit: true }) {
@@ -62,13 +63,14 @@ class ProviderSui extends ProviderSuiBase {
62
63
  }
63
64
  }
64
65
  isAccountsChanged(account) {
65
- return account !== this._account;
66
+ var _a;
67
+ return (account === null || account === void 0 ? void 0 : account.address) !== ((_a = this._account) === null || _a === void 0 ? void 0 : _a.address);
66
68
  }
67
69
  // trigger by bridge account change event
68
70
  _handleAccountChange(payload) {
69
71
  const account = payload;
70
72
  if (this.isAccountsChanged(account)) {
71
- this.emit('accountChanged', account || null);
73
+ this.emit('accountChanged', account.address || null);
72
74
  }
73
75
  if (!account) {
74
76
  this._handleDisconnected();
@@ -133,27 +135,27 @@ class ProviderSui extends ProviderSuiBase {
133
135
  });
134
136
  });
135
137
  }
136
- signAndExecuteTransaction(input) {
138
+ signAndExecuteTransactionBlock(input) {
137
139
  return __awaiter(this, void 0, void 0, function* () {
138
140
  return this._callBridge({
139
- method: 'signAndExecuteTransaction',
140
- params: input,
141
+ method: 'signAndExecuteTransactionBlock',
142
+ params: Object.assign(Object.assign({}, input), { walletSerialize: JSON.stringify(input.account), blockSerialize: input.transactionBlock.serialize() }),
141
143
  });
142
144
  });
143
145
  }
144
- executeMoveCall(transaction) {
146
+ signTransactionBlock(input) {
145
147
  return __awaiter(this, void 0, void 0, function* () {
146
148
  return this._callBridge({
147
- method: 'executeMoveCall',
148
- params: transaction,
149
+ method: 'signTransactionBlock',
150
+ params: Object.assign(Object.assign({}, input), { walletSerialize: JSON.stringify(input.account), blockSerialize: input.transactionBlock.serialize() }),
149
151
  });
150
152
  });
151
153
  }
152
- executeSerializedMoveCall(transaction) {
154
+ signMessage(input) {
153
155
  return __awaiter(this, void 0, void 0, function* () {
154
156
  return this._callBridge({
155
- method: 'executeSerializedMoveCall',
156
- params: transaction,
157
+ method: 'signMessage',
158
+ params: Object.assign(Object.assign({}, input), { walletSerialize: JSON.stringify(input.account), messageSerialize: bytesToHex(input.message) }),
157
159
  });
158
160
  });
159
161
  }
@@ -7,16 +7,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { hexToBytes } from '@noble/hashes/utils';
10
11
  import mitt from 'mitt';
11
- import { registerWallet } from '@mysten/wallet-standard';
12
- import { SUI_CHAINS, ReadonlyWalletAccount, } from '@mysten/wallet-standard';
12
+ import { ReadonlyWalletAccount, registerWallet, SUI_DEVNET_CHAIN, SUI_TESTNET_CHAIN, } from '@mysten/wallet-standard';
13
13
  import { ALL_PERMISSION_TYPES } from './types';
14
14
  var Feature;
15
15
  (function (Feature) {
16
16
  Feature["STANDARD__CONNECT"] = "standard:connect";
17
17
  Feature["STANDARD__DISCONNECT"] = "standard:disconnect";
18
18
  Feature["STANDARD__EVENTS"] = "standard:events";
19
- Feature["SUI__SIGN_AND_EXECUTE_TRANSACTION"] = "sui:signAndExecuteTransaction";
19
+ Feature["SUI__SIGN_AND_EXECUTE_TRANSACTION_BLOCK"] = "sui:signAndExecuteTransactionBlock";
20
+ Feature["SUI__SIGN_TRANSACTION_BLOCK"] = "sui:signTransactionBlock";
21
+ Feature["SUI__SIGN_MESSAGE"] = "sui:signMessage";
20
22
  })(Feature || (Feature = {}));
21
23
  class OnekeySuiStandardWallet {
22
24
  constructor(provider, options) {
@@ -27,24 +29,30 @@ class OnekeySuiStandardWallet {
27
29
  return () => this._events.off(event, listener);
28
30
  };
29
31
  this.$connected = () => __awaiter(this, void 0, void 0, function* () {
30
- const activeChain = yield this.$getActiveChain();
32
+ const activeChain = yield this.getActiveChain();
31
33
  if (!(yield this.$hasPermissions(['viewAccount']))) {
32
34
  return;
33
35
  }
34
36
  const accounts = yield this.provider.getAccounts();
35
- const [address] = accounts;
36
- if (address) {
37
- const account = this._account;
38
- if (!account || account.address !== address) {
39
- this._account = new ReadonlyWalletAccount({
40
- address,
41
- // TODO: Expose public key instead of address:
42
- publicKey: new Uint8Array(),
43
- chains: activeChain ? [activeChain] : [],
44
- features: [Feature.SUI__SIGN_AND_EXECUTE_TRANSACTION],
45
- });
46
- this._events.emit('change', { accounts: this.accounts });
47
- }
37
+ const [account] = accounts;
38
+ const activateAccount = this._account;
39
+ if (activateAccount && activateAccount.address === account.address) {
40
+ return { accounts: this.accounts };
41
+ }
42
+ if (account) {
43
+ this._account = new ReadonlyWalletAccount({
44
+ address: account.address,
45
+ publicKey: hexToBytes(account.publicKey),
46
+ chains: activeChain ? [activeChain] : [],
47
+ features: [
48
+ Feature.STANDARD__CONNECT,
49
+ Feature.SUI__SIGN_AND_EXECUTE_TRANSACTION_BLOCK,
50
+ Feature.SUI__SIGN_TRANSACTION_BLOCK,
51
+ Feature.SUI__SIGN_MESSAGE,
52
+ ],
53
+ });
54
+ this._events.emit('change', { accounts: this.accounts });
55
+ return { accounts: this.accounts };
48
56
  }
49
57
  });
50
58
  this.$connect = (input) => __awaiter(this, void 0, void 0, function* () {
@@ -59,13 +67,20 @@ class OnekeySuiStandardWallet {
59
67
  this._account = null;
60
68
  this._events.all.clear();
61
69
  });
62
- this.$signAndExecuteTransaction = (input) => __awaiter(this, void 0, void 0, function* () {
63
- return this.provider.signAndExecuteTransaction(input);
70
+ this.$signAndExecuteTransactionBlock = (input) => __awaiter(this, void 0, void 0, function* () {
71
+ return this.provider.signAndExecuteTransactionBlock(input);
72
+ });
73
+ this.$signTransactionBlock = (input) => __awaiter(this, void 0, void 0, function* () {
74
+ return this.provider.signTransactionBlock(input);
75
+ });
76
+ this.$signMessage = (input) => __awaiter(this, void 0, void 0, function* () {
77
+ return this.provider.signMessage(input);
64
78
  });
65
79
  this.provider = provider;
66
80
  this._events = mitt();
67
81
  this._account = null;
68
82
  this.options = options;
83
+ this.subscribeEventFromBackend();
69
84
  void this.$connected();
70
85
  }
71
86
  get name() {
@@ -78,8 +93,7 @@ class OnekeySuiStandardWallet {
78
93
  return (((_a = this.options) === null || _a === void 0 ? void 0 : _a.logo) || '');
79
94
  }
80
95
  get chains() {
81
- // TODO: Extract chain from wallet:
82
- return SUI_CHAINS;
96
+ return [SUI_DEVNET_CHAIN, SUI_TESTNET_CHAIN];
83
97
  }
84
98
  get accounts() {
85
99
  return this._account ? [this._account] : [];
@@ -98,19 +112,39 @@ class OnekeySuiStandardWallet {
98
112
  version: '1.0.0',
99
113
  on: this.$on,
100
114
  },
101
- [Feature.SUI__SIGN_AND_EXECUTE_TRANSACTION]: {
102
- version: '1.1.0',
103
- signAndExecuteTransaction: this.$signAndExecuteTransaction,
115
+ [Feature.SUI__SIGN_AND_EXECUTE_TRANSACTION_BLOCK]: {
116
+ version: '1.0.0',
117
+ signAndExecuteTransactionBlock: this.$signAndExecuteTransactionBlock,
118
+ },
119
+ [Feature.SUI__SIGN_TRANSACTION_BLOCK]: {
120
+ version: '1.0.0',
121
+ signTransactionBlock: this.$signTransactionBlock,
122
+ },
123
+ [Feature.SUI__SIGN_MESSAGE]: {
124
+ version: '1.0.0',
125
+ signMessage: this.$signMessage,
104
126
  },
105
127
  };
106
128
  }
107
- $getActiveChain() {
108
- var _a;
109
- return (_a = this.provider.getActiveChain()) !== null && _a !== void 0 ? _a : 'sui:unknown';
129
+ getActiveChain() {
130
+ return this.provider.getActiveChain();
110
131
  }
111
132
  $hasPermissions(permissions = ALL_PERMISSION_TYPES) {
112
133
  return this.provider.hasPermissions(permissions);
113
134
  }
135
+ subscribeEventFromBackend() {
136
+ this.provider.onNetworkChange((network) => {
137
+ if (!network)
138
+ return;
139
+ return this.handleNetworkSwitch({ network });
140
+ });
141
+ }
142
+ handleNetworkSwitch(payload) {
143
+ const { network } = payload;
144
+ this._events.emit('change', {
145
+ chains: [network],
146
+ });
147
+ }
114
148
  }
115
149
  export function registerSuiWallet(provider, options) {
116
150
  try {
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ProviderSui = void 0;
13
+ const utils_1 = require("@noble/hashes/utils");
13
14
  const extension_bridge_injected_1 = require("@onekeyfe/extension-bridge-injected");
14
15
  const ProviderSuiBase_1 = require("./ProviderSuiBase");
15
16
  const cross_inpage_provider_errors_1 = require("@onekeyfe/cross-inpage-provider-errors");
@@ -52,8 +53,8 @@ class ProviderSui extends ProviderSuiBase_1.ProviderSuiBase {
52
53
  if (options.emit && this.isConnectionStatusChanged('connected')) {
53
54
  this.connectionStatus = 'connected';
54
55
  const address = account !== null && account !== void 0 ? account : null;
55
- this.emit('connect', address);
56
- this.emit('accountChanged', address);
56
+ this.emit('connect', address.address);
57
+ this.emit('accountChanged', address.address);
57
58
  }
58
59
  }
59
60
  _handleDisconnected(options = { emit: true }) {
@@ -65,13 +66,14 @@ class ProviderSui extends ProviderSuiBase_1.ProviderSuiBase {
65
66
  }
66
67
  }
67
68
  isAccountsChanged(account) {
68
- return account !== this._account;
69
+ var _a;
70
+ return (account === null || account === void 0 ? void 0 : account.address) !== ((_a = this._account) === null || _a === void 0 ? void 0 : _a.address);
69
71
  }
70
72
  // trigger by bridge account change event
71
73
  _handleAccountChange(payload) {
72
74
  const account = payload;
73
75
  if (this.isAccountsChanged(account)) {
74
- this.emit('accountChanged', account || null);
76
+ this.emit('accountChanged', account.address || null);
75
77
  }
76
78
  if (!account) {
77
79
  this._handleDisconnected();
@@ -136,27 +138,27 @@ class ProviderSui extends ProviderSuiBase_1.ProviderSuiBase {
136
138
  });
137
139
  });
138
140
  }
139
- signAndExecuteTransaction(input) {
141
+ signAndExecuteTransactionBlock(input) {
140
142
  return __awaiter(this, void 0, void 0, function* () {
141
143
  return this._callBridge({
142
- method: 'signAndExecuteTransaction',
143
- params: input,
144
+ method: 'signAndExecuteTransactionBlock',
145
+ params: Object.assign(Object.assign({}, input), { walletSerialize: JSON.stringify(input.account), blockSerialize: input.transactionBlock.serialize() }),
144
146
  });
145
147
  });
146
148
  }
147
- executeMoveCall(transaction) {
149
+ signTransactionBlock(input) {
148
150
  return __awaiter(this, void 0, void 0, function* () {
149
151
  return this._callBridge({
150
- method: 'executeMoveCall',
151
- params: transaction,
152
+ method: 'signTransactionBlock',
153
+ params: Object.assign(Object.assign({}, input), { walletSerialize: JSON.stringify(input.account), blockSerialize: input.transactionBlock.serialize() }),
152
154
  });
153
155
  });
154
156
  }
155
- executeSerializedMoveCall(transaction) {
157
+ signMessage(input) {
156
158
  return __awaiter(this, void 0, void 0, function* () {
157
159
  return this._callBridge({
158
- method: 'executeSerializedMoveCall',
159
- params: transaction,
160
+ method: 'signMessage',
161
+ params: Object.assign(Object.assign({}, input), { walletSerialize: JSON.stringify(input.account), messageSerialize: (0, utils_1.bytesToHex)(input.message) }),
160
162
  });
161
163
  });
162
164
  }
@@ -13,16 +13,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.registerSuiWallet = void 0;
16
+ const utils_1 = require("@noble/hashes/utils");
16
17
  const mitt_1 = __importDefault(require("mitt"));
17
18
  const wallet_standard_1 = require("@mysten/wallet-standard");
18
- const wallet_standard_2 = require("@mysten/wallet-standard");
19
19
  const types_1 = require("./types");
20
20
  var Feature;
21
21
  (function (Feature) {
22
22
  Feature["STANDARD__CONNECT"] = "standard:connect";
23
23
  Feature["STANDARD__DISCONNECT"] = "standard:disconnect";
24
24
  Feature["STANDARD__EVENTS"] = "standard:events";
25
- Feature["SUI__SIGN_AND_EXECUTE_TRANSACTION"] = "sui:signAndExecuteTransaction";
25
+ Feature["SUI__SIGN_AND_EXECUTE_TRANSACTION_BLOCK"] = "sui:signAndExecuteTransactionBlock";
26
+ Feature["SUI__SIGN_TRANSACTION_BLOCK"] = "sui:signTransactionBlock";
27
+ Feature["SUI__SIGN_MESSAGE"] = "sui:signMessage";
26
28
  })(Feature || (Feature = {}));
27
29
  class OnekeySuiStandardWallet {
28
30
  constructor(provider, options) {
@@ -33,24 +35,30 @@ class OnekeySuiStandardWallet {
33
35
  return () => this._events.off(event, listener);
34
36
  };
35
37
  this.$connected = () => __awaiter(this, void 0, void 0, function* () {
36
- const activeChain = yield this.$getActiveChain();
38
+ const activeChain = yield this.getActiveChain();
37
39
  if (!(yield this.$hasPermissions(['viewAccount']))) {
38
40
  return;
39
41
  }
40
42
  const accounts = yield this.provider.getAccounts();
41
- const [address] = accounts;
42
- if (address) {
43
- const account = this._account;
44
- if (!account || account.address !== address) {
45
- this._account = new wallet_standard_2.ReadonlyWalletAccount({
46
- address,
47
- // TODO: Expose public key instead of address:
48
- publicKey: new Uint8Array(),
49
- chains: activeChain ? [activeChain] : [],
50
- features: [Feature.SUI__SIGN_AND_EXECUTE_TRANSACTION],
51
- });
52
- this._events.emit('change', { accounts: this.accounts });
53
- }
43
+ const [account] = accounts;
44
+ const activateAccount = this._account;
45
+ if (activateAccount && activateAccount.address === account.address) {
46
+ return { accounts: this.accounts };
47
+ }
48
+ if (account) {
49
+ this._account = new wallet_standard_1.ReadonlyWalletAccount({
50
+ address: account.address,
51
+ publicKey: (0, utils_1.hexToBytes)(account.publicKey),
52
+ chains: activeChain ? [activeChain] : [],
53
+ features: [
54
+ Feature.STANDARD__CONNECT,
55
+ Feature.SUI__SIGN_AND_EXECUTE_TRANSACTION_BLOCK,
56
+ Feature.SUI__SIGN_TRANSACTION_BLOCK,
57
+ Feature.SUI__SIGN_MESSAGE,
58
+ ],
59
+ });
60
+ this._events.emit('change', { accounts: this.accounts });
61
+ return { accounts: this.accounts };
54
62
  }
55
63
  });
56
64
  this.$connect = (input) => __awaiter(this, void 0, void 0, function* () {
@@ -65,13 +73,20 @@ class OnekeySuiStandardWallet {
65
73
  this._account = null;
66
74
  this._events.all.clear();
67
75
  });
68
- this.$signAndExecuteTransaction = (input) => __awaiter(this, void 0, void 0, function* () {
69
- return this.provider.signAndExecuteTransaction(input);
76
+ this.$signAndExecuteTransactionBlock = (input) => __awaiter(this, void 0, void 0, function* () {
77
+ return this.provider.signAndExecuteTransactionBlock(input);
78
+ });
79
+ this.$signTransactionBlock = (input) => __awaiter(this, void 0, void 0, function* () {
80
+ return this.provider.signTransactionBlock(input);
81
+ });
82
+ this.$signMessage = (input) => __awaiter(this, void 0, void 0, function* () {
83
+ return this.provider.signMessage(input);
70
84
  });
71
85
  this.provider = provider;
72
86
  this._events = (0, mitt_1.default)();
73
87
  this._account = null;
74
88
  this.options = options;
89
+ this.subscribeEventFromBackend();
75
90
  void this.$connected();
76
91
  }
77
92
  get name() {
@@ -84,8 +99,7 @@ class OnekeySuiStandardWallet {
84
99
  return (((_a = this.options) === null || _a === void 0 ? void 0 : _a.logo) || '');
85
100
  }
86
101
  get chains() {
87
- // TODO: Extract chain from wallet:
88
- return wallet_standard_2.SUI_CHAINS;
102
+ return [wallet_standard_1.SUI_DEVNET_CHAIN, wallet_standard_1.SUI_TESTNET_CHAIN];
89
103
  }
90
104
  get accounts() {
91
105
  return this._account ? [this._account] : [];
@@ -104,19 +118,39 @@ class OnekeySuiStandardWallet {
104
118
  version: '1.0.0',
105
119
  on: this.$on,
106
120
  },
107
- [Feature.SUI__SIGN_AND_EXECUTE_TRANSACTION]: {
108
- version: '1.1.0',
109
- signAndExecuteTransaction: this.$signAndExecuteTransaction,
121
+ [Feature.SUI__SIGN_AND_EXECUTE_TRANSACTION_BLOCK]: {
122
+ version: '1.0.0',
123
+ signAndExecuteTransactionBlock: this.$signAndExecuteTransactionBlock,
124
+ },
125
+ [Feature.SUI__SIGN_TRANSACTION_BLOCK]: {
126
+ version: '1.0.0',
127
+ signTransactionBlock: this.$signTransactionBlock,
128
+ },
129
+ [Feature.SUI__SIGN_MESSAGE]: {
130
+ version: '1.0.0',
131
+ signMessage: this.$signMessage,
110
132
  },
111
133
  };
112
134
  }
113
- $getActiveChain() {
114
- var _a;
115
- return (_a = this.provider.getActiveChain()) !== null && _a !== void 0 ? _a : 'sui:unknown';
135
+ getActiveChain() {
136
+ return this.provider.getActiveChain();
116
137
  }
117
138
  $hasPermissions(permissions = types_1.ALL_PERMISSION_TYPES) {
118
139
  return this.provider.hasPermissions(permissions);
119
140
  }
141
+ subscribeEventFromBackend() {
142
+ this.provider.onNetworkChange((network) => {
143
+ if (!network)
144
+ return;
145
+ return this.handleNetworkSwitch({ network });
146
+ });
147
+ }
148
+ handleNetworkSwitch(payload) {
149
+ const { network } = payload;
150
+ this._events.emit('change', {
151
+ chains: [network],
152
+ });
153
+ }
120
154
  }
121
155
  function registerSuiWallet(provider, options) {
122
156
  try {
package/dist/types.d.ts CHANGED
@@ -7,4 +7,8 @@ export declare type WalletInfo = {
7
7
  logo: string;
8
8
  };
9
9
  export declare type SuiChainType = SuiChain;
10
+ export interface AccountInfo {
11
+ address: string;
12
+ publicKey: string;
13
+ }
10
14
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/onekey-sui-provider",
3
- "version": "1.1.24",
3
+ "version": "1.1.26",
4
4
  "keywords": [
5
5
  "cross-inpage-provider"
6
6
  ],
@@ -28,13 +28,13 @@
28
28
  "start": "tsc --watch"
29
29
  },
30
30
  "dependencies": {
31
- "@mysten/wallet-standard": "^0.3.00",
32
- "@onekeyfe/cross-inpage-provider-core": "1.1.24",
33
- "@onekeyfe/cross-inpage-provider-errors": "1.1.24",
34
- "@onekeyfe/cross-inpage-provider-types": "1.1.24",
35
- "@onekeyfe/extension-bridge-injected": "1.1.24",
31
+ "@mysten/wallet-standard": "^0.5.1",
32
+ "@onekeyfe/cross-inpage-provider-core": "1.1.26",
33
+ "@onekeyfe/cross-inpage-provider-errors": "1.1.26",
34
+ "@onekeyfe/cross-inpage-provider-types": "1.1.26",
35
+ "@onekeyfe/extension-bridge-injected": "1.1.26",
36
36
  "eth-rpc-errors": "^4.0.3",
37
37
  "mitt": "^3.0.0"
38
38
  },
39
- "gitHead": "77715c206f3369f7a0c294d2706d471d7339212e"
39
+ "gitHead": "c5fecd176e00c399c4829f73b9da5e74e1f4e1b9"
40
40
  }