@orbi-wallet/sdk 0.1.3 → 0.2.0
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/client.js +4 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -5
- package/dist/provider.d.ts +47 -0
- package/dist/provider.js +161 -0
- package/dist/rainbowkit.d.ts +16 -0
- package/dist/rainbowkit.js +30 -0
- package/dist/types.js +1 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +2 -5
- package/dist/wagmi.d.ts +22 -0
- package/dist/wagmi.js +97 -0
- package/package.json +25 -5
package/dist/client.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @orbi-wallet/sdk — Orbi Smart Wallet SDK (G-wallet)
|
|
4
3
|
*
|
|
@@ -9,17 +8,15 @@
|
|
|
9
8
|
* const { walletAddress } = await orbi.connect();
|
|
10
9
|
* const { signedXdr } = await orbi.signTransaction({ xdr });
|
|
11
10
|
*/
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.OrbiClient = void 0;
|
|
14
11
|
// Generated from package.json at build time (see scripts/generate-version.js)
|
|
15
12
|
// — package.json stays the single source of truth for name/version.
|
|
16
|
-
|
|
13
|
+
import { SDK_NAME, SDK_VERSION } from './version';
|
|
17
14
|
const KEYS_URL = 'https://keys.orbiwallet.xyz';
|
|
18
15
|
const KEYS_ORIGIN = new URL(KEYS_URL).origin;
|
|
19
16
|
const SESSION_KEY = 'orbi_session';
|
|
20
17
|
const POPUP_WIDTH = 420;
|
|
21
18
|
const POPUP_HEIGHT = 640;
|
|
22
|
-
class OrbiClient {
|
|
19
|
+
export class OrbiClient {
|
|
23
20
|
constructor(config = {}) {
|
|
24
21
|
this.network = config.network ?? 'testnet';
|
|
25
22
|
this.chain = config.chain ?? 'stellar';
|
|
@@ -191,8 +188,8 @@ class OrbiClient {
|
|
|
191
188
|
}
|
|
192
189
|
const url = new URL(`${KEYS_URL}${req.path}`);
|
|
193
190
|
url.searchParams.set('origin', window.location.origin);
|
|
194
|
-
url.searchParams.set('sdkName',
|
|
195
|
-
url.searchParams.set('sdkVersion',
|
|
191
|
+
url.searchParams.set('sdkName', SDK_NAME);
|
|
192
|
+
url.searchParams.set('sdkVersion', SDK_VERSION);
|
|
196
193
|
for (const [key, value] of Object.entries(req.params ?? {}))
|
|
197
194
|
url.searchParams.set(key, value);
|
|
198
195
|
const left = window.screenX + Math.max(0, (window.outerWidth - POPUP_WIDTH) / 2);
|
|
@@ -237,4 +234,3 @@ class OrbiClient {
|
|
|
237
234
|
});
|
|
238
235
|
}
|
|
239
236
|
}
|
|
240
|
-
exports.OrbiClient = OrbiClient;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { OrbiClient } from './client';
|
|
2
|
+
export { OrbiEIP1193Provider, createOrbiProvider } from './provider';
|
|
3
|
+
export type { OrbiProviderChain, OrbiProviderConfig } from './provider';
|
|
2
4
|
export type { ConnectedWallet, EvmSignatureResult, EvmSignResult, EvmTxParams, OrbiChain, OrbiClientConfig, OrbiNetwork, SignResult } from './types';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.OrbiClient = void 0;
|
|
4
|
-
var client_1 = require("./client");
|
|
5
|
-
Object.defineProperty(exports, "OrbiClient", { enumerable: true, get: function () { return client_1.OrbiClient; } });
|
|
1
|
+
export { OrbiClient } from './client';
|
|
2
|
+
export { OrbiEIP1193Provider, createOrbiProvider } from './provider';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EIP-1193 provider for Orbi (EVM).
|
|
3
|
+
*
|
|
4
|
+
* Wraps OrbiClient so any standard EVM tooling — wagmi, ethers, viem,
|
|
5
|
+
* RainbowKit — can talk to an Orbi passkey wallet through the universal
|
|
6
|
+
* `request({ method, params })` interface. Signing methods open the Orbi popup
|
|
7
|
+
* (where the passkey lives); read methods are proxied to the chain's RPC.
|
|
8
|
+
*/
|
|
9
|
+
import { OrbiClient } from './client';
|
|
10
|
+
import type { OrbiNetwork } from './types';
|
|
11
|
+
export interface OrbiProviderChain {
|
|
12
|
+
chainId: number;
|
|
13
|
+
rpcUrl: string;
|
|
14
|
+
}
|
|
15
|
+
export interface OrbiProviderConfig {
|
|
16
|
+
/** EVM chains this provider can serve, each with a JSON-RPC URL. */
|
|
17
|
+
chains: OrbiProviderChain[];
|
|
18
|
+
/** Active chain on construction. Defaults to the first chain. */
|
|
19
|
+
defaultChainId?: number;
|
|
20
|
+
network?: OrbiNetwork;
|
|
21
|
+
/** Reuse an existing client (and its session); one is created otherwise. */
|
|
22
|
+
client?: OrbiClient;
|
|
23
|
+
}
|
|
24
|
+
interface RequestArgs {
|
|
25
|
+
method: string;
|
|
26
|
+
params?: unknown[] | Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
type Listener = (...args: unknown[]) => void;
|
|
29
|
+
export declare class OrbiEIP1193Provider {
|
|
30
|
+
/** Lets dApps detect Orbi specifically (à la `isMetaMask`). */
|
|
31
|
+
readonly isOrbi = true;
|
|
32
|
+
private client;
|
|
33
|
+
private chains;
|
|
34
|
+
private chainId;
|
|
35
|
+
private listeners;
|
|
36
|
+
constructor(config: OrbiProviderConfig);
|
|
37
|
+
on(event: string, fn: Listener): this;
|
|
38
|
+
removeListener(event: string, fn: Listener): this;
|
|
39
|
+
private emit;
|
|
40
|
+
private currentAccounts;
|
|
41
|
+
request(args: RequestArgs): Promise<unknown>;
|
|
42
|
+
private rpc;
|
|
43
|
+
/** Convenience: forget the cached session (next eth_requestAccounts re-prompts). */
|
|
44
|
+
disconnect(): void;
|
|
45
|
+
}
|
|
46
|
+
export declare function createOrbiProvider(config: OrbiProviderConfig): OrbiEIP1193Provider;
|
|
47
|
+
export {};
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EIP-1193 provider for Orbi (EVM).
|
|
3
|
+
*
|
|
4
|
+
* Wraps OrbiClient so any standard EVM tooling — wagmi, ethers, viem,
|
|
5
|
+
* RainbowKit — can talk to an Orbi passkey wallet through the universal
|
|
6
|
+
* `request({ method, params })` interface. Signing methods open the Orbi popup
|
|
7
|
+
* (where the passkey lives); read methods are proxied to the chain's RPC.
|
|
8
|
+
*/
|
|
9
|
+
import { OrbiClient } from './client';
|
|
10
|
+
function providerError(code, message) {
|
|
11
|
+
return Object.assign(new Error(message), { code });
|
|
12
|
+
}
|
|
13
|
+
// SDK popup rejections → EIP-1193's standard "user rejected" code (4001).
|
|
14
|
+
function mapRejection(err) {
|
|
15
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
16
|
+
if (/cancel|closed|reject/i.test(msg))
|
|
17
|
+
throw providerError(4001, 'User rejected the request');
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
20
|
+
const isAddress = (v) => typeof v === 'string' && /^0x[0-9a-fA-F]{40}$/.test(v);
|
|
21
|
+
const toHexNum = (n) => '0x' + n.toString(16);
|
|
22
|
+
export class OrbiEIP1193Provider {
|
|
23
|
+
constructor(config) {
|
|
24
|
+
/** Lets dApps detect Orbi specifically (à la `isMetaMask`). */
|
|
25
|
+
this.isOrbi = true;
|
|
26
|
+
this.listeners = {};
|
|
27
|
+
if (!config.chains?.length)
|
|
28
|
+
throw new Error('OrbiProvider requires at least one chain');
|
|
29
|
+
this.chains = new Map(config.chains.map((c) => [c.chainId, c.rpcUrl]));
|
|
30
|
+
this.chainId = config.defaultChainId ?? config.chains[0].chainId;
|
|
31
|
+
if (!this.chains.has(this.chainId))
|
|
32
|
+
throw new Error(`No RPC configured for chain ${this.chainId}`);
|
|
33
|
+
this.client =
|
|
34
|
+
config.client ?? new OrbiClient({ network: config.network, chain: 'botchain', chainId: this.chainId });
|
|
35
|
+
}
|
|
36
|
+
// ── EIP-1193 events ──────────────────────────────────────────────────────────
|
|
37
|
+
on(event, fn) { (this.listeners[event] ??= []).push(fn); return this; }
|
|
38
|
+
removeListener(event, fn) {
|
|
39
|
+
this.listeners[event] = (this.listeners[event] ?? []).filter((l) => l !== fn);
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
emit(event, ...args) {
|
|
43
|
+
(this.listeners[event] ?? []).forEach((l) => l(...args));
|
|
44
|
+
}
|
|
45
|
+
currentAccounts() {
|
|
46
|
+
const addr = this.client.getAddress();
|
|
47
|
+
return addr && this.client.getChain() === 'botchain' ? [addr] : [];
|
|
48
|
+
}
|
|
49
|
+
// ── EIP-1193 request ─────────────────────────────────────────────────────────
|
|
50
|
+
async request(args) {
|
|
51
|
+
const { method } = args;
|
|
52
|
+
const params = (Array.isArray(args.params) ? args.params : []);
|
|
53
|
+
switch (method) {
|
|
54
|
+
case 'eth_requestAccounts': {
|
|
55
|
+
try {
|
|
56
|
+
const { walletAddress } = await this.client.connect({ chain: 'botchain' });
|
|
57
|
+
this.emit('connect', { chainId: toHexNum(this.chainId) });
|
|
58
|
+
this.emit('accountsChanged', [walletAddress]);
|
|
59
|
+
return [walletAddress];
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
return mapRejection(err);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
case 'eth_accounts':
|
|
66
|
+
return this.currentAccounts();
|
|
67
|
+
case 'eth_chainId':
|
|
68
|
+
return toHexNum(this.chainId);
|
|
69
|
+
case 'net_version':
|
|
70
|
+
return String(this.chainId);
|
|
71
|
+
case 'wallet_getPermissions':
|
|
72
|
+
case 'wallet_requestPermissions':
|
|
73
|
+
return [{ parentCapability: 'eth_accounts' }];
|
|
74
|
+
case 'wallet_switchEthereumChain': {
|
|
75
|
+
const target = parseInt(params[0]?.chainId, 16);
|
|
76
|
+
if (!this.chains.has(target)) {
|
|
77
|
+
throw providerError(4902, `Chain ${target} not configured in Orbi provider`);
|
|
78
|
+
}
|
|
79
|
+
this.chainId = target;
|
|
80
|
+
this.emit('chainChanged', toHexNum(target));
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
case 'wallet_addEthereumChain': {
|
|
84
|
+
const target = parseInt(params[0]?.chainId, 16);
|
|
85
|
+
if (!this.chains.has(target))
|
|
86
|
+
throw providerError(4902, `Chain ${target} not supported by Orbi`);
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
case 'eth_sendTransaction': {
|
|
90
|
+
const tx = (params[0] ?? {});
|
|
91
|
+
try {
|
|
92
|
+
const { txHash } = await this.client.signEvmTransaction({
|
|
93
|
+
to: tx.to,
|
|
94
|
+
value: tx.value ? BigInt(tx.value).toString() : undefined,
|
|
95
|
+
data: tx.data,
|
|
96
|
+
gas: tx.gas ? BigInt(tx.gas).toString() : undefined,
|
|
97
|
+
chainId: this.chainId,
|
|
98
|
+
});
|
|
99
|
+
return txHash;
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
return mapRejection(err);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
case 'personal_sign': {
|
|
106
|
+
// params: [message, address] (order varies by dApp — detect the address)
|
|
107
|
+
const message = (isAddress(params[0]) ? params[1] : params[0]);
|
|
108
|
+
try {
|
|
109
|
+
const { signature } = await this.client.signMessage({ message, chainId: this.chainId });
|
|
110
|
+
return signature;
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
return mapRejection(err);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
case 'eth_signTypedData_v4': {
|
|
117
|
+
// params: [address, typedData]
|
|
118
|
+
const raw = (isAddress(params[0]) ? params[1] : params[0]);
|
|
119
|
+
const typedData = typeof raw === 'string' ? JSON.parse(raw) : raw;
|
|
120
|
+
try {
|
|
121
|
+
const { signature } = await this.client.signTypedData({ typedData, chainId: this.chainId });
|
|
122
|
+
return signature;
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
return mapRejection(err);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
case 'eth_sign':
|
|
129
|
+
case 'eth_signTypedData':
|
|
130
|
+
case 'eth_signTypedData_v3':
|
|
131
|
+
throw providerError(4200, `${method} is not supported — use personal_sign or eth_signTypedData_v4`);
|
|
132
|
+
// Everything else (eth_call, eth_getBalance, eth_estimateGas,
|
|
133
|
+
// eth_getTransactionReceipt, eth_blockNumber, …) is a read — proxy to RPC.
|
|
134
|
+
default:
|
|
135
|
+
return this.rpc(method, params);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async rpc(method, params) {
|
|
139
|
+
const url = this.chains.get(this.chainId);
|
|
140
|
+
if (!url)
|
|
141
|
+
throw providerError(4901, `No RPC for chain ${this.chainId}`);
|
|
142
|
+
const res = await fetch(url, {
|
|
143
|
+
method: 'POST',
|
|
144
|
+
headers: { 'content-type': 'application/json' },
|
|
145
|
+
body: JSON.stringify({ jsonrpc: '2.0', id: Date.now(), method, params }),
|
|
146
|
+
});
|
|
147
|
+
const json = (await res.json());
|
|
148
|
+
if (json.error)
|
|
149
|
+
throw providerError(json.error.code ?? -32000, json.error.message ?? 'RPC error');
|
|
150
|
+
return json.result;
|
|
151
|
+
}
|
|
152
|
+
/** Convenience: forget the cached session (next eth_requestAccounts re-prompts). */
|
|
153
|
+
disconnect() {
|
|
154
|
+
this.client.disconnect();
|
|
155
|
+
this.emit('disconnect');
|
|
156
|
+
this.emit('accountsChanged', []);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
export function createOrbiProvider(config) {
|
|
160
|
+
return new OrbiEIP1193Provider(config);
|
|
161
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RainbowKit wallet for Orbi (Layer D).
|
|
3
|
+
*
|
|
4
|
+
* Drop Orbi into any RainbowKit dApp's wallet list:
|
|
5
|
+
*
|
|
6
|
+
* import { orbiWallet } from '@orbi-wallet/sdk/rainbowkit';
|
|
7
|
+
* const connectors = connectorsForWallets(
|
|
8
|
+
* [{ groupName: 'Recommended', wallets: [orbiWallet()] }],
|
|
9
|
+
* { appName, projectId },
|
|
10
|
+
* );
|
|
11
|
+
*
|
|
12
|
+
* Requires `wagmi`, `viem`, and `@rainbow-me/rainbowkit` as peer dependencies.
|
|
13
|
+
*/
|
|
14
|
+
import type { Wallet } from '@rainbow-me/rainbowkit';
|
|
15
|
+
import { type OrbiConnectorParams } from './wagmi';
|
|
16
|
+
export declare function orbiWallet(params?: OrbiConnectorParams): Wallet;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RainbowKit wallet for Orbi (Layer D).
|
|
3
|
+
*
|
|
4
|
+
* Drop Orbi into any RainbowKit dApp's wallet list:
|
|
5
|
+
*
|
|
6
|
+
* import { orbiWallet } from '@orbi-wallet/sdk/rainbowkit';
|
|
7
|
+
* const connectors = connectorsForWallets(
|
|
8
|
+
* [{ groupName: 'Recommended', wallets: [orbiWallet()] }],
|
|
9
|
+
* { appName, projectId },
|
|
10
|
+
* );
|
|
11
|
+
*
|
|
12
|
+
* Requires `wagmi`, `viem`, and `@rainbow-me/rainbowkit` as peer dependencies.
|
|
13
|
+
*/
|
|
14
|
+
import { createConnector } from 'wagmi';
|
|
15
|
+
import { orbiConnectorImpl } from './wagmi';
|
|
16
|
+
const ICON_URL = 'https://keys.orbiwallet.xyz/Orbi%20Icon.png';
|
|
17
|
+
export function orbiWallet(params = {}) {
|
|
18
|
+
return {
|
|
19
|
+
id: 'orbi',
|
|
20
|
+
name: 'Orbi',
|
|
21
|
+
iconUrl: ICON_URL,
|
|
22
|
+
iconBackground: '#020817',
|
|
23
|
+
// Passkey wallet — nothing to install; always available in-browser.
|
|
24
|
+
installed: true,
|
|
25
|
+
createConnector: (walletDetails) => createConnector((config) => ({
|
|
26
|
+
...orbiConnectorImpl(params)(config),
|
|
27
|
+
...walletDetails,
|
|
28
|
+
})),
|
|
29
|
+
};
|
|
30
|
+
}
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const SDK_NAME = "@orbi-wallet/sdk";
|
|
2
|
-
export declare const SDK_VERSION = "0.
|
|
2
|
+
export declare const SDK_VERSION = "0.2.0";
|
package/dist/version.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SDK_VERSION = exports.SDK_NAME = void 0;
|
|
4
1
|
// Generated by scripts/generate-version.js from package.json — do not edit.
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
export const SDK_NAME = "@orbi-wallet/sdk";
|
|
3
|
+
export const SDK_VERSION = "0.2.0";
|
package/dist/wagmi.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wagmi connector for Orbi (Layer C).
|
|
3
|
+
*
|
|
4
|
+
* Wraps the Orbi EIP-1193 provider as a wagmi v2 connector so Orbi can be used
|
|
5
|
+
* with the entire wagmi/viem ecosystem — `writeContract`, `readContract`,
|
|
6
|
+
* SIWE, chain switching — with no Orbi-specific code in the dApp. ABI encoding
|
|
7
|
+
* is handled by viem/wagmi; the encoded calldata flows to Orbi's popup via the
|
|
8
|
+
* provider's `eth_sendTransaction`.
|
|
9
|
+
*
|
|
10
|
+
* Requires `wagmi` and `viem` as peer dependencies (a wagmi dApp already has them).
|
|
11
|
+
*/
|
|
12
|
+
import { type CreateConnectorFn } from 'wagmi';
|
|
13
|
+
import { type OrbiProviderChain } from './provider';
|
|
14
|
+
import type { OrbiNetwork } from './types';
|
|
15
|
+
export interface OrbiConnectorParams {
|
|
16
|
+
/** Explicit chainId→rpcUrl list. Defaults to the wagmi config's chains. */
|
|
17
|
+
chains?: OrbiProviderChain[];
|
|
18
|
+
network?: OrbiNetwork;
|
|
19
|
+
}
|
|
20
|
+
export declare function orbiConnectorImpl(params?: OrbiConnectorParams): CreateConnectorFn;
|
|
21
|
+
/** Standalone wagmi connector (for dApps not using RainbowKit). */
|
|
22
|
+
export declare function orbiConnector(params?: OrbiConnectorParams): CreateConnectorFn;
|
package/dist/wagmi.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wagmi connector for Orbi (Layer C).
|
|
3
|
+
*
|
|
4
|
+
* Wraps the Orbi EIP-1193 provider as a wagmi v2 connector so Orbi can be used
|
|
5
|
+
* with the entire wagmi/viem ecosystem — `writeContract`, `readContract`,
|
|
6
|
+
* SIWE, chain switching — with no Orbi-specific code in the dApp. ABI encoding
|
|
7
|
+
* is handled by viem/wagmi; the encoded calldata flows to Orbi's popup via the
|
|
8
|
+
* provider's `eth_sendTransaction`.
|
|
9
|
+
*
|
|
10
|
+
* Requires `wagmi` and `viem` as peer dependencies (a wagmi dApp already has them).
|
|
11
|
+
*/
|
|
12
|
+
import { createConnector } from 'wagmi';
|
|
13
|
+
import { getAddress } from 'viem';
|
|
14
|
+
import { OrbiEIP1193Provider } from './provider';
|
|
15
|
+
// Inner factory: `(config) => connectorObject`. Exported separately because
|
|
16
|
+
// RainbowKit composes it with its own wallet details (see rainbowkit.ts).
|
|
17
|
+
export function orbiConnectorImpl(params = {}) {
|
|
18
|
+
return ((config) => {
|
|
19
|
+
let provider;
|
|
20
|
+
const getProvider = async () => {
|
|
21
|
+
if (!provider) {
|
|
22
|
+
const chains = params.chains ??
|
|
23
|
+
config.chains.map((c) => ({ chainId: c.id, rpcUrl: c.rpcUrls.default.http[0] }));
|
|
24
|
+
provider = new OrbiEIP1193Provider({ chains, network: params.network });
|
|
25
|
+
}
|
|
26
|
+
return provider;
|
|
27
|
+
};
|
|
28
|
+
const getChainId = async () => {
|
|
29
|
+
const p = await getProvider();
|
|
30
|
+
return Number((await p.request({ method: 'eth_chainId' })));
|
|
31
|
+
};
|
|
32
|
+
const getAccounts = async () => {
|
|
33
|
+
const p = await getProvider();
|
|
34
|
+
const accounts = (await p.request({ method: 'eth_accounts' }));
|
|
35
|
+
return accounts.map((a) => getAddress(a));
|
|
36
|
+
};
|
|
37
|
+
const switchChain = async ({ chainId }) => {
|
|
38
|
+
const p = await getProvider();
|
|
39
|
+
await p.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: `0x${chainId.toString(16)}` }] });
|
|
40
|
+
const chain = config.chains.find((c) => c.id === chainId);
|
|
41
|
+
if (!chain)
|
|
42
|
+
throw new Error(`Chain ${chainId} not configured`);
|
|
43
|
+
config.emitter.emit('change', { chainId });
|
|
44
|
+
return chain;
|
|
45
|
+
};
|
|
46
|
+
const onAccountsChanged = (accounts) => {
|
|
47
|
+
if (accounts.length === 0)
|
|
48
|
+
config.emitter.emit('disconnect');
|
|
49
|
+
else
|
|
50
|
+
config.emitter.emit('change', { accounts: accounts.map((a) => getAddress(a)) });
|
|
51
|
+
};
|
|
52
|
+
const onChainChanged = (chain) => config.emitter.emit('change', { chainId: Number(chain) });
|
|
53
|
+
const onDisconnect = () => config.emitter.emit('disconnect');
|
|
54
|
+
return {
|
|
55
|
+
id: 'orbi',
|
|
56
|
+
name: 'Orbi',
|
|
57
|
+
type: 'orbi',
|
|
58
|
+
async connect({ chainId } = {}) {
|
|
59
|
+
const p = await getProvider();
|
|
60
|
+
const accounts = (await p.request({ method: 'eth_requestAccounts' })).map((a) => getAddress(a));
|
|
61
|
+
p.on('accountsChanged', onAccountsChanged);
|
|
62
|
+
p.on('chainChanged', onChainChanged);
|
|
63
|
+
p.on('disconnect', onDisconnect);
|
|
64
|
+
let id = await getChainId();
|
|
65
|
+
if (chainId && chainId !== id)
|
|
66
|
+
id = (await switchChain({ chainId })).id;
|
|
67
|
+
return { accounts, chainId: id };
|
|
68
|
+
},
|
|
69
|
+
async disconnect() {
|
|
70
|
+
const p = await getProvider();
|
|
71
|
+
p.removeListener('accountsChanged', onAccountsChanged);
|
|
72
|
+
p.removeListener('chainChanged', onChainChanged);
|
|
73
|
+
p.removeListener('disconnect', onDisconnect);
|
|
74
|
+
p.disconnect();
|
|
75
|
+
},
|
|
76
|
+
getAccounts,
|
|
77
|
+
getChainId,
|
|
78
|
+
getProvider,
|
|
79
|
+
switchChain,
|
|
80
|
+
async isAuthorized() {
|
|
81
|
+
try {
|
|
82
|
+
return (await getAccounts()).length > 0;
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
onAccountsChanged,
|
|
89
|
+
onChainChanged,
|
|
90
|
+
onDisconnect,
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/** Standalone wagmi connector (for dApps not using RainbowKit). */
|
|
95
|
+
export function orbiConnector(params = {}) {
|
|
96
|
+
return createConnector(orbiConnectorImpl(params));
|
|
97
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orbi-wallet/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Orbi Smart Wallet SDK — connect any Stellar or
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Orbi Smart Wallet SDK — connect any Stellar or EVM dApp to Orbi passkey wallets",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
|
|
10
|
+
"./provider": { "types": "./dist/provider.d.ts", "default": "./dist/provider.js" },
|
|
11
|
+
"./wagmi": { "types": "./dist/wagmi.d.ts", "default": "./dist/wagmi.js" },
|
|
12
|
+
"./rainbowkit": { "types": "./dist/rainbowkit.d.ts", "default": "./dist/rainbowkit.js" }
|
|
13
|
+
},
|
|
7
14
|
"files": [
|
|
8
15
|
"dist"
|
|
9
16
|
],
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@rainbow-me/rainbowkit": "^2",
|
|
19
|
+
"viem": "^2",
|
|
20
|
+
"wagmi": "^2"
|
|
21
|
+
},
|
|
22
|
+
"peerDependenciesMeta": {
|
|
23
|
+
"@rainbow-me/rainbowkit": { "optional": true },
|
|
24
|
+
"viem": { "optional": true },
|
|
25
|
+
"wagmi": { "optional": true }
|
|
26
|
+
},
|
|
10
27
|
"license": "MIT",
|
|
11
28
|
"keywords": [
|
|
12
29
|
"stellar",
|
|
@@ -23,13 +40,16 @@
|
|
|
23
40
|
"url": "https://github.com/Novablitz404/orbi-wallet-sdk/issues"
|
|
24
41
|
},
|
|
25
42
|
"scripts": {
|
|
26
|
-
"prebuild": "node scripts/generate-version.
|
|
43
|
+
"prebuild": "node scripts/generate-version.cjs",
|
|
27
44
|
"build": "tsc",
|
|
28
|
-
"predev": "node scripts/generate-version.
|
|
45
|
+
"predev": "node scripts/generate-version.cjs",
|
|
29
46
|
"dev": "tsc --watch"
|
|
30
47
|
},
|
|
31
48
|
"devDependencies": {
|
|
49
|
+
"@rainbow-me/rainbowkit": "^2.2.11",
|
|
32
50
|
"@types/node": "^20.14.2",
|
|
33
|
-
"typescript": "^5.5.2"
|
|
51
|
+
"typescript": "^5.5.2",
|
|
52
|
+
"viem": "^2.52.2",
|
|
53
|
+
"wagmi": "^2.19.5"
|
|
34
54
|
}
|
|
35
55
|
}
|