@orbi-wallet/sdk 0.1.4 → 0.2.1
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.js +2 -8
- package/dist/provider.js +5 -10
- package/dist/rainbowkit.d.ts +16 -0
- package/dist/rainbowkit.js +33 -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.js
CHANGED
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.createOrbiProvider = exports.OrbiEIP1193Provider = exports.OrbiClient = void 0;
|
|
4
|
-
var client_1 = require("./client");
|
|
5
|
-
Object.defineProperty(exports, "OrbiClient", { enumerable: true, get: function () { return client_1.OrbiClient; } });
|
|
6
|
-
var provider_1 = require("./provider");
|
|
7
|
-
Object.defineProperty(exports, "OrbiEIP1193Provider", { enumerable: true, get: function () { return provider_1.OrbiEIP1193Provider; } });
|
|
8
|
-
Object.defineProperty(exports, "createOrbiProvider", { enumerable: true, get: function () { return provider_1.createOrbiProvider; } });
|
|
1
|
+
export { OrbiClient } from './client';
|
|
2
|
+
export { OrbiEIP1193Provider, createOrbiProvider } from './provider';
|
package/dist/provider.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* EIP-1193 provider for Orbi (EVM).
|
|
4
3
|
*
|
|
@@ -7,10 +6,7 @@
|
|
|
7
6
|
* `request({ method, params })` interface. Signing methods open the Orbi popup
|
|
8
7
|
* (where the passkey lives); read methods are proxied to the chain's RPC.
|
|
9
8
|
*/
|
|
10
|
-
|
|
11
|
-
exports.OrbiEIP1193Provider = void 0;
|
|
12
|
-
exports.createOrbiProvider = createOrbiProvider;
|
|
13
|
-
const client_1 = require("./client");
|
|
9
|
+
import { OrbiClient } from './client';
|
|
14
10
|
function providerError(code, message) {
|
|
15
11
|
return Object.assign(new Error(message), { code });
|
|
16
12
|
}
|
|
@@ -23,7 +19,7 @@ function mapRejection(err) {
|
|
|
23
19
|
}
|
|
24
20
|
const isAddress = (v) => typeof v === 'string' && /^0x[0-9a-fA-F]{40}$/.test(v);
|
|
25
21
|
const toHexNum = (n) => '0x' + n.toString(16);
|
|
26
|
-
class OrbiEIP1193Provider {
|
|
22
|
+
export class OrbiEIP1193Provider {
|
|
27
23
|
constructor(config) {
|
|
28
24
|
/** Lets dApps detect Orbi specifically (à la `isMetaMask`). */
|
|
29
25
|
this.isOrbi = true;
|
|
@@ -35,10 +31,10 @@ class OrbiEIP1193Provider {
|
|
|
35
31
|
if (!this.chains.has(this.chainId))
|
|
36
32
|
throw new Error(`No RPC configured for chain ${this.chainId}`);
|
|
37
33
|
this.client =
|
|
38
|
-
config.client ?? new
|
|
34
|
+
config.client ?? new OrbiClient({ network: config.network, chain: 'botchain', chainId: this.chainId });
|
|
39
35
|
}
|
|
40
36
|
// ── EIP-1193 events ──────────────────────────────────────────────────────────
|
|
41
|
-
on(event, fn) {
|
|
37
|
+
on(event, fn) { (this.listeners[event] ??= []).push(fn); return this; }
|
|
42
38
|
removeListener(event, fn) {
|
|
43
39
|
this.listeners[event] = (this.listeners[event] ?? []).filter((l) => l !== fn);
|
|
44
40
|
return this;
|
|
@@ -160,7 +156,6 @@ class OrbiEIP1193Provider {
|
|
|
160
156
|
this.emit('accountsChanged', []);
|
|
161
157
|
}
|
|
162
158
|
}
|
|
163
|
-
|
|
164
|
-
function createOrbiProvider(config) {
|
|
159
|
+
export function createOrbiProvider(config) {
|
|
165
160
|
return new OrbiEIP1193Provider(config);
|
|
166
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,33 @@
|
|
|
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/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.1
|
|
2
|
+
export declare const SDK_VERSION = "0.2.1";
|
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.1";
|
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.1
|
|
4
|
-
"description": "Orbi Smart Wallet SDK — connect any Stellar or
|
|
3
|
+
"version": "0.2.1",
|
|
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
|
}
|