@nibgate/sdk 0.2.14 → 0.2.16
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/dist/nibgate.js +8 -177
- package/dist/nibgate.js.map +4 -4
- package/dist/nibgate.min.js +8 -8
- package/dist/nibgate.min.js.map +4 -4
- package/package.json +1 -1
- package/src/browser/evm-gateway.js +7 -3
- package/src/browser/gateway.js +2 -13
package/package.json
CHANGED
|
@@ -113,12 +113,16 @@ export function createEvmGatewayUnlock(resource, options = {}) {
|
|
|
113
113
|
async function checkout(input) {
|
|
114
114
|
const evm = provider();
|
|
115
115
|
if (!evm) throw new Error(options.noWalletMessage || 'Install or open an EVM wallet to continue.');
|
|
116
|
-
|
|
116
|
+
// Always fetch the current wallet from MetaMask — the cached walletAddress
|
|
117
|
+
// might be stale if the user switched accounts after connecting.
|
|
118
|
+
const currentAccounts = await evm.request({ method: 'eth_accounts' }).catch(() => walletAddress ? [walletAddress] : []);
|
|
119
|
+
const currentAddress = Array.isArray(currentAccounts) && currentAccounts[0] ? currentAccounts[0] : (walletAddress || await connect());
|
|
120
|
+
if (currentAddress !== walletAddress) walletAddress = currentAddress;
|
|
117
121
|
const gatewayWallet = await createCircleGatewayBrowserAdapter({
|
|
118
122
|
network,
|
|
119
123
|
signer: {
|
|
120
|
-
address:
|
|
121
|
-
signTypedData: (typedData) => evm.request({ method: 'eth_signTypedData_v4', params: [
|
|
124
|
+
address: currentAddress,
|
|
125
|
+
signTypedData: (typedData) => evm.request({ method: 'eth_signTypedData_v4', params: [currentAddress, stringifyJson(typedData)] })
|
|
122
126
|
},
|
|
123
127
|
clientModule: options.circleClientModule
|
|
124
128
|
});
|
package/src/browser/gateway.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BatchEvmScheme as CircleBatchEvmScheme } from '@circle-fin/x402-batching/client';
|
|
1
2
|
import { stringifyJson } from './json.js';
|
|
2
3
|
|
|
3
4
|
function encodeBase64(value) {
|
|
@@ -17,19 +18,7 @@ export async function createCircleGatewayBrowserAdapter(options = {}) {
|
|
|
17
18
|
throw new Error('Circle Gateway browser adapter requires an EVM signer with address and signTypedData.');
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
const circle = await import('@circle-fin/x402-batching/client');
|
|
23
|
-
BatchEvmScheme = circle.BatchEvmScheme;
|
|
24
|
-
} catch (err) {
|
|
25
|
-
console.warn('[nibgate] Failed to import @circle-fin/x402-batching/client:', err.message);
|
|
26
|
-
console.warn('[nibgate] Falling back to custom BatchEvmScheme');
|
|
27
|
-
const local = await import('./schemes/batch-scheme.js');
|
|
28
|
-
BatchEvmScheme = local.BatchEvmScheme;
|
|
29
|
-
}
|
|
30
|
-
const scheme = options.clientModule?.BatchEvmScheme
|
|
31
|
-
? new options.clientModule.BatchEvmScheme(signer)
|
|
32
|
-
: new BatchEvmScheme(signer);
|
|
21
|
+
const scheme = new CircleBatchEvmScheme(signer);
|
|
33
22
|
const network = options.network || options.chainId && `eip155:${options.chainId}` || 'eip155:5042002';
|
|
34
23
|
|
|
35
24
|
function parsePaymentRequired(input) {
|