@joeywallet/wallet-sdk 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/LICENSE +21 -0
- package/README.md +705 -0
- package/dist/client.d.ts +55 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +224 -0
- package/dist/client.js.map +1 -0
- package/dist/detect.d.ts +45 -0
- package/dist/detect.d.ts.map +1 -0
- package/dist/detect.js +238 -0
- package/dist/detect.js.map +1 -0
- package/dist/errors.d.ts +75 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +120 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/mutation.d.ts +46 -0
- package/dist/mutation.d.ts.map +1 -0
- package/dist/mutation.js +67 -0
- package/dist/mutation.js.map +1 -0
- package/dist/provider.d.ts +159 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +142 -0
- package/dist/provider.js.map +1 -0
- package/dist/react.d.ts +76 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +225 -0
- package/dist/react.js.map +1 -0
- package/dist/types.d.ts +391 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +38 -0
- package/dist/types.js.map +1 -0
- package/dist/vanilla.d.ts +58 -0
- package/dist/vanilla.d.ts.map +1 -0
- package/dist/vanilla.js +161 -0
- package/dist/vanilla.js.map +1 -0
- package/package.json +70 -0
- package/src/client.ts +342 -0
- package/src/detect.ts +278 -0
- package/src/errors.ts +133 -0
- package/src/index.ts +97 -0
- package/src/mutation.ts +109 -0
- package/src/provider.ts +229 -0
- package/src/react.ts +375 -0
- package/src/types.ts +440 -0
- package/src/vanilla.ts +239 -0
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one error type every SDK method rejects with.
|
|
3
|
+
*
|
|
4
|
+
* Codes are EIP-1193 numbers verbatim rather than XRPL-specific strings,
|
|
5
|
+
* because every wallet aggregator in this ecosystem already branches on them.
|
|
6
|
+
* Two of them are Joey extensions in the same numeric space: 4300 (locked) and
|
|
7
|
+
* 4902 (unrecognised chain).
|
|
8
|
+
*/
|
|
9
|
+
export declare const JOEY_ERROR_CODES: {
|
|
10
|
+
/** The user declined the request in the wallet. */
|
|
11
|
+
readonly USER_REJECTED: 4001;
|
|
12
|
+
/** The origin has not been granted access to the requested account. */
|
|
13
|
+
readonly UNAUTHORIZED: 4100;
|
|
14
|
+
/** The provider does not implement this method. */
|
|
15
|
+
readonly UNSUPPORTED_METHOD: 4200;
|
|
16
|
+
/** A vault exists but is locked, and the user did not unlock it. */
|
|
17
|
+
readonly LOCKED: 4300;
|
|
18
|
+
/** No provider, or the provider is not connected to this origin. */
|
|
19
|
+
readonly DISCONNECTED: 4900;
|
|
20
|
+
/** The provider is connected but cannot reach the requested chain. */
|
|
21
|
+
readonly CHAIN_DISCONNECTED: 4901;
|
|
22
|
+
/**
|
|
23
|
+
* The requested chain is not one of `xrpl:0`, `xrpl:1`, `xrpl:2` — or the
|
|
24
|
+
* wallet is on a different one and will not sign for the one you asked for.
|
|
25
|
+
*
|
|
26
|
+
* Spelled with a `z`. Both spellings existed: the wallet's
|
|
27
|
+
* `ProviderErrorCode` used `UNRECOGNIZED_CHAIN` and this table used
|
|
28
|
+
* `UNRECOGNISED_CHAIN`, which is exactly the kind of thing that survives
|
|
29
|
+
* until a dapp imports the wrong one. EIP-1193 names the code
|
|
30
|
+
* "Unrecognized chain ID", so the standard's spelling wins over the rest of
|
|
31
|
+
* this repo's British prose, and the wallet no longer declares a second copy
|
|
32
|
+
* to disagree with.
|
|
33
|
+
*/
|
|
34
|
+
readonly UNRECOGNIZED_CHAIN: 4902;
|
|
35
|
+
/**
|
|
36
|
+
* Too many requests from this origin in too short a window.
|
|
37
|
+
*
|
|
38
|
+
* Reachable two ways, and a dapp that does not handle it will look broken in
|
|
39
|
+
* both: the content-script bridge caps concurrent in-flight requests, and the
|
|
40
|
+
* wallet blocks an origin the user has rejected three times in a row. Back
|
|
41
|
+
* off; do not retry in a loop.
|
|
42
|
+
*/
|
|
43
|
+
readonly LIMIT_EXCEEDED: -32005;
|
|
44
|
+
/** The message was not a well-formed request — no method, or not an object. */
|
|
45
|
+
readonly INVALID_REQUEST: -32600;
|
|
46
|
+
/** Malformed arguments; the request never reached the approval queue. */
|
|
47
|
+
readonly INVALID_PARAMS: -32602;
|
|
48
|
+
/** Anything the SDK could not classify. */
|
|
49
|
+
readonly INTERNAL: -32603;
|
|
50
|
+
};
|
|
51
|
+
export type JoeyErrorCode = (typeof JOEY_ERROR_CODES)[keyof typeof JOEY_ERROR_CODES];
|
|
52
|
+
export declare class JoeyRpcError extends Error {
|
|
53
|
+
readonly code: number;
|
|
54
|
+
readonly data?: unknown;
|
|
55
|
+
constructor(code: number, message: string, data?: unknown);
|
|
56
|
+
/**
|
|
57
|
+
* Normalise anything a provider threw into a `JoeyRpcError`.
|
|
58
|
+
*
|
|
59
|
+
* Providers reject with plain objects at least as often as with Errors, and
|
|
60
|
+
* some older shims reject with a bare string.
|
|
61
|
+
*/
|
|
62
|
+
static from(value: unknown, fallbackCode?: number): JoeyRpcError;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* True when the user declined.
|
|
66
|
+
*
|
|
67
|
+
* Also matches on the message, because a provider that predates the numeric
|
|
68
|
+
* codes (or a shim in between) may only carry the word. This is the same
|
|
69
|
+
* string match the existing XRPL adapters do, which is why every rejection the
|
|
70
|
+
* SDK constructs itself is worded to contain "rejected".
|
|
71
|
+
*/
|
|
72
|
+
export declare function isUserRejection(error: unknown): boolean;
|
|
73
|
+
export declare function userRejectedError(what?: string): JoeyRpcError;
|
|
74
|
+
export declare function notInstalledError(): JoeyRpcError;
|
|
75
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,gBAAgB;IAC3B,mDAAmD;;IAEnD,uEAAuE;;IAEvE,mDAAmD;;IAEnD,oEAAoE;;IAEpE,oEAAoE;;IAEpE,sEAAsE;;IAEtE;;;;;;;;;;;OAWG;;IAEH;;;;;;;OAOG;;IAEH,+EAA+E;;IAE/E,yEAAyE;;IAEzE,2CAA2C;;CAEnC,CAAA;AAEV,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAA;AAEpF,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;gBAEX,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;IAUzD;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,GAAE,MAAkC,GAAG,YAAY;CAoB5F;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAWvD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,SAAmC,GAAG,YAAY,CAEvF;AAED,wBAAgB,iBAAiB,IAAI,YAAY,CAKhD"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one error type every SDK method rejects with.
|
|
3
|
+
*
|
|
4
|
+
* Codes are EIP-1193 numbers verbatim rather than XRPL-specific strings,
|
|
5
|
+
* because every wallet aggregator in this ecosystem already branches on them.
|
|
6
|
+
* Two of them are Joey extensions in the same numeric space: 4300 (locked) and
|
|
7
|
+
* 4902 (unrecognised chain).
|
|
8
|
+
*/
|
|
9
|
+
export const JOEY_ERROR_CODES = {
|
|
10
|
+
/** The user declined the request in the wallet. */
|
|
11
|
+
USER_REJECTED: 4001,
|
|
12
|
+
/** The origin has not been granted access to the requested account. */
|
|
13
|
+
UNAUTHORIZED: 4100,
|
|
14
|
+
/** The provider does not implement this method. */
|
|
15
|
+
UNSUPPORTED_METHOD: 4200,
|
|
16
|
+
/** A vault exists but is locked, and the user did not unlock it. */
|
|
17
|
+
LOCKED: 4300,
|
|
18
|
+
/** No provider, or the provider is not connected to this origin. */
|
|
19
|
+
DISCONNECTED: 4900,
|
|
20
|
+
/** The provider is connected but cannot reach the requested chain. */
|
|
21
|
+
CHAIN_DISCONNECTED: 4901,
|
|
22
|
+
/**
|
|
23
|
+
* The requested chain is not one of `xrpl:0`, `xrpl:1`, `xrpl:2` — or the
|
|
24
|
+
* wallet is on a different one and will not sign for the one you asked for.
|
|
25
|
+
*
|
|
26
|
+
* Spelled with a `z`. Both spellings existed: the wallet's
|
|
27
|
+
* `ProviderErrorCode` used `UNRECOGNIZED_CHAIN` and this table used
|
|
28
|
+
* `UNRECOGNISED_CHAIN`, which is exactly the kind of thing that survives
|
|
29
|
+
* until a dapp imports the wrong one. EIP-1193 names the code
|
|
30
|
+
* "Unrecognized chain ID", so the standard's spelling wins over the rest of
|
|
31
|
+
* this repo's British prose, and the wallet no longer declares a second copy
|
|
32
|
+
* to disagree with.
|
|
33
|
+
*/
|
|
34
|
+
UNRECOGNIZED_CHAIN: 4902,
|
|
35
|
+
/**
|
|
36
|
+
* Too many requests from this origin in too short a window.
|
|
37
|
+
*
|
|
38
|
+
* Reachable two ways, and a dapp that does not handle it will look broken in
|
|
39
|
+
* both: the content-script bridge caps concurrent in-flight requests, and the
|
|
40
|
+
* wallet blocks an origin the user has rejected three times in a row. Back
|
|
41
|
+
* off; do not retry in a loop.
|
|
42
|
+
*/
|
|
43
|
+
LIMIT_EXCEEDED: -32005,
|
|
44
|
+
/** The message was not a well-formed request — no method, or not an object. */
|
|
45
|
+
INVALID_REQUEST: -32600,
|
|
46
|
+
/** Malformed arguments; the request never reached the approval queue. */
|
|
47
|
+
INVALID_PARAMS: -32602,
|
|
48
|
+
/** Anything the SDK could not classify. */
|
|
49
|
+
INTERNAL: -32603,
|
|
50
|
+
};
|
|
51
|
+
export class JoeyRpcError extends Error {
|
|
52
|
+
code;
|
|
53
|
+
data;
|
|
54
|
+
constructor(code, message, data) {
|
|
55
|
+
super(message);
|
|
56
|
+
this.name = 'JoeyRpcError';
|
|
57
|
+
this.code = code;
|
|
58
|
+
if (data !== undefined)
|
|
59
|
+
this.data = data;
|
|
60
|
+
// Restores the prototype chain when this file is transpiled to ES5 by a
|
|
61
|
+
// consumer's bundler, so `instanceof JoeyRpcError` keeps working.
|
|
62
|
+
Object.setPrototypeOf(this, JoeyRpcError.prototype);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Normalise anything a provider threw into a `JoeyRpcError`.
|
|
66
|
+
*
|
|
67
|
+
* Providers reject with plain objects at least as often as with Errors, and
|
|
68
|
+
* some older shims reject with a bare string.
|
|
69
|
+
*/
|
|
70
|
+
static from(value, fallbackCode = JOEY_ERROR_CODES.INTERNAL) {
|
|
71
|
+
if (value instanceof JoeyRpcError)
|
|
72
|
+
return value;
|
|
73
|
+
if (typeof value === 'string') {
|
|
74
|
+
return new JoeyRpcError(codeFromMessage(value, fallbackCode), value);
|
|
75
|
+
}
|
|
76
|
+
if (typeof value === 'object' && value !== null) {
|
|
77
|
+
const record = value;
|
|
78
|
+
const message = typeof record.message === 'string' && record.message.length > 0
|
|
79
|
+
? record.message
|
|
80
|
+
: 'The wallet request failed.';
|
|
81
|
+
const code = typeof record.code === 'number' ? record.code : codeFromMessage(message, fallbackCode);
|
|
82
|
+
return new JoeyRpcError(code, message, record.data);
|
|
83
|
+
}
|
|
84
|
+
return new JoeyRpcError(fallbackCode, 'The wallet request failed.');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* True when the user declined.
|
|
89
|
+
*
|
|
90
|
+
* Also matches on the message, because a provider that predates the numeric
|
|
91
|
+
* codes (or a shim in between) may only carry the word. This is the same
|
|
92
|
+
* string match the existing XRPL adapters do, which is why every rejection the
|
|
93
|
+
* SDK constructs itself is worded to contain "rejected".
|
|
94
|
+
*/
|
|
95
|
+
export function isUserRejection(error) {
|
|
96
|
+
if (error instanceof JoeyRpcError) {
|
|
97
|
+
if (error.code === JOEY_ERROR_CODES.USER_REJECTED)
|
|
98
|
+
return true;
|
|
99
|
+
return /reject/i.test(error.message);
|
|
100
|
+
}
|
|
101
|
+
if (typeof error === 'object' && error !== null) {
|
|
102
|
+
const record = error;
|
|
103
|
+
if (record.code === JOEY_ERROR_CODES.USER_REJECTED)
|
|
104
|
+
return true;
|
|
105
|
+
return typeof record.message === 'string' && /reject/i.test(record.message);
|
|
106
|
+
}
|
|
107
|
+
return typeof error === 'string' && /reject/i.test(error);
|
|
108
|
+
}
|
|
109
|
+
export function userRejectedError(what = 'The user rejected the request.') {
|
|
110
|
+
return new JoeyRpcError(JOEY_ERROR_CODES.USER_REJECTED, what);
|
|
111
|
+
}
|
|
112
|
+
export function notInstalledError() {
|
|
113
|
+
return new JoeyRpcError(JOEY_ERROR_CODES.DISCONNECTED, 'Joey Wallet is not installed, or its provider has not been injected into this page.');
|
|
114
|
+
}
|
|
115
|
+
function codeFromMessage(message, fallbackCode) {
|
|
116
|
+
return /reject|denied|declined|cancell?ed/i.test(message)
|
|
117
|
+
? JOEY_ERROR_CODES.USER_REJECTED
|
|
118
|
+
: fallbackCode;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,mDAAmD;IACnD,aAAa,EAAE,IAAI;IACnB,uEAAuE;IACvE,YAAY,EAAE,IAAI;IAClB,mDAA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AO,IAAI,YAAY,CAAC,gBAAgB,CAAC,aAAa,EAAE,IAAI,CAAC,CAAA;AAC/D,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,OAAO,IAAI,YAAY,CACrB,gBAAgB,CAAC,YAAY,EAC7B,qFAAqF,CACtF,CAAA;AACH,CAAC;AAED,SAAS,eAAe,CAAC,OAAe,EAAE,YAAoB;IAC5D,OAAO,oCAAoC,CAAC,IAAI,CAAC,OAAO,CAAC;QACvD,CAAC,CAAC,gBAAgB,CAAC,aAAa;QAChC,CAAC,CAAC,YAAY,CAAA;AAClB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@joeywallet/wallet-sdk` — the core API.
|
|
3
|
+
*
|
|
4
|
+
* Zero runtime dependencies, ESM only, safe to import in Node (every function
|
|
5
|
+
* that needs a page checks for one first).
|
|
6
|
+
*/
|
|
7
|
+
export { getJoey, isJoeyAvailable, requireJoey, resetJoeyDetection, waitForJoey, type WaitForJoeyOptions, } from './detect.js';
|
|
8
|
+
export { createJoeyClient, readAccounts, readChain, readNetwork, type Joey, } from './client.js';
|
|
9
|
+
export { JOEY_ERROR_CODES, JoeyRpcError, isUserRejection, notInstalledError, userRejectedError, type JoeyErrorCode, } from './errors.js';
|
|
10
|
+
export { APPROVAL_TIMEOUT_MS, CAIP294_ANNOUNCE_EVENT, CAIP294_PROMPT_EVENT, JOEY_DAPP_FORBIDDEN_TRANSACTION_TYPES, JOEY_RDNS, JOEY_RPC_METHODS, JOEY_WALLET_NAME, MAX_BULK_TRANSACTIONS, REQUEST_TIMEOUT_MS, WALLET_STANDARD_APP_READY_EVENT, WALLET_STANDARD_REGISTER_EVENT, invoke, isJoeyInjectedProvider, subscribe, type JoeyInjectedProvider, type JoeyProviderEventName, type JoeyRequestArguments, type JoeyRpcMethod, } from './provider.js';
|
|
11
|
+
export { JOEY_CHAINS, chainForNetworkId, isJoeyChain, networkIdForChain, type Amount, type AnyTransaction, type ConnectParams, type ConnectResult, type IssuedCurrencyAmount, type JoeyAccount, type JoeyChain, type JoeyEventListener, type JoeyEventMap, type JoeyEventName, type JoeyNetwork, type Memo, type MPTAmount, type Path, type PathStep, type SignAndSubmitTransactionResult, type SigningContextParams, type SignInMode, type SignInParams, type SignInResult, type BulkEntryResult, type BulkEntryStatus, type SignTransactionBulkFailure, type SignTransactionBulkParams, type SignTransactionForParams, type SignTransactionParams, type SignTransactionResult, type Signer, type TransactionLike, } from './types.js';
|
|
12
|
+
export { initialMutationState, mutationReducer, toPublicState, type MutationAction, type MutationState, type MutationStatus, } from './mutation.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,OAAO,EACP,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,KAAK,kBAAkB,GACxB,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACT,WAAW,EACX,KAAK,IAAI,GACV,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,KAAK,aAAa,GACnB,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,qCAAqC,EACrC,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,EAClB,+BAA+B,EAC/B,8BAA8B,EAC9B,MAAM,EACN,sBAAsB,EACtB,SAAS,EACT,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,aAAa,GACnB,MAAM,eAAe,CAAA;AAEtB,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,IAAI,EACT,KAAK,SAAS,EACd,KAAK,IAAI,EACT,KAAK,QAAQ,EACb,KAAK,8BAA8B,EACnC,KAAK,oBAAoB,EACzB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,MAAM,EACX,KAAK,eAAe,GACrB,MAAM,YAAY,CAAA;AAEnB,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,cAAc,GACpB,MAAM,eAAe,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@joeywallet/wallet-sdk` — the core API.
|
|
3
|
+
*
|
|
4
|
+
* Zero runtime dependencies, ESM only, safe to import in Node (every function
|
|
5
|
+
* that needs a page checks for one first).
|
|
6
|
+
*/
|
|
7
|
+
export { getJoey, isJoeyAvailable, requireJoey, resetJoeyDetection, waitForJoey, } from './detect.js';
|
|
8
|
+
export { createJoeyClient, readAccounts, readChain, readNetwork, } from './client.js';
|
|
9
|
+
export { JOEY_ERROR_CODES, JoeyRpcError, isUserRejection, notInstalledError, userRejectedError, } from './errors.js';
|
|
10
|
+
export { APPROVAL_TIMEOUT_MS, CAIP294_ANNOUNCE_EVENT, CAIP294_PROMPT_EVENT, JOEY_DAPP_FORBIDDEN_TRANSACTION_TYPES, JOEY_RDNS, JOEY_RPC_METHODS, JOEY_WALLET_NAME, MAX_BULK_TRANSACTIONS, REQUEST_TIMEOUT_MS, WALLET_STANDARD_APP_READY_EVENT, WALLET_STANDARD_REGISTER_EVENT, invoke, isJoeyInjectedProvider, subscribe, } from './provider.js';
|
|
11
|
+
export { JOEY_CHAINS, chainForNetworkId, isJoeyChain, networkIdForChain, } from './types.js';
|
|
12
|
+
export { initialMutationState, mutationReducer, toPublicState, } from './mutation.js';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,OAAO,EACP,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,WAAW,GAEZ,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACT,WAAW,GAEZ,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,iBAAiB,GAElB,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,qCAAqC,EACrC,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,EAClB,+BAA+B,EAC/B,8BAA8B,EAC9B,MAAM,EACN,sBAAsB,EACtB,SAAS,GAKV,MAAM,eAAe,CAAA;AAEtB,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,iBAAiB,GA8BlB,MAAM,YAAY,CAAA;AAEnB,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,aAAa,GAId,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The state machine behind the react-query-shaped hooks.
|
|
3
|
+
*
|
|
4
|
+
* Kept here, free of React, for two reasons: the reducer is the part with the
|
|
5
|
+
* interesting edge cases (a stale response landing after a newer one), and it is
|
|
6
|
+
* testable without a DOM. `@joeywallet/wallet-sdk/react` is a thin binding over it, so
|
|
7
|
+
* the SDK gains react-query's ergonomics without react-query's dependency.
|
|
8
|
+
*/
|
|
9
|
+
import { JoeyRpcError } from './errors.js';
|
|
10
|
+
export type MutationStatus = 'idle' | 'pending' | 'success' | 'error';
|
|
11
|
+
export interface MutationState<TData, TVariables> {
|
|
12
|
+
status: MutationStatus;
|
|
13
|
+
data: TData | undefined;
|
|
14
|
+
error: JoeyRpcError | undefined;
|
|
15
|
+
/** The arguments of the most recent call, kept so a retry needs no closure. */
|
|
16
|
+
variables: TVariables | undefined;
|
|
17
|
+
isIdle: boolean;
|
|
18
|
+
isPending: boolean;
|
|
19
|
+
isSuccess: boolean;
|
|
20
|
+
isError: boolean;
|
|
21
|
+
}
|
|
22
|
+
export type MutationAction<TData, TVariables> = {
|
|
23
|
+
type: 'reset';
|
|
24
|
+
} | {
|
|
25
|
+
type: 'start';
|
|
26
|
+
variables: TVariables;
|
|
27
|
+
runId: number;
|
|
28
|
+
} | {
|
|
29
|
+
type: 'success';
|
|
30
|
+
data: TData;
|
|
31
|
+
runId: number;
|
|
32
|
+
} | {
|
|
33
|
+
type: 'error';
|
|
34
|
+
error: JoeyRpcError;
|
|
35
|
+
runId: number;
|
|
36
|
+
};
|
|
37
|
+
interface InternalState<TData, TVariables> extends MutationState<TData, TVariables> {
|
|
38
|
+
/** Identifies the call whose result may still write to this state. */
|
|
39
|
+
runId: number;
|
|
40
|
+
}
|
|
41
|
+
export declare function initialMutationState<TData, TVariables>(): InternalState<TData, TVariables>;
|
|
42
|
+
export declare function mutationReducer<TData, TVariables>(state: InternalState<TData, TVariables>, action: MutationAction<TData, TVariables>): InternalState<TData, TVariables>;
|
|
43
|
+
/** The public half of {@link InternalState}, with `runId` dropped. */
|
|
44
|
+
export declare function toPublicState<TData, TVariables>(state: InternalState<TData, TVariables>): MutationState<TData, TVariables>;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=mutation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutation.d.ts","sourceRoot":"","sources":["../src/mutation.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAA;AAErE,MAAM,WAAW,aAAa,CAAC,KAAK,EAAE,UAAU;IAC9C,MAAM,EAAE,cAAc,CAAA;IACtB,IAAI,EAAE,KAAK,GAAG,SAAS,CAAA;IACvB,KAAK,EAAE,YAAY,GAAG,SAAS,CAAA;IAC/B,+EAA+E;IAC/E,SAAS,EAAE,UAAU,GAAG,SAAS,CAAA;IACjC,MAAM,EAAE,OAAO,CAAA;IACf,SAAS,EAAE,OAAO,CAAA;IAClB,SAAS,EAAE,OAAO,CAAA;IAClB,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,MAAM,cAAc,CAAC,KAAK,EAAE,UAAU,IACxC;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACvD;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC/C;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAEzD,UAAU,aAAa,CAAC,KAAK,EAAE,UAAU,CAAE,SAAQ,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC;IACjF,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAA;CACd;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,KAAK,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,CAY1F;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,EAC/C,KAAK,EAAE,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,EACvC,MAAM,EAAE,cAAc,CAAC,KAAK,EAAE,UAAU,CAAC,GACxC,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,CAgDlC;AAED,sEAAsE;AACtE,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAC7C,KAAK,EAAE,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,GACtC,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,CAGlC"}
|
package/dist/mutation.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export function initialMutationState() {
|
|
2
|
+
return {
|
|
3
|
+
status: 'idle',
|
|
4
|
+
data: undefined,
|
|
5
|
+
error: undefined,
|
|
6
|
+
variables: undefined,
|
|
7
|
+
isIdle: true,
|
|
8
|
+
isPending: false,
|
|
9
|
+
isSuccess: false,
|
|
10
|
+
isError: false,
|
|
11
|
+
runId: 0,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function mutationReducer(state, action) {
|
|
15
|
+
switch (action.type) {
|
|
16
|
+
case 'reset':
|
|
17
|
+
return { ...initialMutationState(), runId: state.runId };
|
|
18
|
+
case 'start':
|
|
19
|
+
return {
|
|
20
|
+
status: 'pending',
|
|
21
|
+
// The previous result is cleared so a stale success cannot be rendered
|
|
22
|
+
// next to a spinner for the call that superseded it.
|
|
23
|
+
data: undefined,
|
|
24
|
+
error: undefined,
|
|
25
|
+
variables: action.variables,
|
|
26
|
+
isIdle: false,
|
|
27
|
+
isPending: true,
|
|
28
|
+
isSuccess: false,
|
|
29
|
+
isError: false,
|
|
30
|
+
runId: action.runId,
|
|
31
|
+
};
|
|
32
|
+
case 'success':
|
|
33
|
+
// A response from a superseded call is dropped: the user clicked twice,
|
|
34
|
+
// and the answer to the first click must not overwrite the second.
|
|
35
|
+
if (action.runId !== state.runId)
|
|
36
|
+
return state;
|
|
37
|
+
return {
|
|
38
|
+
...state,
|
|
39
|
+
status: 'success',
|
|
40
|
+
data: action.data,
|
|
41
|
+
error: undefined,
|
|
42
|
+
isIdle: false,
|
|
43
|
+
isPending: false,
|
|
44
|
+
isSuccess: true,
|
|
45
|
+
isError: false,
|
|
46
|
+
};
|
|
47
|
+
case 'error':
|
|
48
|
+
if (action.runId !== state.runId)
|
|
49
|
+
return state;
|
|
50
|
+
return {
|
|
51
|
+
...state,
|
|
52
|
+
status: 'error',
|
|
53
|
+
data: undefined,
|
|
54
|
+
error: action.error,
|
|
55
|
+
isIdle: false,
|
|
56
|
+
isPending: false,
|
|
57
|
+
isSuccess: false,
|
|
58
|
+
isError: true,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** The public half of {@link InternalState}, with `runId` dropped. */
|
|
63
|
+
export function toPublicState(state) {
|
|
64
|
+
const { runId: _runId, ...rest } = state;
|
|
65
|
+
return rest;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=mutation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutation.js","sourceRoot":"","sources":["../src/mutation.ts"],"names":[],"mappings":"AAmCA,MAAM,UAAU,oBAAoB;IAClC,OAAO;QACL,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;QAChB,SAAS,EAAE,SAAS;QACpB,MAAM,EAAE,IAAI;QACZ,SAAS,EAAE,KAAK;QAChB,SAAS,EAAE,KAAK;QAChB,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,CAAC;KACT,CAAA;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,KAAuC,EACvC,MAAyC;IAEzC,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,OAAO;YACV,OAAO,EA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O,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The object the extension injects into the page's MAIN world, as this SDK sees
|
|
3
|
+
* it.
|
|
4
|
+
*
|
|
5
|
+
* It is mounted at both `window.joey` and `window.xrpl.joey` (the latter by a
|
|
6
|
+
* non-destructive merge, so Crossmark's `window.xrpl` keeps working). The
|
|
7
|
+
* declaration below is a structural view of
|
|
8
|
+
* `apps/extension/src/provider/provider.ts`; anything the wallet adds later is
|
|
9
|
+
* still reachable through `request()`.
|
|
10
|
+
*/
|
|
11
|
+
import type { ConnectParams, ConnectResult, JoeyChain, JoeyNetwork, SignAndSubmitTransactionResult, SignInParams, SignInResult, SignTransactionBulkParams, SignTransactionForParams, SignTransactionParams, SignTransactionResult } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Wire method names.
|
|
14
|
+
*
|
|
15
|
+
* Short, unprefixed names: the injected provider is already a Joey-specific
|
|
16
|
+
* object, and the same table is what the content-script bridge and the
|
|
17
|
+
* background validate against. The three that also exist over WalletConnect
|
|
18
|
+
* (`signTransaction`, `signTransactionFor`, `signTransactionBulk`) carry the
|
|
19
|
+
* same parameter shapes as Joey mobile, minus the `xrpl_` namespace prefix that
|
|
20
|
+
* only WalletConnect needs.
|
|
21
|
+
*/
|
|
22
|
+
export declare const JOEY_RPC_METHODS: {
|
|
23
|
+
readonly connect: "connect";
|
|
24
|
+
readonly disconnect: "disconnect";
|
|
25
|
+
readonly getAccounts: "getAccounts";
|
|
26
|
+
readonly getNetwork: "getNetwork";
|
|
27
|
+
readonly signTransaction: "signTransaction";
|
|
28
|
+
readonly signAndSubmitTransaction: "signAndSubmitTransaction";
|
|
29
|
+
readonly signTransactionFor: "signTransactionFor";
|
|
30
|
+
readonly signTransactionBulk: "signTransactionBulk";
|
|
31
|
+
readonly signIn: "signIn";
|
|
32
|
+
};
|
|
33
|
+
export type JoeyRpcMethod = (typeof JOEY_RPC_METHODS)[keyof typeof JOEY_RPC_METHODS];
|
|
34
|
+
export interface JoeyRequestArguments {
|
|
35
|
+
method: string;
|
|
36
|
+
params?: unknown;
|
|
37
|
+
}
|
|
38
|
+
/** Events the wallet pushes. Payloads are unnormalised at this layer. */
|
|
39
|
+
export type JoeyProviderEventName = 'connect' | 'disconnect' | 'accountsChanged' | 'networkChanged';
|
|
40
|
+
export interface JoeyInjectedProvider {
|
|
41
|
+
readonly isJoey?: boolean;
|
|
42
|
+
/** Reverse-DNS identity, `xyz.joeywallet`. Used by CAIP-294 and aggregators. */
|
|
43
|
+
readonly rdns?: string;
|
|
44
|
+
/** Version of the injected surface, not of the extension. */
|
|
45
|
+
readonly version?: string;
|
|
46
|
+
/** Granted addresses for this origin. `[]` until the user connects. */
|
|
47
|
+
readonly accounts?: readonly string[];
|
|
48
|
+
readonly chain?: JoeyChain | null;
|
|
49
|
+
isAvailable?(): boolean;
|
|
50
|
+
isConnected?(): boolean;
|
|
51
|
+
connect?(params?: ConnectParams): Promise<ConnectResult>;
|
|
52
|
+
disconnect?(): Promise<void>;
|
|
53
|
+
getAccounts?(): Promise<string[]>;
|
|
54
|
+
getNetwork?(): Promise<JoeyNetwork>;
|
|
55
|
+
signTransaction?(params: SignTransactionParams): Promise<SignTransactionResult>;
|
|
56
|
+
signAndSubmitTransaction?(params: SignTransactionParams): Promise<SignAndSubmitTransactionResult>;
|
|
57
|
+
signTransactionFor?(params: SignTransactionForParams): Promise<SignTransactionResult>;
|
|
58
|
+
signTransactionBulk?(params: SignTransactionBulkParams): Promise<SignTransactionResult[]>;
|
|
59
|
+
signIn?(params?: SignInParams): Promise<SignInResult>;
|
|
60
|
+
/** EIP-1193-shaped escape hatch. Always present. */
|
|
61
|
+
request<TResult = unknown>(args: JoeyRequestArguments): Promise<TResult>;
|
|
62
|
+
/** Returns an unsubscribe function. */
|
|
63
|
+
on(event: JoeyProviderEventName, listener: (payload: never) => void): (() => void) | void;
|
|
64
|
+
removeListener?(event: JoeyProviderEventName, listener: (payload: never) => void): void;
|
|
65
|
+
/** Not implemented by Joey, but common enough elsewhere to be worth trying. */
|
|
66
|
+
off?(event: JoeyProviderEventName, listener: (payload: never) => void): void;
|
|
67
|
+
}
|
|
68
|
+
/** The name Joey registers under with the Wallet Standard. */
|
|
69
|
+
export declare const JOEY_WALLET_NAME = "Joey";
|
|
70
|
+
export declare const JOEY_RDNS = "xyz.joeywallet";
|
|
71
|
+
/**
|
|
72
|
+
* Events that mean "the provider just finished installing itself".
|
|
73
|
+
*
|
|
74
|
+
* Both are dispatched synchronously by the provider's install step, so a page
|
|
75
|
+
* whose bundle ran before `document_start` injection completed can wait on them
|
|
76
|
+
* instead of polling. There is no Joey-specific ready event on purpose: an
|
|
77
|
+
* extra global signal is one more thing a page can probe to fingerprint the
|
|
78
|
+
* extension, and these two already exist for discovery.
|
|
79
|
+
*/
|
|
80
|
+
export declare const CAIP294_ANNOUNCE_EVENT = "wallet_announce";
|
|
81
|
+
export declare const WALLET_STANDARD_REGISTER_EVENT = "wallet-standard:register-wallet";
|
|
82
|
+
/**
|
|
83
|
+
* Events an *app* dispatches to make wallets announce themselves again.
|
|
84
|
+
*
|
|
85
|
+
* The counterparts to the two above, and the half that matters for a late
|
|
86
|
+
* bundle: a wallet that installed before your code ran has already dispatched
|
|
87
|
+
* its announcement into a page with nobody listening. Waiting for a second one
|
|
88
|
+
* that will never come is how a detection helper times out against a wallet
|
|
89
|
+
* that is sitting right there. {@link waitForJoey} dispatches both.
|
|
90
|
+
*/
|
|
91
|
+
export declare const CAIP294_PROMPT_EVENT = "wallet_prompt";
|
|
92
|
+
export declare const WALLET_STANDARD_APP_READY_EVENT = "wallet-standard:app-ready";
|
|
93
|
+
/**
|
|
94
|
+
* How long the wallet's own plumbing will wait before answering for it.
|
|
95
|
+
*
|
|
96
|
+
* Published because a dapp cannot otherwise size its own spinner or its own
|
|
97
|
+
* retry, and the two numbers are three orders of magnitude apart on purpose. A
|
|
98
|
+
* method that never touches the approval queue — `getAccounts`, `getNetwork`,
|
|
99
|
+
* `disconnect` — answers in milliseconds or the extension's worker is wedged,
|
|
100
|
+
* so it gets {@link REQUEST_TIMEOUT_MS}. A method that does touch the queue is
|
|
101
|
+
* waiting on a person reading a transaction, and its ceiling is
|
|
102
|
+
* {@link APPROVAL_TIMEOUT_MS}, which matches the approval's own expiry: a
|
|
103
|
+
* shorter one would fail a dapp for a signature the user did in fact give.
|
|
104
|
+
*
|
|
105
|
+
* So `signTransaction` can legitimately be pending for five minutes, and with
|
|
106
|
+
* the page's own backstop on top of it, a little over five. Do not put a
|
|
107
|
+
* thirty-second timeout around it.
|
|
108
|
+
*/
|
|
109
|
+
export declare const REQUEST_TIMEOUT_MS = 30000;
|
|
110
|
+
export declare const APPROVAL_TIMEOUT_MS = 300000;
|
|
111
|
+
/**
|
|
112
|
+
* The most transactions `signTransactionBulk` will accept in one call.
|
|
113
|
+
*
|
|
114
|
+
* Exported so a dapp can split its own work rather than discover the rule by
|
|
115
|
+
* rejection. The wallet enforces it; this is the same constant, imported by the
|
|
116
|
+
* wallet from here.
|
|
117
|
+
*/
|
|
118
|
+
export declare const MAX_BULK_TRANSACTIONS = 32;
|
|
119
|
+
/**
|
|
120
|
+
* Transaction types Joey refuses to sign for a website, whatever the user
|
|
121
|
+
* clicks and whichever method carries them.
|
|
122
|
+
*
|
|
123
|
+
* Published so a dapp can check before it builds a flow around one, and so the
|
|
124
|
+
* refusal is a documented rule rather than a surprise `4100`. Every entry hands
|
|
125
|
+
* over or destroys the account itself:
|
|
126
|
+
*
|
|
127
|
+
* - `SetRegularKey`, `SignerListSet` and `DelegateSet` (XLS-75) each grant
|
|
128
|
+
* permanent authority to act as the account, by three separate mechanisms.
|
|
129
|
+
* - `AccountDelete` is irreversible.
|
|
130
|
+
* - `SetHook` installs code that runs on every future transaction.
|
|
131
|
+
* - `Batch` (XLS-56) carries other transactions inside `RawTransactions`, and
|
|
132
|
+
* Joey's approval screen renders the outer transaction. A user cannot consent
|
|
133
|
+
* to something they were never shown, so it is refused until the review
|
|
134
|
+
* screen can render inner transactions individually.
|
|
135
|
+
*
|
|
136
|
+
* Two rules are not expressible as a type name and are enforced anyway:
|
|
137
|
+
* `AccountSet` is refused when it sets or clears a flag that changes who
|
|
138
|
+
* controls the account (`asfDisableMaster`, `asfRequireAuth`, `asfNoFreeze` and
|
|
139
|
+
* the rest of that family) and permitted otherwise; and the ledger's
|
|
140
|
+
* pseudo-transactions — `EnableAmendment`, `SetFee`, `UNLModify` — are refused
|
|
141
|
+
* because no account signs one.
|
|
142
|
+
*
|
|
143
|
+
* The wallet checks at every nesting level, not just the top.
|
|
144
|
+
*/
|
|
145
|
+
export declare const JOEY_DAPP_FORBIDDEN_TRANSACTION_TYPES: readonly string[];
|
|
146
|
+
export declare function isJoeyInjectedProvider(value: unknown): value is JoeyInjectedProvider;
|
|
147
|
+
/**
|
|
148
|
+
* Call a provider method by name, preferring the typed method over `request()`.
|
|
149
|
+
*
|
|
150
|
+
* The typed methods are not just sugar: `connect`, `disconnect` and
|
|
151
|
+
* `getAccounts` update the provider's own `accounts` and `chain` state, which a
|
|
152
|
+
* dapp reads synchronously through `joey.accounts` / `joey.isConnected()`.
|
|
153
|
+
* Routing those through `request()` would leave that state stale. `request()`
|
|
154
|
+
* remains the fallback for a provider older or newer than this SDK.
|
|
155
|
+
*/
|
|
156
|
+
export declare function invoke<TResult>(provider: JoeyInjectedProvider, method: JoeyRpcMethod, params?: unknown): Promise<TResult>;
|
|
157
|
+
/** Subscribe, tolerating a provider that reports removal three different ways. */
|
|
158
|
+
export declare function subscribe(provider: JoeyInjectedProvider, event: JoeyProviderEventName, listener: (payload: never) => void): () => void;
|
|
159
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,SAAS,EACT,WAAW,EAC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