@xrpl-wallet-kit/adapter-otsu 0.1.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/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # @xrpl-wallet-kit/adapter-otsu
2
+
3
+ Otsu Wallet adapter for [XRPL Wallet Kit](https://github.com/XRPDomains/xrpl-wallet-kit).
4
+
5
+ Otsu is an MV3 browser extension wallet for the XRP Ledger. It supports mainnet, testnet, and devnet, and provides granular dApp permission scopes plus transaction simulation with risk scanning before user approval.
6
+
7
+ - **Extension inject:** `window.xrpl` with `isOtsu = true`
8
+ - **Networks:** mainnet · testnet · devnet
9
+ - **Capabilities:** connect · disconnect · signMessage · signTransaction · signAndSubmit
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install @xrpl-wallet-kit/adapter-otsu
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### With `createWalletKit` (recommended)
20
+
21
+ ```ts
22
+ import { createWalletKit } from "@xrpl-wallet-kit/client";
23
+ import { createOtsuAdapter } from "@xrpl-wallet-kit/adapter-otsu";
24
+
25
+ const kit = createWalletKit({
26
+ adapters: [createOtsuAdapter()],
27
+ modal: true,
28
+ connectButton: "#connect-btn",
29
+ });
30
+ ```
31
+
32
+ ### With `WalletManager` directly
33
+
34
+ ```ts
35
+ import { WalletManager } from "@xrpl-wallet-kit/core";
36
+ import { createOtsuAdapter } from "@xrpl-wallet-kit/adapter-otsu";
37
+
38
+ const manager = new WalletManager({
39
+ adapters: [createOtsuAdapter()],
40
+ });
41
+
42
+ const result = await manager.connect("otsu");
43
+ console.log("Connected:", result.account.address);
44
+ ```
45
+
46
+ ### Auto-reconnect
47
+
48
+ ```ts
49
+ const kit = createWalletKit({
50
+ adapters: [createOtsuAdapter()],
51
+ autoReconnect: true,
52
+ storage: "localStorage",
53
+ });
54
+ ```
55
+
56
+ `restoreSession` checks `provider.isConnected()` before attempting to restore; a disconnected or locked extension will cleanly return `null`.
57
+
58
+ ## Provider injection
59
+
60
+ The adapter reads `window.xrpl.isOtsu`. No npm SDK dependency is required.
61
+
62
+ ```ts
63
+ // Type declaration included in the package:
64
+ declare global {
65
+ interface Window {
66
+ xrpl?: OtsuProvider;
67
+ }
68
+ }
69
+ ```
70
+
71
+ ## Testing
72
+
73
+ Pass a mock provider via `options.provider`:
74
+
75
+ ```ts
76
+ import { OtsuAdapter, OtsuProvider } from "@xrpl-wallet-kit/adapter-otsu";
77
+ import { assertWalletAdapter } from "@xrpl-wallet-kit/core";
78
+
79
+ const mock: OtsuProvider = {
80
+ isOtsu: true,
81
+ isConnected: () => false,
82
+ connect: async () => ({ address: "rTest..." }),
83
+ disconnect: async () => {},
84
+ getAddress: async () => ({ address: "rTest..." }),
85
+ getNetwork: async () => ({ network: "testnet" }),
86
+ signTransaction: async (tx) => ({ tx_blob: "BLOB", hash: "HASH" }),
87
+ signAndSubmit: async (tx) => ({ tx_blob: "BLOB", hash: "HASH" }),
88
+ signMessage: async (msg) => ({ signature: "SIG" }),
89
+ on: () => {},
90
+ off: () => {},
91
+ };
92
+
93
+ const adapter = new OtsuAdapter({ provider: mock });
94
+ assertWalletAdapter(adapter); // throws if contract is violated
95
+ ```
96
+
97
+ ## Wire-up (coder leader)
98
+
99
+ > **Note:** This package is a standalone adapter. Wiring it into `@xrpl-wallet-kit/client` and `@xrpl-wallet-kit/browser` is the responsibility of the project maintainer.
100
+
101
+ Steps:
102
+ 1. Add `{ "path": "./packages/adapters/otsu" }` to root `tsconfig.json` references.
103
+ 2. Import `createOtsuAdapter` in `packages/client/src/index.ts` and add it to `createDefaultAdapters()`.
104
+ 3. Add `"otsu"` to the `WalletKitAdapterId` union in `client/src/index.ts`.
105
+ 4. Run `npm run build && npm run typecheck` from the repo root.
106
+
107
+ ## Wallet homepage
108
+
109
+ https://github.com/RomThpt/otsu-wallet
110
+
111
+ ## License
112
+
113
+ MIT
@@ -0,0 +1,154 @@
1
+ import { BaseWalletAdapter } from "@xrpl-wallet-kit/core";
2
+ import type { ConnectOptions, ConnectResult, SignAndSubmitRequest, SignMessageRequest, SignTransactionRequest, WalletCapabilities, WalletMetadata, WalletSession } from "@xrpl-wallet-kit/core";
3
+ /**
4
+ * Otsu Wallet provider interface injected at window.xrpl by the MV3 extension.
5
+ *
6
+ * The extension injects this object via content script bridging.
7
+ * dApps interact with the wallet through postMessage under the hood.
8
+ */
9
+ export interface OtsuProvider {
10
+ /** Identifies this provider as Otsu Wallet */
11
+ isOtsu: true;
12
+ /** Returns true when a dApp connection is already active */
13
+ isConnected(): boolean;
14
+ /**
15
+ * Request a new dApp connection.
16
+ * Opens an extension notification popup for the user to approve scopes.
17
+ * Supported scopes: 'read', 'sign', 'submit', 'switchNetwork'
18
+ */
19
+ connect(params?: {
20
+ scopes?: string[];
21
+ }): Promise<{
22
+ address: string;
23
+ publicKey?: string;
24
+ }>;
25
+ /** Revoke the current dApp permission and close the session */
26
+ disconnect(): Promise<void>;
27
+ /** Return the address of the currently connected account */
28
+ getAddress(): Promise<{
29
+ address: string;
30
+ publicKey?: string;
31
+ }>;
32
+ /**
33
+ * Return the active network identifier.
34
+ * Known values: 'mainnet' | 'testnet' | 'devnet'
35
+ */
36
+ getNetwork(): Promise<{
37
+ network: string;
38
+ }>;
39
+ /** Sign a transaction without submitting it to the ledger */
40
+ signTransaction(tx: Record<string, unknown>): Promise<{
41
+ tx_blob: string;
42
+ hash: string;
43
+ }>;
44
+ /** Sign and submit a transaction to the active network */
45
+ signAndSubmit(tx: Record<string, unknown>): Promise<{
46
+ tx_blob: string;
47
+ hash: string;
48
+ }>;
49
+ /** Sign an arbitrary UTF-8 message */
50
+ signMessage(message: string): Promise<{
51
+ signature: string;
52
+ publicKey?: string;
53
+ }>;
54
+ /** Register a provider-level event listener */
55
+ on(event: string, callback: (data: unknown) => void): void;
56
+ /** Remove a provider-level event listener */
57
+ off(event: string, callback: (data: unknown) => void): void;
58
+ }
59
+ export interface OtsuAdapterOptions {
60
+ /** Override the injected provider (useful for testing) */
61
+ provider?: OtsuProvider;
62
+ /**
63
+ * Permission scopes to request from Otsu during connect().
64
+ *
65
+ * Otsu requires all needed scopes to be declared upfront at connection time;
66
+ * it does not support incremental scope elevation per operation. Therefore
67
+ * the default includes 'sign' and 'submit' so that signing flows work without
68
+ * a second popup.
69
+ *
70
+ * If your app only needs read access (e.g. address lookup), you can override
71
+ * this to `["read"]` and Otsu will not request signing permissions.
72
+ *
73
+ * Default: ["read", "sign", "submit", "switchNetwork"]
74
+ */
75
+ scopes?: string[];
76
+ }
77
+ /**
78
+ * XRPL Wallet Kit adapter for Otsu Wallet.
79
+ *
80
+ * Otsu is an MV3 browser extension wallet for XRPL networks (mainnet, testnet,
81
+ * devnet). It provides granular dApp permission scopes, transaction simulation,
82
+ * and risk scanning before user approval.
83
+ *
84
+ * The extension injects its provider at window.xrpl with isOtsu=true.
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * import { createOtsuAdapter } from "@xrpl-wallet-kit/adapter-otsu";
89
+ *
90
+ * const kit = createWalletKit({
91
+ * adapters: [createOtsuAdapter()],
92
+ * // ...
93
+ * });
94
+ * ```
95
+ */
96
+ export declare class OtsuAdapter extends BaseWalletAdapter {
97
+ private options;
98
+ adapterApiVersion: import("@xrpl-wallet-kit/core").WalletAdapterApiVersion;
99
+ metadata: WalletMetadata;
100
+ capabilities: WalletCapabilities;
101
+ constructor(options?: OtsuAdapterOptions);
102
+ isAvailable(): boolean;
103
+ connect(options: ConnectOptions): Promise<ConnectResult>;
104
+ disconnect(): Promise<void>;
105
+ restoreSession(session: WalletSession): Promise<ConnectResult | null>;
106
+ signMessage(request: SignMessageRequest): Promise<{
107
+ signatureKind: "signature";
108
+ proof: string;
109
+ signature: string;
110
+ publicKey: string | undefined;
111
+ raw: {
112
+ signature: string;
113
+ publicKey?: string;
114
+ };
115
+ }>;
116
+ signTransaction(request: SignTransactionRequest): Promise<{
117
+ txBlob: string;
118
+ tx_blob: string;
119
+ hash: string;
120
+ raw: {
121
+ tx_blob: string;
122
+ hash: string;
123
+ };
124
+ }>;
125
+ signAndSubmit(request: SignAndSubmitRequest): Promise<{
126
+ txBlob: string;
127
+ tx_blob: string;
128
+ hash: string;
129
+ raw: {
130
+ tx_blob: string;
131
+ hash: string;
132
+ };
133
+ } | import("@xrpl-wallet-kit/core").TxResult>;
134
+ private getProvider;
135
+ private getInjectedProvider;
136
+ private isOtsuProvider;
137
+ private requireProvider;
138
+ /**
139
+ * Query the provider's current network and return a normalized networkType
140
+ * string ('MAINNET' | 'TESTNET' | 'DEVNET').
141
+ * Falls back to 'MAINNET' when the query fails or the value is unrecognised.
142
+ */
143
+ private resolveNetworkType;
144
+ /**
145
+ * Map a raw provider error thrown during connect() into a typed WalletError.
146
+ */
147
+ private mapConnectError;
148
+ /**
149
+ * Map a raw provider error thrown during sign operations into a typed WalletError.
150
+ */
151
+ private mapSignError;
152
+ }
153
+ export declare function createOtsuAdapter(options?: OtsuAdapterOptions): OtsuAdapter;
154
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
package/dist/index.js ADDED
@@ -0,0 +1,230 @@
1
+ import { BaseWalletAdapter, WALLET_ADAPTER_API_VERSION, createWalletError, normalizeTxResult } from "@xrpl-wallet-kit/core";
2
+ /**
3
+ * Placeholder icon (dark "O" on #0f0f23).
4
+ * TODO: Replace with the official Otsu Wallet logo before publishing.
5
+ * Obtain from: https://github.com/RomThpt/otsu-wallet (assets/ folder)
6
+ * and convert to a data:image/png;base64 or data:image/svg+xml;base64 URL.
7
+ */
8
+ const OTSU_ICON = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MCA0MCI+PHJlY3Qgd2lkdGg9IjQwIiBoZWlnaHQ9IjQwIiByeD0iOCIgZmlsbD0iIzBmMGYyMyIvPjx0ZXh0IHg9IjIwIiB5PSIyNyIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZm9udC1mYW1pbHk9InN5c3RlbS11aSxzYW5zLXNlcmlmIiBmb250LXNpemU9IjIyIiBmb250LXdlaWdodD0iNzAwIiBmaWxsPSIjMzhiZGY4Ij5PPC90ZXh0Pjwvc3ZnPg==";
9
+ /**
10
+ * XRPL Wallet Kit adapter for Otsu Wallet.
11
+ *
12
+ * Otsu is an MV3 browser extension wallet for XRPL networks (mainnet, testnet,
13
+ * devnet). It provides granular dApp permission scopes, transaction simulation,
14
+ * and risk scanning before user approval.
15
+ *
16
+ * The extension injects its provider at window.xrpl with isOtsu=true.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { createOtsuAdapter } from "@xrpl-wallet-kit/adapter-otsu";
21
+ *
22
+ * const kit = createWalletKit({
23
+ * adapters: [createOtsuAdapter()],
24
+ * // ...
25
+ * });
26
+ * ```
27
+ */
28
+ export class OtsuAdapter extends BaseWalletAdapter {
29
+ constructor(options = {}) {
30
+ super();
31
+ this.options = options;
32
+ this.adapterApiVersion = WALLET_ADAPTER_API_VERSION;
33
+ this.metadata = {
34
+ id: "otsu",
35
+ name: "Otsu Wallet",
36
+ type: "extension",
37
+ group: "Extensions",
38
+ icon: OTSU_ICON,
39
+ homepage: "https://github.com/RomThpt/otsu-wallet"
40
+ };
41
+ this.capabilities = {
42
+ connect: true,
43
+ disconnect: true,
44
+ signMessage: true,
45
+ signTransaction: true,
46
+ signAndSubmit: true
47
+ // payments and nftOffers are intentionally omitted until confirmed with
48
+ // live Otsu transaction tests. Enable them here once Payment and NFT
49
+ // offer payloads have been validated end-to-end with the extension.
50
+ };
51
+ }
52
+ // Availability
53
+ isAvailable() {
54
+ return Boolean(this.getProvider(false)?.isOtsu);
55
+ }
56
+ // Connection
57
+ async connect(options) {
58
+ if (options.signal?.aborted) {
59
+ throw createWalletError.connectionRejected(this.metadata.name, new Error("Connection canceled before start"));
60
+ }
61
+ const provider = this.requireProvider();
62
+ let response;
63
+ try {
64
+ response = await provider.connect({
65
+ scopes: this.options.scopes ?? ["read", "sign", "submit", "switchNetwork"]
66
+ });
67
+ }
68
+ catch (error) {
69
+ throw this.mapConnectError(error);
70
+ }
71
+ const { address } = response;
72
+ if (!address)
73
+ throw new Error("Otsu Wallet did not return an XRPL address");
74
+ // Resolve networkType from the provider's active network
75
+ const networkType = await this.resolveNetworkType(provider);
76
+ return {
77
+ account: {
78
+ address,
79
+ publicKey: response.publicKey,
80
+ network: options.network,
81
+ networkType: options.network?.networkType ?? networkType
82
+ },
83
+ raw: response
84
+ };
85
+ }
86
+ async disconnect() {
87
+ try {
88
+ await this.getProvider(false)?.disconnect();
89
+ }
90
+ finally {
91
+ await this.runCleanup();
92
+ }
93
+ }
94
+ async restoreSession(session) {
95
+ const provider = this.getProvider(false);
96
+ if (!provider?.isOtsu)
97
+ return null;
98
+ // Only restore if the extension still reports an active connection
99
+ if (!provider.isConnected())
100
+ return null;
101
+ try {
102
+ const { address, publicKey } = await provider.getAddress();
103
+ const restoredAddress = address ?? session.account.address;
104
+ return {
105
+ account: { ...session.account, address: restoredAddress, publicKey: session.account.publicKey ?? publicKey },
106
+ session: { ...session, account: { ...session.account, address: restoredAddress, publicKey: session.account.publicKey ?? publicKey } },
107
+ raw: { address, publicKey }
108
+ };
109
+ }
110
+ catch {
111
+ // If getAddress fails the session cannot be safely restored
112
+ return null;
113
+ }
114
+ }
115
+ // Signing
116
+ async signMessage(request) {
117
+ const provider = this.requireProvider();
118
+ let result;
119
+ try {
120
+ result = await provider.signMessage(request.message);
121
+ }
122
+ catch (error) {
123
+ throw this.mapSignError(error);
124
+ }
125
+ return {
126
+ signatureKind: "signature",
127
+ proof: result.signature,
128
+ signature: result.signature,
129
+ publicKey: result.publicKey ?? request.account?.publicKey,
130
+ raw: result
131
+ };
132
+ }
133
+ async signTransaction(request) {
134
+ const provider = this.requireProvider();
135
+ let result;
136
+ try {
137
+ result = await provider.signTransaction(request.txJson);
138
+ }
139
+ catch (error) {
140
+ throw this.mapSignError(error);
141
+ }
142
+ // Expose both camelCase (txBlob) and snake_case (tx_blob) for compatibility
143
+ return { txBlob: result.tx_blob, tx_blob: result.tx_blob, hash: result.hash, raw: result };
144
+ }
145
+ async signAndSubmit(request) {
146
+ // When the caller explicitly opts out of network submission, use the
147
+ // sign-only path so the transaction blob is returned without broadcasting.
148
+ if (request.submit === false) {
149
+ return this.signTransaction(request);
150
+ }
151
+ const provider = this.requireProvider();
152
+ let raw;
153
+ try {
154
+ raw = await provider.signAndSubmit(request.txJson);
155
+ }
156
+ catch (error) {
157
+ throw this.mapSignError(error);
158
+ }
159
+ return normalizeTxResult(raw);
160
+ }
161
+ getProvider(required = true) {
162
+ const provider = this.options.provider ?? this.getInjectedProvider();
163
+ if (required && (!provider || !provider.isOtsu)) {
164
+ throw createWalletError.walletNotAvailable(this.metadata.name);
165
+ }
166
+ return provider?.isOtsu ? provider : undefined;
167
+ }
168
+ getInjectedProvider() {
169
+ if (typeof window === "undefined")
170
+ return undefined;
171
+ const provider = window.xrpl;
172
+ return this.isOtsuProvider(provider) ? provider : undefined;
173
+ }
174
+ isOtsuProvider(provider) {
175
+ return Boolean(provider && typeof provider === "object" && provider.isOtsu === true);
176
+ }
177
+ requireProvider() {
178
+ return this.getProvider(true);
179
+ }
180
+ /**
181
+ * Query the provider's current network and return a normalized networkType
182
+ * string ('MAINNET' | 'TESTNET' | 'DEVNET').
183
+ * Falls back to 'MAINNET' when the query fails or the value is unrecognised.
184
+ */
185
+ async resolveNetworkType(provider) {
186
+ try {
187
+ const { network } = await provider.getNetwork();
188
+ const lower = (network ?? "").toLowerCase();
189
+ if (lower === "mainnet" || lower.includes("main"))
190
+ return "MAINNET";
191
+ if (lower === "testnet" || lower.includes("test"))
192
+ return "TESTNET";
193
+ if (lower === "devnet" || lower.includes("dev"))
194
+ return "DEVNET";
195
+ }
196
+ catch {
197
+ // Non-fatal; caller falls back to options.network.
198
+ }
199
+ return undefined;
200
+ }
201
+ /**
202
+ * Map a raw provider error thrown during connect() into a typed WalletError.
203
+ */
204
+ mapConnectError(error) {
205
+ const message = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
206
+ if (message.includes("reject") || message.includes("denied") || message.includes("cancelled") || message.includes("canceled")) {
207
+ return createWalletError.connectionRejected(this.metadata.name);
208
+ }
209
+ if (message.includes("not installed") || message.includes("not found")) {
210
+ return createWalletError.walletNotAvailable(this.metadata.name);
211
+ }
212
+ return createWalletError.connectionFailed(this.metadata.name, error instanceof Error ? error : new Error(String(error)));
213
+ }
214
+ /**
215
+ * Map a raw provider error thrown during sign operations into a typed WalletError.
216
+ */
217
+ mapSignError(error) {
218
+ const message = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
219
+ if (message.includes("reject") || message.includes("denied") || message.includes("cancelled") || message.includes("canceled")) {
220
+ return createWalletError.signRejected(error instanceof Error ? error : new Error(String(error)));
221
+ }
222
+ if (message.includes("timeout") || message.includes("timed out")) {
223
+ return createWalletError.requestTimeout("Otsu Wallet: signing timed out. Please try again.", error);
224
+ }
225
+ return createWalletError.signFailed(error instanceof Error ? error : new Error(String(error)));
226
+ }
227
+ }
228
+ export function createOtsuAdapter(options) {
229
+ return new OtsuAdapter(options);
230
+ }
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@xrpl-wallet-kit/adapter-otsu",
3
+ "version": "0.1.0",
4
+ "description": "Otsu Wallet adapter for XRPL Wallet Kit - MV3 browser extension wallet.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc -p tsconfig.json"
21
+ },
22
+ "dependencies": {
23
+ "@xrpl-wallet-kit/core": "0.1.0"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/XRPDomains/xrpl-wallet-kit.git"
31
+ },
32
+ "homepage": "https://github.com/XRPDomains/xrpl-wallet-kit#readme",
33
+ "bugs": {
34
+ "url": "https://github.com/XRPDomains/xrpl-wallet-kit/issues"
35
+ },
36
+ "keywords": [
37
+ "xrpl",
38
+ "otsu",
39
+ "wallet",
40
+ "wallet-adapter",
41
+ "wallet-kit",
42
+ "xrp-ledger",
43
+ "web3",
44
+ "browser-extension",
45
+ "mv3"
46
+ ]
47
+ }