@joeywallet/gemwallet-compat 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/index.js ADDED
@@ -0,0 +1,279 @@
1
+ /**
2
+ * `@joeywallet/gemwallet-compat` — GemWallet's `@gemwallet/api` surface over Joey.
3
+ *
4
+ * - import { isInstalled, getAddress, sendPayment } from '@gemwallet/api'
5
+ * + import { isInstalled, getAddress, sendPayment } from '@joeywallet/gemwallet-compat'
6
+ *
7
+ * Function names, argument shapes and the `{ type, result }` envelope match
8
+ * `@gemwallet/api@3.8.0`. Four functions deliberately do not exist as working
9
+ * calls — see `./unsupported.ts`.
10
+ */
11
+ import { JOEY_ERROR_CODES, JoeyRpcError, getJoey, waitForJoey, } from '@joeywallet/wallet-sdk';
12
+ import { toGemNetwork, toGemNetworkDescription, toGemWebsocket, toPaymentTransaction, toTrustSetTransaction, } from './convert.js';
13
+ import { envelope } from './envelope.js';
14
+ import { refuse } from './unsupported.js';
15
+ /**
16
+ * How long to wait for a provider that has not been injected yet.
17
+ *
18
+ * 1000ms is GemWallet's own number, and dapps written against it already treat
19
+ * a slower answer as "not installed".
20
+ */
21
+ const DETECT_TIMEOUT_MS = 1000;
22
+ async function requireProvider() {
23
+ const immediate = getJoey();
24
+ if (immediate !== null)
25
+ return immediate;
26
+ return await waitForJoey({ timeoutMs: DETECT_TIMEOUT_MS });
27
+ }
28
+ /**
29
+ * The account this origin may use, connecting first if it has to.
30
+ *
31
+ * `connect({ silent: true })` rather than `getAccounts()` because GemWallet's
32
+ * `getPublicKey()` needs the public key, and only the connect result carries
33
+ * it — `getAccounts()` answers with bare addresses. A silent connect resolves
34
+ * with an empty list rather than throwing when the origin has no grant, so the
35
+ * non-silent call below is what actually opens the approval window, matching
36
+ * GemWallet's behaviour of prompting from `getAddress()`.
37
+ */
38
+ async function requireAccount() {
39
+ const joey = await requireProvider();
40
+ let result = await joey.connect({ silent: true });
41
+ if (result.accounts.length === 0)
42
+ result = await joey.connect();
43
+ const account = result.accounts[0];
44
+ if (account === undefined) {
45
+ throw new JoeyRpcError(JOEY_ERROR_CODES.UNAUTHORIZED, 'Joey Wallet connected without sharing an account.');
46
+ }
47
+ return { joey, account };
48
+ }
49
+ /* ------------------------------------------------------------------ detection */
50
+ /**
51
+ * Never rejects, and answers immediately when the provider is already present.
52
+ *
53
+ * Matches GemWallet's contract, including its 1-second budget for a provider
54
+ * that has not been injected yet.
55
+ */
56
+ export async function isInstalled() {
57
+ if (getJoey() !== null)
58
+ return { result: { isInstalled: true } };
59
+ try {
60
+ await waitForJoey({ timeoutMs: DETECT_TIMEOUT_MS });
61
+ return { result: { isInstalled: true } };
62
+ }
63
+ catch {
64
+ return { result: { isInstalled: false } };
65
+ }
66
+ }
67
+ /* -------------------------------------------------------------------- account */
68
+ export async function getAddress() {
69
+ return await envelope(async () => {
70
+ const { account } = await requireAccount();
71
+ return { address: account.address };
72
+ });
73
+ }
74
+ export async function getPublicKey() {
75
+ return await envelope(async () => {
76
+ const { account } = await requireAccount();
77
+ if (account.publicKey === undefined) {
78
+ throw new JoeyRpcError(JOEY_ERROR_CODES.UNAUTHORIZED, 'The selected Joey account is watch-only and has no public key.');
79
+ }
80
+ return { address: account.address, publicKey: account.publicKey };
81
+ });
82
+ }
83
+ export async function getNetwork() {
84
+ return await envelope(async () => {
85
+ const joey = await requireProvider();
86
+ const network = await joey.getNetwork();
87
+ return {
88
+ // Joey is XRPL-only. GemWallet's other value, XAHAU, is never returned.
89
+ chain: 'XRPL',
90
+ network: toGemNetwork(network),
91
+ websocket: toGemWebsocket(network),
92
+ };
93
+ });
94
+ }
95
+ /* -------------------------------------------------------------------- signing */
96
+ /**
97
+ * Not implemented. Throws {@link GemWalletUnsupportedError} synchronously.
98
+ *
99
+ * Joey has no raw message-signing method: a bare signature over a string
100
+ * carries no domain, nonce or timestamp and is replayable against another site.
101
+ * Use `signIn()` from `@joeywallet/wallet-sdk`, which signs a CAIP-122 message bound
102
+ * to this origin.
103
+ */
104
+ export function signMessage(_message, _isHex) {
105
+ return refuse('signMessage');
106
+ }
107
+ export async function sendPayment(paymentPayload) {
108
+ return await envelope(async () => {
109
+ const { joey, account } = await requireAccount();
110
+ const result = await joey.signAndSubmitTransaction({
111
+ tx_json: toPaymentTransaction(paymentPayload, account.address),
112
+ });
113
+ return { hash: result.hash };
114
+ });
115
+ }
116
+ export async function setTrustline(payload) {
117
+ return await envelope(async () => {
118
+ const { joey, account } = await requireAccount();
119
+ const result = await joey.signAndSubmitTransaction({
120
+ tx_json: toTrustSetTransaction(payload, account.address),
121
+ });
122
+ return { hash: result.hash };
123
+ });
124
+ }
125
+ export async function signTransaction(payload) {
126
+ return await envelope(async () => {
127
+ const { joey } = await requireAccount();
128
+ const result = await joey.signTransaction({ tx_json: payload.transaction });
129
+ // GemWallet calls the signed blob `signature`. It is the full signed
130
+ // transaction, not the `TxnSignature` field.
131
+ return { signature: result.tx_blob };
132
+ });
133
+ }
134
+ export async function submitTransaction(payload) {
135
+ return await envelope(async () => {
136
+ const { joey } = await requireAccount();
137
+ const result = await joey.signAndSubmitTransaction({ tx_json: payload.transaction });
138
+ return { hash: result.hash };
139
+ });
140
+ }
141
+ export async function submitBulkTransactions(payload) {
142
+ return await envelope(async () => {
143
+ const { joey } = await requireAccount();
144
+ // GemWallet correlates results by an `ID` field carried inside each
145
+ // transaction. `ID` is not an XRPL field and would break serialisation, so
146
+ // it is stripped here and re-attached by position — Joey signs the batch in
147
+ // the order it was given.
148
+ const ids = [];
149
+ const tx_list = payload.transactions.map((entry) => {
150
+ const { ID, ...tx_json } = entry;
151
+ ids.push(ID);
152
+ return { tx_json };
153
+ });
154
+ const results = await joey.signTransactionBulk({ tx_list, submit: true });
155
+ const transactions = ids.map((id, index) => {
156
+ const result = results[index];
157
+ return {
158
+ ...(id === undefined ? {} : { id }),
159
+ // A resolved bulk request carries one entry per transaction, so every
160
+ // one of these is `true`. The guard stays because the alternative
161
+ // reading — an index with no entry silently becoming `accepted: true`
162
+ // with no hash — is the failure this shape exists to prevent.
163
+ //
164
+ // A batch that fails part way *rejects*, and `envelope` turns that into
165
+ // GemWallet's error response. The signed blobs and the failing index
166
+ // are on the error's `data` (`SignTransactionBulkFailure`); mapping
167
+ // them onto per-transaction `accepted` flags would be a better answer
168
+ // for a GemWallet dapp than an error, and is deliberately left as a
169
+ // change to this package's own contract rather than smuggled in with
170
+ // the wallet's.
171
+ accepted: result !== undefined,
172
+ ...(result === undefined ? {} : { hash: result.hash }),
173
+ };
174
+ });
175
+ return { transactions };
176
+ });
177
+ }
178
+ /* --------------------------------------------------------------- unsupported */
179
+ /**
180
+ * Not implemented. Throws {@link GemWalletUnsupportedError} synchronously.
181
+ *
182
+ * @see ./unsupported.ts for why.
183
+ */
184
+ export function setRegularKey(_payload) {
185
+ return refuse('setRegularKey');
186
+ }
187
+ /** Not implemented. Throws {@link GemWalletUnsupportedError} synchronously. */
188
+ export function setHook(_payload) {
189
+ return refuse('setHook');
190
+ }
191
+ /** Not implemented. Throws {@link GemWalletUnsupportedError} synchronously. */
192
+ export function setAccount(_payload) {
193
+ return refuse('setAccount');
194
+ }
195
+ function normaliseEvent(eventType) {
196
+ switch (eventType) {
197
+ case 'login':
198
+ case 'EVENT_LOGIN':
199
+ return 'login';
200
+ case 'logout':
201
+ case 'EVENT_LOGOUT':
202
+ return 'logout';
203
+ case 'networkChanged':
204
+ case 'EVENT_NETWORK_CHANGED':
205
+ return 'networkChanged';
206
+ case 'walletChanged':
207
+ case 'EVENT_WALLET_CHANGED':
208
+ return 'walletChanged';
209
+ }
210
+ }
211
+ function toGemNetworkEvent(network) {
212
+ return {
213
+ network: {
214
+ name: toGemNetwork(network),
215
+ server: toGemWebsocket(network),
216
+ description: toGemNetworkDescription(network),
217
+ },
218
+ };
219
+ }
220
+ function attach(joey, event, callback) {
221
+ const emit = (payload) => {
222
+ ;
223
+ callback(payload);
224
+ };
225
+ switch (event) {
226
+ case 'login':
227
+ return joey.on('connect', () => emit({ loggedIn: true }));
228
+ case 'logout':
229
+ return joey.on('disconnect', () => emit({ loggedIn: false }));
230
+ case 'networkChanged':
231
+ return joey.on('networkChanged', (network) => {
232
+ if (network !== null)
233
+ emit(toGemNetworkEvent(network));
234
+ });
235
+ case 'walletChanged':
236
+ return joey.on('accountsChanged', (accounts) => emit({
237
+ wallet: { publicAddress: accounts[0]?.address ?? '' },
238
+ }));
239
+ }
240
+ }
241
+ /**
242
+ * Subscribe to a wallet event.
243
+ *
244
+ * `@gemwallet/api`'s `on()` returns `void`; this returns an unsubscribe
245
+ * function. That is a superset — existing call sites that ignore the return
246
+ * value are unaffected — and it is what a single-page app needs to avoid
247
+ * leaking a listener on every route change.
248
+ */
249
+ export function on(eventType, callback) {
250
+ const event = normaliseEvent(eventType);
251
+ let detach = null;
252
+ let cancelled = false;
253
+ const bind = (joey) => {
254
+ if (cancelled)
255
+ return;
256
+ detach = attach(joey, event, callback);
257
+ };
258
+ const immediate = getJoey();
259
+ if (immediate !== null)
260
+ bind(immediate);
261
+ else {
262
+ void waitForJoey({ timeoutMs: DETECT_TIMEOUT_MS })
263
+ .then(bind)
264
+ .catch(() => {
265
+ /* no wallet, nothing to listen to */
266
+ });
267
+ }
268
+ return () => {
269
+ cancelled = true;
270
+ detach?.();
271
+ detach = null;
272
+ };
273
+ }
274
+ /* -------------------------------------------------------------------- exports */
275
+ export { GemWalletUnsupportedError, UNSUPPORTED_METHODS, } from './unsupported.js';
276
+ export { envelope, rejected, response } from './envelope.js';
277
+ export { toGemNetwork, toGemWebsocket, toPaymentTransaction, toTrustSetTransaction, toXrplMemos, toXrplSigners, } from './convert.js';
278
+ export { DEFAULT_SUBMIT_TX_BULK_ON_ERROR } from './types.js';
279
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,OAAO,EAC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E,MAAM,YAAY,CAAA"}
@@ -0,0 +1,182 @@
1
+ /**
2
+ * GemWallet's public types, restated.
3
+ *
4
+ * Copied by shape from `@gemwallet/api@3.8.0` rather than imported, so a
5
+ * migrating dapp can delete the `@gemwallet/api` dependency entirely — which is
6
+ * the whole point of this package. Field names, casing and optionality are
7
+ * deliberately identical to GemWallet's, including the parts that differ from
8
+ * XRPL's own JSON (lowercase `memos`, `{ memo: { memoData } }` instead of
9
+ * `{ Memo: { MemoData } }`); `../src/convert.ts` does the translation.
10
+ */
11
+ import type { Amount, IssuedCurrencyAmount, Path, TransactionLike } from '@joeywallet/wallet-sdk';
12
+ export type { Amount, IssuedCurrencyAmount, Path };
13
+ /** GemWallet's envelope discriminant. `reject` means the user declined. */
14
+ export type ResponseType = 'response' | 'reject';
15
+ export interface BaseResponse<T> {
16
+ type: ResponseType;
17
+ result?: T;
18
+ }
19
+ /** GemWallet's own `Network` enum values, as string literals. */
20
+ export type Network = 'Mainnet' | 'Testnet' | 'Devnet' | 'Custom';
21
+ export type Chain = 'XRPL' | 'XAHAU';
22
+ /** GemWallet spells memos lowercase and singular-nested. */
23
+ export interface Memo {
24
+ memo: {
25
+ memoType?: string;
26
+ memoData?: string;
27
+ memoFormat?: string;
28
+ };
29
+ }
30
+ export interface Signer {
31
+ signer: {
32
+ account: string;
33
+ txnSignature: string;
34
+ signingPubKey: string;
35
+ };
36
+ }
37
+ export type PaymentFlags = number | object;
38
+ export type TrustSetFlags = number | object;
39
+ export interface BaseTransactionRequest {
40
+ fee?: string;
41
+ sequence?: number;
42
+ accountTxnID?: string;
43
+ lastLedgerSequence?: number;
44
+ memos?: Memo[];
45
+ networkID?: number;
46
+ signers?: Signer[];
47
+ sourceTag?: number;
48
+ signingPubKey?: string;
49
+ ticketSequence?: number;
50
+ txnSignature?: string;
51
+ }
52
+ export interface SendPaymentRequest extends BaseTransactionRequest {
53
+ amount: Amount;
54
+ destination: string;
55
+ destinationTag?: number;
56
+ invoiceID?: string;
57
+ paths?: Path[];
58
+ sendMax?: Amount;
59
+ deliverMin?: Amount;
60
+ flags?: PaymentFlags;
61
+ }
62
+ export interface SetTrustlineRequest extends BaseTransactionRequest {
63
+ limitAmount: IssuedCurrencyAmount;
64
+ qualityIn?: number;
65
+ qualityOut?: number;
66
+ flags?: TrustSetFlags;
67
+ }
68
+ /**
69
+ * GemWallet types this as xrpl.js's `SubmittableTransaction`. Restated as the
70
+ * SDK's structural constraint so this package stays free of xrpl.js, and left
71
+ * generic so a caller who has xrpl.js keeps full checking on their own side.
72
+ */
73
+ export type Transaction = TransactionLike;
74
+ export type TransactionWithID = TransactionLike & {
75
+ ID?: string;
76
+ };
77
+ export interface SignTransactionRequest {
78
+ transaction: Transaction;
79
+ }
80
+ export interface SubmitTransactionRequest {
81
+ transaction: Transaction;
82
+ }
83
+ export type TransactionErrorHandling = 'abort' | 'continue';
84
+ export declare const DEFAULT_SUBMIT_TX_BULK_ON_ERROR: TransactionErrorHandling;
85
+ export interface SubmitBulkTransactionsRequest {
86
+ transactions: TransactionWithID[];
87
+ /**
88
+ * Accepted for source compatibility. Joey always waits for the hashes it
89
+ * reports, so `false` does not make the call return early.
90
+ */
91
+ waitForHashes?: boolean;
92
+ /**
93
+ * Accepted for source compatibility and ignored. Joey always aborts the batch
94
+ * at the first failure, which is GemWallet's own default and the safer of the
95
+ * two behaviours — `'continue'` would keep signing after a transaction the
96
+ * user or the ledger already refused.
97
+ */
98
+ onError?: TransactionErrorHandling;
99
+ }
100
+ export interface IsInstalledResponse {
101
+ result: {
102
+ isInstalled: boolean;
103
+ };
104
+ }
105
+ export interface GetAddressResponse extends BaseResponse<{
106
+ address: string;
107
+ }> {
108
+ }
109
+ export interface GetPublicKeyResponse extends BaseResponse<{
110
+ address: string;
111
+ publicKey: string;
112
+ }> {
113
+ }
114
+ export interface GetNetworkResponse extends BaseResponse<{
115
+ chain: string;
116
+ network: Network;
117
+ websocket: string;
118
+ }> {
119
+ }
120
+ export interface SignMessageResponse extends BaseResponse<{
121
+ signedMessage: string;
122
+ }> {
123
+ }
124
+ export interface SendPaymentResponse extends BaseResponse<{
125
+ hash: string;
126
+ }> {
127
+ }
128
+ export interface SetTrustlineResponse extends BaseResponse<{
129
+ hash: string;
130
+ }> {
131
+ }
132
+ export interface SignTransactionResponse extends BaseResponse<{
133
+ signature: string | null | undefined;
134
+ }> {
135
+ }
136
+ export interface SubmitTransactionResponse extends BaseResponse<{
137
+ hash: string;
138
+ }> {
139
+ }
140
+ export interface TransactionBulkResponse {
141
+ id?: string;
142
+ accepted?: boolean;
143
+ hash?: string;
144
+ error?: string;
145
+ }
146
+ export interface SubmitBulkTransactionsResponse extends BaseResponse<{
147
+ transactions: TransactionBulkResponse[];
148
+ }> {
149
+ }
150
+ export interface EventLoginResponse {
151
+ loggedIn: boolean;
152
+ }
153
+ export interface EventLogoutResponse {
154
+ loggedIn: boolean;
155
+ }
156
+ export interface EventNetworkChangedResponse {
157
+ network: {
158
+ name: string;
159
+ server: string;
160
+ description: string;
161
+ };
162
+ }
163
+ export interface EventWalletChangedResponse {
164
+ wallet: {
165
+ publicAddress: string;
166
+ };
167
+ }
168
+ /**
169
+ * Event names.
170
+ *
171
+ * `@gemwallet/api`'s `on()` compares against the raw wire constants
172
+ * (`EVENT_LOGIN` and friends), while GemWallet's documentation and most dapp
173
+ * code use the short names. Both are accepted.
174
+ */
175
+ export type GemEventType = 'login' | 'logout' | 'networkChanged' | 'walletChanged' | 'EVENT_LOGIN' | 'EVENT_LOGOUT' | 'EVENT_NETWORK_CHANGED' | 'EVENT_WALLET_CHANGED';
176
+ export interface GemEventPayloadMap {
177
+ login: EventLoginResponse;
178
+ logout: EventLogoutResponse;
179
+ networkChanged: EventNetworkChangedResponse;
180
+ walletChanged: EventWalletChangedResponse;
181
+ }
182
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAC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B;IACjC,QAAQ,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,2BAA2B;IAC1C,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAA;CAC/D;AAED,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE;QAAE,aAAa,EAAE,MAAM,CAAA;KAAE,CAAA;CAClC;AAED;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GACpB,OAAO,GACP,QAAQ,GACR,gBAAgB,GAChB,eAAe,GACf,aAAa,GACb,cAAc,GACd,uBAAuB,GACvB,sBAAsB,CAAA;AAE1B,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,kBAAkB,CAAA;IACzB,MAAM,EAAE,mBAAmB,CAAA;IAC3B,cAAc,EAAE,2BAA2B,CAAA;IAC3C,aAAa,EAAE,0BAA0B,CAAA;CAC1C"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export const DEFAULT_SUBMIT_TX_BULK_ON_ERROR = 'abort';
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAkGA,MAAM,CAAC,MAAM,+BAA+B,GAA6B,OAAO,CAAA"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The GemWallet methods Joey will not implement.
3
+ *
4
+ * `setRegularKey`, `setHook` and `setAccount` are account-control transactions.
5
+ * `SetRegularKey` combined with `AccountSet asfDisableMaster` hands the caller
6
+ * permanent, unrevokable control of an XRPL account, and the balance looks
7
+ * untouched while it drains over later ledgers; `SetHook` installs code that
8
+ * runs on every future transaction. Exposing any of them to an arbitrary
9
+ * website is how XRPL accounts get taken over, and no approval dialog makes
10
+ * that safe, because the user cannot evaluate the consequence from the
11
+ * transaction JSON.
12
+ *
13
+ * Joey supports all three from its own UI, behind a typed confirmation and
14
+ * step-up authentication. It does not expose them to dapps at all — the
15
+ * extension hard-rejects `SetRegularKey`, `SignerListSet` and `AccountDelete`
16
+ * at the deserialisation layer, so even a hand-rolled `signTransaction` call
17
+ * carrying one of these transaction types fails.
18
+ *
19
+ * `signMessage` is here for a different reason: Joey has no raw
20
+ * message-signing method at all. See below.
21
+ *
22
+ * The three account-control functions throw synchronously rather than returning
23
+ * a rejected promise or a `{ type: 'reject' }` envelope, so a migrating dapp
24
+ * finds out at the first call in development instead of shipping a silently
25
+ * dead code path.
26
+ */
27
+ export declare const UNSUPPORTED_METHODS: readonly ["setRegularKey", "setHook", "setAccount", "signMessage"];
28
+ export type UnsupportedMethod = (typeof UNSUPPORTED_METHODS)[number];
29
+ export declare class GemWalletUnsupportedError extends Error {
30
+ /** EIP-1193 "unsupported method". */
31
+ readonly code = 4200;
32
+ readonly method: UnsupportedMethod;
33
+ constructor(method: UnsupportedMethod);
34
+ }
35
+ export declare function refuse(method: UnsupportedMethod): never;
36
+ //# sourceMappingURL=unsupported.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unsupported.d.ts","sourceRoot":"","sources":["../src/unsupported.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,mBAAmB,oEAKtB,CAAA;AAEV,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAA;AAapE,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,qCAAqC;IACrC,QAAQ,CAAC,IAAI,QAAO;IACpB,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAA;gBAEtB,MAAM,EAAE,iBAAiB;CAMtC;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,KAAK,CAEvD"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The GemWallet methods Joey will not implement.
3
+ *
4
+ * `setRegularKey`, `setHook` and `setAccount` are account-control transactions.
5
+ * `SetRegularKey` combined with `AccountSet asfDisableMaster` hands the caller
6
+ * permanent, unrevokable control of an XRPL account, and the balance looks
7
+ * untouched while it drains over later ledgers; `SetHook` installs code that
8
+ * runs on every future transaction. Exposing any of them to an arbitrary
9
+ * website is how XRPL accounts get taken over, and no approval dialog makes
10
+ * that safe, because the user cannot evaluate the consequence from the
11
+ * transaction JSON.
12
+ *
13
+ * Joey supports all three from its own UI, behind a typed confirmation and
14
+ * step-up authentication. It does not expose them to dapps at all — the
15
+ * extension hard-rejects `SetRegularKey`, `SignerListSet` and `AccountDelete`
16
+ * at the deserialisation layer, so even a hand-rolled `signTransaction` call
17
+ * carrying one of these transaction types fails.
18
+ *
19
+ * `signMessage` is here for a different reason: Joey has no raw
20
+ * message-signing method at all. See below.
21
+ *
22
+ * The three account-control functions throw synchronously rather than returning
23
+ * a rejected promise or a `{ type: 'reject' }` envelope, so a migrating dapp
24
+ * finds out at the first call in development instead of shipping a silently
25
+ * dead code path.
26
+ */
27
+ export const UNSUPPORTED_METHODS = [
28
+ 'setRegularKey',
29
+ 'setHook',
30
+ 'setAccount',
31
+ 'signMessage',
32
+ ];
33
+ const REASONS = {
34
+ setRegularKey: 'SetRegularKey assigns an alternate signing key to the account. Together with AccountSet asfDisableMaster it is an irreversible account takeover, so Joey never exposes it to a website. Change your account keys from the Joey Wallet UI instead.',
35
+ setHook: 'SetHook installs code that runs on every future transaction for the account. Joey never exposes it to a website. Install hooks from the Joey Wallet UI instead.',
36
+ setAccount: 'AccountSet can disable the master key, set an NFT minter, or change the transfer rate. Joey never exposes it to a website. Change account settings from the Joey Wallet UI instead.',
37
+ signMessage: 'Joey does not sign arbitrary strings for a website: a bare signature carries no domain, nonce or timestamp, so it can be replayed against another site. Use signIn() from @joeywallet/wallet-sdk instead, which signs a CAIP-122 message bound to this origin.',
38
+ };
39
+ export class GemWalletUnsupportedError extends Error {
40
+ /** EIP-1193 "unsupported method". */
41
+ code = 4200;
42
+ method;
43
+ constructor(method) {
44
+ super(`@joeywallet/gemwallet-compat does not implement ${method}(). ${REASONS[method]}`);
45
+ this.name = 'GemWalletUnsupportedError';
46
+ this.method = method;
47
+ Object.setPrototypeOf(this, GemWalletUnsupportedError.prototype);
48
+ }
49
+ }
50
+ export function refuse(method) {
51
+ throw new GemWalletUnsupportedError(method);
52
+ }
53
+ //# sourceMappingURL=unsupported.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unsupported.js","sourceRoot":"","sources":["../src/unsupported.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,eAAe;IACf,SAAS;IACT,YAAY;IACZ,aAAa;CACL,CAAA;AAIV,MAAM,OAAO,GAAsC;IACjD,aAAa,EACX,mPAAmP;IACrP,OAAO,EACL,iKAAiK;IACnK,UAAU,EACR,qLAAqL;IACvL,WAAW,EACT,gQAAgQ;CACnQ,CAAA;AAED,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAClD,qCAAqC;IAC5B,IAAI,GAAG,IAAI,CAAA;IACX,MAAM,CAAmB;IAElC,YAAY,MAAyB;QACnC,KAAK,CAAC,mDAAmD,MAAM,OAAO,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QACxF,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAA;QACvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,yBAAyB,CAAC,SAAS,CAAC,CAAA;IAClE,CAAC;CACF;AAED,MAAM,UAAU,MAAM,CAAC,MAAyB;IAC9C,MAAM,IAAI,yBAAyB,CAAC,MAAM,CAAC,CAAA;AAC7C,CAAC"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@joeywallet/gemwallet-compat",
3
+ "version": "0.2.0",
4
+ "description": "GemWallet's @gemwallet/api surface, implemented over Joey Wallet. Migrate a dapp by changing one import.",
5
+ "license": "MIT",
6
+ "homepage": "https://github.com/Joey-Wallet/joey-wallet-sdk#readme",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Joey-Wallet/joey-wallet-sdk.git",
10
+ "directory": "packages/gemwallet-compat"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/Joey-Wallet/joey-wallet-sdk/issues"
14
+ },
15
+ "type": "module",
16
+ "sideEffects": false,
17
+ "main": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "src",
28
+ "LICENSE",
29
+ "README.md"
30
+ ],
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "engines": {
35
+ "node": ">=18"
36
+ },
37
+ "dependencies": {
38
+ "@joeywallet/wallet-sdk": "0.2.0"
39
+ },
40
+ "devDependencies": {
41
+ "typescript": "5.7.2"
42
+ },
43
+ "keywords": [
44
+ "xrpl",
45
+ "gemwallet",
46
+ "joey",
47
+ "compatibility"
48
+ ],
49
+ "scripts": {
50
+ "build": "tsc -p tsconfig.json",
51
+ "ts:check": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json"
52
+ }
53
+ }