@dynamic-labs/global-wallet 3.0.0-alpha.61 → 3.0.0-alpha.63
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/_virtual/_tslib.cjs +36 -0
- package/_virtual/_tslib.js +32 -0
- package/package.json +6 -6
- package/src/GlobalWalletConnector.cjs +191 -0
- package/{index.js → src/GlobalWalletConnector.js} +2 -30
- package/src/index.cjs +11 -0
- package/src/index.js +2 -0
|
@@ -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.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/global-wallet",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.63",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"homepage": "https://github.com/dynamic-labs/DynamicAuth#readme",
|
|
14
14
|
"author": "Dynamic Labs, Inc.",
|
|
15
15
|
"license": "MIT",
|
|
16
|
-
"main": "./index.
|
|
16
|
+
"main": "./index.cjs",
|
|
17
17
|
"module": "./index.js",
|
|
18
18
|
"types": "./src/index.d.ts",
|
|
19
19
|
"type": "module",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"@walletconnect/core": "2.13.1",
|
|
30
30
|
"@walletconnect/utils": "2.13.1",
|
|
31
31
|
"@walletconnect/web3wallet": "1.12.1",
|
|
32
|
-
"jsqr": "1.4.0"
|
|
32
|
+
"jsqr": "1.4.0",
|
|
33
|
+
"@dynamic-labs/wallet-connector-core": "3.0.0-alpha.63"
|
|
33
34
|
},
|
|
34
35
|
"peerDependencies": {
|
|
35
|
-
"viem": "2.7.6",
|
|
36
|
-
"react": "^18.0.0"
|
|
37
|
-
"@dynamic-labs/wallet-connector-core": "3.0.0-alpha.61"
|
|
36
|
+
"viem": "^2.7.6",
|
|
37
|
+
"react": "^18.0.0"
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../_virtual/_tslib.cjs');
|
|
7
|
+
var core = require('@walletconnect/core');
|
|
8
|
+
var utils = require('@walletconnect/utils');
|
|
9
|
+
var web3wallet = require('@walletconnect/web3wallet');
|
|
10
|
+
var viem = require('viem');
|
|
11
|
+
var jsQR = require('jsqr');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
var jsQR__default = /*#__PURE__*/_interopDefaultLegacy(jsQR);
|
|
16
|
+
|
|
17
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
18
|
+
const buildCombinedNamespaces = (params) => {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
const requiredEip155 = ((_a = params.requiredNamespaces) === null || _a === void 0 ? void 0 : _a.eip155) || {};
|
|
21
|
+
const optionalEip155 = ((_b = params.optionalNamespaces) === null || _b === void 0 ? void 0 : _b.eip155) || {};
|
|
22
|
+
const chains = new Set([
|
|
23
|
+
...(requiredEip155.chains || []),
|
|
24
|
+
...(optionalEip155.chains || []),
|
|
25
|
+
]);
|
|
26
|
+
const events = new Set([
|
|
27
|
+
...(requiredEip155.events || []),
|
|
28
|
+
...(optionalEip155.events || []),
|
|
29
|
+
]);
|
|
30
|
+
const methods = new Set([
|
|
31
|
+
...(requiredEip155.methods || []),
|
|
32
|
+
...(optionalEip155.methods || []),
|
|
33
|
+
]);
|
|
34
|
+
return {
|
|
35
|
+
chains: Array.from(chains),
|
|
36
|
+
events: Array.from(events),
|
|
37
|
+
methods: Array.from(methods),
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
const GlobalWalletExtension = {
|
|
41
|
+
extend: (connector) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
let web3wallet$1;
|
|
43
|
+
let WCListenersOn = false;
|
|
44
|
+
let pendingSessionProposal;
|
|
45
|
+
const globalWallet = {
|
|
46
|
+
confirmPairing: (confirm) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
const { params, id } = pendingSessionProposal;
|
|
48
|
+
if (!confirm) {
|
|
49
|
+
yield web3wallet$1.rejectSession({
|
|
50
|
+
id,
|
|
51
|
+
reason: utils.getSdkError('USER_REJECTED'),
|
|
52
|
+
});
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const { chains, events, methods } = buildCombinedNamespaces(params);
|
|
56
|
+
const address = yield connector.getAddress();
|
|
57
|
+
const approvedNamespaces = utils.buildApprovedNamespaces({
|
|
58
|
+
proposal: params,
|
|
59
|
+
supportedNamespaces: {
|
|
60
|
+
eip155: {
|
|
61
|
+
accounts: chains.map((chain) => `${chain}:${address}`),
|
|
62
|
+
chains,
|
|
63
|
+
events,
|
|
64
|
+
methods,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
yield web3wallet$1.approveSession({
|
|
69
|
+
id,
|
|
70
|
+
namespaces: approvedNamespaces,
|
|
71
|
+
});
|
|
72
|
+
}),
|
|
73
|
+
disconnectWCSession: (topic) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
74
|
+
if (web3wallet$1) {
|
|
75
|
+
yield web3wallet$1.disconnectSession({
|
|
76
|
+
reason: utils.getSdkError('USER_DISCONNECTED'),
|
|
77
|
+
topic,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}),
|
|
81
|
+
// topic => session mapping, with peer metadata in the session
|
|
82
|
+
getConnectedWCSessions: () => _tslib.__awaiter(void 0, void 0, void 0, function* () { return web3wallet$1.getActiveSessions(); }),
|
|
83
|
+
getPendingPairing: () => pendingSessionProposal,
|
|
84
|
+
getWeb3Wallet: () => web3wallet$1,
|
|
85
|
+
initWeb3Wallet: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
+
if (!web3wallet$1) {
|
|
87
|
+
const core$1 = new core.Core({
|
|
88
|
+
projectId: '7569c63c696a4e8aeb3217c1b1332bd7',
|
|
89
|
+
});
|
|
90
|
+
web3wallet$1 = yield web3wallet.Web3Wallet.init({
|
|
91
|
+
core: core$1,
|
|
92
|
+
metadata: {
|
|
93
|
+
description: 'Dynamic Embedded Wallet',
|
|
94
|
+
icons: [],
|
|
95
|
+
name: 'Dynamic',
|
|
96
|
+
url: 'app.dynamic.xyz',
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}),
|
|
101
|
+
initializeListeners: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
102
|
+
if (WCListenersOn)
|
|
103
|
+
return;
|
|
104
|
+
const onSessionProposal = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ params, id }) {
|
|
105
|
+
pendingSessionProposal = { id, params };
|
|
106
|
+
});
|
|
107
|
+
const sessionMessageListener = (_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ params, id, topic }) {
|
|
108
|
+
const { request, chainId } = params;
|
|
109
|
+
// since we cant listen to chain events from the dapp, just change when a request comes in
|
|
110
|
+
const [requestParamsMessage, typedDataToSign] = request.params;
|
|
111
|
+
const signer = (yield connector.getSigner());
|
|
112
|
+
const handleRequest = (handler) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
try {
|
|
114
|
+
connector.isGlobalTransaction = true;
|
|
115
|
+
const result = yield handler();
|
|
116
|
+
connector.isGlobalTransaction = false;
|
|
117
|
+
return { id, jsonrpc: '2.0', result };
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
return {
|
|
121
|
+
error: {
|
|
122
|
+
code: 5000,
|
|
123
|
+
message: 'User rejected.',
|
|
124
|
+
},
|
|
125
|
+
id,
|
|
126
|
+
jsonrpc: '2.0',
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
let response;
|
|
131
|
+
if (request.method === 'eth_signTypedData_v4') {
|
|
132
|
+
response = yield handleRequest(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
133
|
+
return signer.signTypedData(Object.assign(Object.assign({}, JSON.parse(typedDataToSign)), { account: requestParamsMessage }));
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
else if (request.method === 'personal_sign') {
|
|
137
|
+
const message = Buffer.from(requestParamsMessage.slice(2), 'hex').toString('utf8');
|
|
138
|
+
response = yield handleRequest(() => connector.signMessage(message));
|
|
139
|
+
}
|
|
140
|
+
else if (request.method === 'eth_sendTransaction') {
|
|
141
|
+
if (chainId) {
|
|
142
|
+
yield connector.switchNetwork({
|
|
143
|
+
networkChainId: chainId.split(':')[1],
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
response = yield handleRequest(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
147
|
+
return signer.sendTransaction(Object.assign(Object.assign({}, requestParamsMessage), { gas: viem.fromHex(requestParamsMessage.gas, 'bigint'), value: requestParamsMessage.value
|
|
148
|
+
? viem.fromHex(requestParamsMessage.value, 'bigint')
|
|
149
|
+
: BigInt(0) }));
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
if (response) {
|
|
153
|
+
yield web3wallet$1.respondSessionRequest({
|
|
154
|
+
response,
|
|
155
|
+
topic,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
yield globalWallet.initWeb3Wallet();
|
|
160
|
+
web3wallet$1.on('session_proposal', onSessionProposal);
|
|
161
|
+
web3wallet$1.on('session_request', sessionMessageListener);
|
|
162
|
+
connector.on('chainChange', (_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({ chain }) {
|
|
163
|
+
const connections = yield web3wallet$1.getActiveSessions();
|
|
164
|
+
const connectionTopics = Object.keys(connections !== null && connections !== void 0 ? connections : {});
|
|
165
|
+
// tell all connected dapps that the chain has changed
|
|
166
|
+
yield Promise.all(connectionTopics.map((topic) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
167
|
+
yield web3wallet$1.emitSessionEvent({
|
|
168
|
+
chainId: `eip155:${chain}`,
|
|
169
|
+
event: {
|
|
170
|
+
data: chain,
|
|
171
|
+
name: 'chainChanged',
|
|
172
|
+
},
|
|
173
|
+
topic,
|
|
174
|
+
});
|
|
175
|
+
})));
|
|
176
|
+
}));
|
|
177
|
+
WCListenersOn = true;
|
|
178
|
+
}),
|
|
179
|
+
pairWithWC: (uri) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
180
|
+
yield web3wallet$1.pair({ uri });
|
|
181
|
+
}),
|
|
182
|
+
qrScanner: (data, width, height, providedOptions) => jsQR__default["default"](data, width, height, providedOptions),
|
|
183
|
+
};
|
|
184
|
+
connector.globalWallet = globalWallet;
|
|
185
|
+
yield globalWallet.initializeListeners();
|
|
186
|
+
}),
|
|
187
|
+
name: 'global-wallet-extension',
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
exports.GlobalWalletExtension = GlobalWalletExtension;
|
|
191
|
+
exports.buildCombinedNamespaces = buildCombinedNamespaces;
|
|
@@ -1,39 +1,11 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../_virtual/_tslib.js';
|
|
1
3
|
import { Core } from '@walletconnect/core';
|
|
2
4
|
import { getSdkError, buildApprovedNamespaces } from '@walletconnect/utils';
|
|
3
5
|
import { Web3Wallet } from '@walletconnect/web3wallet';
|
|
4
6
|
import { fromHex } from 'viem';
|
|
5
7
|
import jsQR from 'jsqr';
|
|
6
8
|
|
|
7
|
-
/******************************************************************************
|
|
8
|
-
Copyright (c) Microsoft Corporation.
|
|
9
|
-
|
|
10
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
-
purpose with or without fee is hereby granted.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
-
***************************************************************************** */
|
|
21
|
-
|
|
22
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
23
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
24
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
25
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
26
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
27
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
28
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
33
|
-
var e = new Error(message);
|
|
34
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
9
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
38
10
|
const buildCombinedNamespaces = (params) => {
|
|
39
11
|
var _a, _b;
|
package/src/index.cjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var GlobalWalletConnector = require('./GlobalWalletConnector.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.GlobalWalletExtension = GlobalWalletConnector.GlobalWalletExtension;
|
|
11
|
+
exports.buildCombinedNamespaces = GlobalWalletConnector.buildCombinedNamespaces;
|
package/src/index.js
ADDED