@orbi-wallet/sdk 0.2.1 → 0.2.2
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.d.ts +1 -27
- package/dist/client.js +5 -95
- package/dist/index.d.ts +2 -4
- package/dist/index.js +1 -2
- package/dist/types.d.ts +2 -25
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +8 -20
- package/dist/provider.d.ts +0 -47
- package/dist/provider.js +0 -161
- package/dist/rainbowkit.d.ts +0 -16
- package/dist/rainbowkit.js +0 -33
- package/dist/wagmi.d.ts +0 -22
- package/dist/wagmi.js +0 -97
package/dist/client.d.ts
CHANGED
|
@@ -8,11 +8,10 @@
|
|
|
8
8
|
* const { walletAddress } = await orbi.connect();
|
|
9
9
|
* const { signedXdr } = await orbi.signTransaction({ xdr });
|
|
10
10
|
*/
|
|
11
|
-
import type { ConnectedWallet,
|
|
11
|
+
import type { ConnectedWallet, OrbiChain, OrbiClientConfig, SignResult } from './types.js';
|
|
12
12
|
export declare class OrbiClient {
|
|
13
13
|
private network;
|
|
14
14
|
private chain;
|
|
15
|
-
private chainId?;
|
|
16
15
|
constructor(config?: OrbiClientConfig);
|
|
17
16
|
/** Wallet address from a previous `connect()`, restored from local storage. */
|
|
18
17
|
getAddress(): string | null;
|
|
@@ -40,30 +39,5 @@ export declare class OrbiClient {
|
|
|
40
39
|
xdr: string;
|
|
41
40
|
walletAddress?: string;
|
|
42
41
|
}): Promise<SignResult>;
|
|
43
|
-
/**
|
|
44
|
-
* Review and approve an EVM transaction — native transfer or contract call.
|
|
45
|
-
* Signing and submission happen inside the Orbi popup (where the passkey
|
|
46
|
-
* lives), so the dApp never touches a key. Returns the tx hash.
|
|
47
|
-
* `value` is wei (decimal string); `data` is 0x calldata for contract calls.
|
|
48
|
-
*/
|
|
49
|
-
signEvmTransaction(params: EvmTxParams): Promise<EvmSignResult>;
|
|
50
|
-
/**
|
|
51
|
-
* Sign an arbitrary message (EIP-191 / personal_sign). This is what dApp
|
|
52
|
-
* login ("Sign-In With Ethereum") uses. Returns the 65-byte signature.
|
|
53
|
-
*/
|
|
54
|
-
signMessage(params: {
|
|
55
|
-
message: string;
|
|
56
|
-
chainId?: number;
|
|
57
|
-
walletAddress?: string;
|
|
58
|
-
}): Promise<EvmSignatureResult>;
|
|
59
|
-
/**
|
|
60
|
-
* Sign EIP-712 typed data (eth_signTypedData_v4) — permits, listings, etc.
|
|
61
|
-
* `typedData` is the standard { domain, types, primaryType, message } object.
|
|
62
|
-
*/
|
|
63
|
-
signTypedData(params: {
|
|
64
|
-
typedData: unknown;
|
|
65
|
-
chainId?: number;
|
|
66
|
-
walletAddress?: string;
|
|
67
|
-
}): Promise<EvmSignatureResult>;
|
|
68
42
|
private openPopup;
|
|
69
43
|
}
|
package/dist/client.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
// Generated from package.json at build time (see scripts/generate-version.js)
|
|
12
12
|
// — package.json stays the single source of truth for name/version.
|
|
13
|
-
import { SDK_NAME, SDK_VERSION } from './version';
|
|
13
|
+
import { SDK_NAME, SDK_VERSION } from './version.js';
|
|
14
14
|
const KEYS_URL = 'https://keys.orbiwallet.xyz';
|
|
15
15
|
const KEYS_ORIGIN = new URL(KEYS_URL).origin;
|
|
16
16
|
const SESSION_KEY = 'orbi_session';
|
|
@@ -20,7 +20,6 @@ export class OrbiClient {
|
|
|
20
20
|
constructor(config = {}) {
|
|
21
21
|
this.network = config.network ?? 'testnet';
|
|
22
22
|
this.chain = config.chain ?? 'stellar';
|
|
23
|
-
this.chainId = config.chainId;
|
|
24
23
|
}
|
|
25
24
|
// ── Session ─────────────────────────────────────────────────────────────────
|
|
26
25
|
/** Wallet address from a previous `connect()`, restored from local storage. */
|
|
@@ -52,30 +51,17 @@ export class OrbiClient {
|
|
|
52
51
|
async connect(opts = {}) {
|
|
53
52
|
const chain = opts.chain ?? this.chain;
|
|
54
53
|
const cached = this.getSession();
|
|
55
|
-
if (cached)
|
|
56
|
-
|
|
57
|
-
if (cached.chain === chain)
|
|
58
|
-
return cached;
|
|
59
|
-
// Switching chains: if a prior connect already derived this chain's
|
|
60
|
-
// address (the popup returns both at once), switch instantly with no
|
|
61
|
-
// re-prompt — just re-point the active chain/address.
|
|
62
|
-
const known = cached.addresses?.[chain];
|
|
63
|
-
if (known) {
|
|
64
|
-
const switched = { ...cached, walletAddress: known, chain };
|
|
65
|
-
localStorage.setItem(SESSION_KEY, JSON.stringify(switched));
|
|
66
|
-
return switched;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
54
|
+
if (cached)
|
|
55
|
+
return { ...cached, chain: 'stellar', addresses: { stellar: cached.walletAddress } };
|
|
69
56
|
const wallet = await this.openPopup({
|
|
70
57
|
path: '/connect',
|
|
71
|
-
params: { chain },
|
|
72
58
|
successType: 'orbi_connected',
|
|
73
59
|
mapSuccess: (msg) => ({
|
|
74
60
|
walletAddress: msg.address,
|
|
75
61
|
credentialId: msg.credentialId ?? '',
|
|
76
62
|
passkeyId: msg.passkeyId ?? '',
|
|
77
|
-
chain
|
|
78
|
-
addresses: msg.
|
|
63
|
+
chain,
|
|
64
|
+
addresses: { stellar: msg.address },
|
|
79
65
|
}),
|
|
80
66
|
});
|
|
81
67
|
localStorage.setItem(SESSION_KEY, JSON.stringify(wallet));
|
|
@@ -105,82 +91,6 @@ export class OrbiClient {
|
|
|
105
91
|
}),
|
|
106
92
|
});
|
|
107
93
|
}
|
|
108
|
-
/**
|
|
109
|
-
* Review and approve an EVM transaction — native transfer or contract call.
|
|
110
|
-
* Signing and submission happen inside the Orbi popup (where the passkey
|
|
111
|
-
* lives), so the dApp never touches a key. Returns the tx hash.
|
|
112
|
-
* `value` is wei (decimal string); `data` is 0x calldata for contract calls.
|
|
113
|
-
*/
|
|
114
|
-
signEvmTransaction(params) {
|
|
115
|
-
const walletAddress = params.walletAddress ?? this.getAddress() ?? undefined;
|
|
116
|
-
const chainId = params.chainId ?? this.chainId;
|
|
117
|
-
if (chainId === undefined)
|
|
118
|
-
throw new Error('chainId is required for EVM transactions');
|
|
119
|
-
return this.openPopup({
|
|
120
|
-
path: '/sign',
|
|
121
|
-
params: {
|
|
122
|
-
chain: 'botchain',
|
|
123
|
-
evmAction: 'tx',
|
|
124
|
-
chainId: String(chainId),
|
|
125
|
-
to: params.to,
|
|
126
|
-
...(params.value ? { value: params.value } : {}),
|
|
127
|
-
...(params.data ? { data: params.data } : {}),
|
|
128
|
-
...(params.gas ? { gas: params.gas } : {}),
|
|
129
|
-
...(walletAddress ? { walletAddress } : {}),
|
|
130
|
-
},
|
|
131
|
-
successType: 'orbi_evm_sent',
|
|
132
|
-
mapSuccess: (msg) => ({
|
|
133
|
-
txHash: msg.txHash,
|
|
134
|
-
walletAddress: msg.walletAddress,
|
|
135
|
-
}),
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Sign an arbitrary message (EIP-191 / personal_sign). This is what dApp
|
|
140
|
-
* login ("Sign-In With Ethereum") uses. Returns the 65-byte signature.
|
|
141
|
-
*/
|
|
142
|
-
signMessage(params) {
|
|
143
|
-
const walletAddress = params.walletAddress ?? this.getAddress() ?? undefined;
|
|
144
|
-
const chainId = params.chainId ?? this.chainId;
|
|
145
|
-
return this.openPopup({
|
|
146
|
-
path: '/sign',
|
|
147
|
-
params: {
|
|
148
|
-
chain: 'botchain',
|
|
149
|
-
evmAction: 'message',
|
|
150
|
-
message: params.message,
|
|
151
|
-
...(chainId !== undefined ? { chainId: String(chainId) } : {}),
|
|
152
|
-
...(walletAddress ? { walletAddress } : {}),
|
|
153
|
-
},
|
|
154
|
-
successType: 'orbi_evm_signed',
|
|
155
|
-
mapSuccess: (msg) => ({
|
|
156
|
-
signature: msg.signature,
|
|
157
|
-
walletAddress: msg.walletAddress,
|
|
158
|
-
}),
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Sign EIP-712 typed data (eth_signTypedData_v4) — permits, listings, etc.
|
|
163
|
-
* `typedData` is the standard { domain, types, primaryType, message } object.
|
|
164
|
-
*/
|
|
165
|
-
signTypedData(params) {
|
|
166
|
-
const walletAddress = params.walletAddress ?? this.getAddress() ?? undefined;
|
|
167
|
-
const chainId = params.chainId ?? this.chainId;
|
|
168
|
-
return this.openPopup({
|
|
169
|
-
path: '/sign',
|
|
170
|
-
params: {
|
|
171
|
-
chain: 'botchain',
|
|
172
|
-
evmAction: 'typedData',
|
|
173
|
-
typedData: JSON.stringify(params.typedData),
|
|
174
|
-
...(chainId !== undefined ? { chainId: String(chainId) } : {}),
|
|
175
|
-
...(walletAddress ? { walletAddress } : {}),
|
|
176
|
-
},
|
|
177
|
-
successType: 'orbi_evm_signed',
|
|
178
|
-
mapSuccess: (msg) => ({
|
|
179
|
-
signature: msg.signature,
|
|
180
|
-
walletAddress: msg.walletAddress,
|
|
181
|
-
}),
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
94
|
// ── Popup + postMessage handshake ───────────────────────────────────────────
|
|
185
95
|
openPopup(req) {
|
|
186
96
|
if (typeof window === 'undefined') {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
export { OrbiClient } from './client';
|
|
2
|
-
export {
|
|
3
|
-
export type { OrbiProviderChain, OrbiProviderConfig } from './provider';
|
|
4
|
-
export type { ConnectedWallet, EvmSignatureResult, EvmSignResult, EvmTxParams, OrbiChain, OrbiClientConfig, OrbiNetwork, SignResult } from './types';
|
|
1
|
+
export { OrbiClient } from './client.js';
|
|
2
|
+
export type { ConnectedWallet, OrbiChain, OrbiClientConfig, OrbiNetwork, SignResult } from './types.js';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export { OrbiClient } from './client';
|
|
2
|
-
export { OrbiEIP1193Provider, createOrbiProvider } from './provider';
|
|
1
|
+
export { OrbiClient } from './client.js';
|
package/dist/types.d.ts
CHANGED
|
@@ -1,43 +1,20 @@
|
|
|
1
1
|
export type OrbiNetwork = 'testnet' | 'mainnet';
|
|
2
|
-
/** Which chain the wallet operates on.
|
|
3
|
-
export type OrbiChain = 'stellar'
|
|
2
|
+
/** Which chain the wallet operates on. Orbi is Stellar-only for now. */
|
|
3
|
+
export type OrbiChain = 'stellar';
|
|
4
4
|
export interface OrbiClientConfig {
|
|
5
5
|
/** Network the dApp is operating on. Defaults to 'testnet'. */
|
|
6
6
|
network?: OrbiNetwork;
|
|
7
7
|
/** Chain to connect on. Defaults to 'stellar'. */
|
|
8
8
|
chain?: OrbiChain;
|
|
9
|
-
/** Default EVM chainId for signing/sending (per-call override available). */
|
|
10
|
-
chainId?: number;
|
|
11
9
|
}
|
|
12
10
|
export interface ConnectedWallet {
|
|
13
11
|
walletAddress: string;
|
|
14
12
|
credentialId: string;
|
|
15
13
|
passkeyId: string;
|
|
16
14
|
chain: OrbiChain;
|
|
17
|
-
/**
|
|
18
|
-
* All per-chain addresses derived from this passkey, when the wallet
|
|
19
|
-
* provided them. Lets `connect()` switch chains without re-prompting once an
|
|
20
|
-
* address is known.
|
|
21
|
-
*/
|
|
22
15
|
addresses?: Partial<Record<OrbiChain, string>>;
|
|
23
16
|
}
|
|
24
17
|
export interface SignResult {
|
|
25
18
|
signedXdr: string;
|
|
26
19
|
walletAddress: string;
|
|
27
20
|
}
|
|
28
|
-
export interface EvmSignResult {
|
|
29
|
-
txHash: string;
|
|
30
|
-
walletAddress: string;
|
|
31
|
-
}
|
|
32
|
-
export interface EvmSignatureResult {
|
|
33
|
-
signature: string;
|
|
34
|
-
walletAddress: string;
|
|
35
|
-
}
|
|
36
|
-
export interface EvmTxParams {
|
|
37
|
-
to: string;
|
|
38
|
-
value?: string;
|
|
39
|
-
data?: string;
|
|
40
|
-
gas?: string;
|
|
41
|
-
chainId?: number;
|
|
42
|
-
walletAddress?: string;
|
|
43
|
-
}
|
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.
|
|
2
|
+
export declare const SDK_VERSION = "0.2.2";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,29 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orbi-wallet/sdk",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "Orbi
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"description": "Orbi Wallet SDK — connect Stellar dApps to Orbi passkey wallets",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
13
14
|
},
|
|
14
15
|
"files": [
|
|
15
16
|
"dist"
|
|
16
17
|
],
|
|
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
|
-
},
|
|
27
18
|
"license": "MIT",
|
|
28
19
|
"keywords": [
|
|
29
20
|
"stellar",
|
|
@@ -46,10 +37,7 @@
|
|
|
46
37
|
"dev": "tsc --watch"
|
|
47
38
|
},
|
|
48
39
|
"devDependencies": {
|
|
49
|
-
"@rainbow-me/rainbowkit": "^2.2.11",
|
|
50
40
|
"@types/node": "^20.14.2",
|
|
51
|
-
"typescript": "^5.5.2"
|
|
52
|
-
"viem": "^2.52.2",
|
|
53
|
-
"wagmi": "^2.19.5"
|
|
41
|
+
"typescript": "^5.5.2"
|
|
54
42
|
}
|
|
55
43
|
}
|
package/dist/provider.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/rainbowkit.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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;
|
package/dist/rainbowkit.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
// Returns a RainbowKit CreateWalletFn (`wallets: [orbiWallet()]`). RainbowKit
|
|
18
|
-
// calls it with its own wallet params, which Orbi doesn't need (no
|
|
19
|
-
// WalletConnect) — the connector derives its chains from the wagmi config.
|
|
20
|
-
export function orbiWallet(params = {}) {
|
|
21
|
-
return () => ({
|
|
22
|
-
id: 'orbi',
|
|
23
|
-
name: 'Orbi',
|
|
24
|
-
iconUrl: ICON_URL,
|
|
25
|
-
iconBackground: '#020817',
|
|
26
|
-
// Passkey wallet — nothing to install; always available in-browser.
|
|
27
|
-
installed: true,
|
|
28
|
-
createConnector: (walletDetails) => createConnector((config) => ({
|
|
29
|
-
...orbiConnectorImpl(params)(config),
|
|
30
|
-
...walletDetails,
|
|
31
|
-
})),
|
|
32
|
-
});
|
|
33
|
-
}
|
package/dist/wagmi.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
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
|
-
}
|