@amadeus-protocol/wallet-sdk 0.1.6 → 0.1.7
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/injected.d.ts +2 -0
- package/dist/client/injected.d.ts.map +1 -1
- package/dist/client/injected.js +5 -0
- package/dist/client/injected.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -0
- package/dist/react/index.js.map +1 -1
- package/dist/schema.d.ts +10 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +3 -1
- package/dist/schema.js.map +1 -1
- package/dist/transport/envelope.d.ts +1 -1
- package/dist/transport/envelope.d.ts.map +1 -1
- package/dist/transport/envelope.js +2 -1
- package/dist/transport/envelope.js.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/wallet/handler.d.ts +3 -2
- package/dist/wallet/handler.d.ts.map +1 -1
- package/dist/wallet/handler.js +4 -2
- package/dist/wallet/handler.js.map +1 -1
- package/package.json +1 -1
|
@@ -11,6 +11,8 @@ interface WalletClient {
|
|
|
11
11
|
connect(): Promise<string>;
|
|
12
12
|
getAccount(): Promise<string | null>;
|
|
13
13
|
getNetwork(): Promise<string>;
|
|
14
|
+
/** Ask the wallet to switch the active account (user-confirmed); resolves to the new address. */
|
|
15
|
+
switchAccount(target?: string): Promise<string>;
|
|
14
16
|
signTransaction(request: SignTransactionRequest): Promise<SignTransactionResponse>;
|
|
15
17
|
/** Sign then submit the packed bytes to a node; resolves to the tx hash + node reply. */
|
|
16
18
|
signAndSubmit(request: SignTransactionRequest, options: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injected.d.ts","names":[],"sources":["../../src/client/injected.ts"],"mappings":";;UAyBiB;EAChB;EACA,IAAI;;UAiBY;EAChB;EACA,eAAe;;EAEf,WAAW;EACX,cAAc;EACd,cAAc;
|
|
1
|
+
{"version":3,"file":"injected.d.ts","names":[],"sources":["../../src/client/injected.ts"],"mappings":";;UAyBiB;EAChB;EACA,IAAI;;UAiBY;EAChB;EACA,eAAe;;EAEf,WAAW;EACX,cAAc;EACd,cAAc;;EAEd,cAAc,kBAAkB;EAChC,gBAAgB,SAAS,yBAAyB,QAAQ;;EAE1D,cACC,SAAS,wBACT;IAAW;IAAiB;MAC1B;IAAU;IAAgB;;;EAE7B,aAAa;IACZ;IACA;IACA,QAAQ;IACR;MACG;EACJ,GAAG,UAAU,sBACZ,OAAO,GACP,KAAK,MAAM,uBAAuB;EAEnC,IAAI,UAAU,sBACb,OAAO,GACP,KAAK,MAAM,uBAAuB;;;;;;iBAQpB,2BAA2B,mBAAmB,kBAAkB"}
|
package/dist/client/injected.js
CHANGED
|
@@ -52,6 +52,11 @@ function createInjectedWalletClient(providerOverride) {
|
|
|
52
52
|
},
|
|
53
53
|
getAccount: () => requireProvider().getAccount(),
|
|
54
54
|
getNetwork: () => requireProvider().getNetwork(),
|
|
55
|
+
switchAccount: async (target) => {
|
|
56
|
+
const provider = requireProvider();
|
|
57
|
+
if (typeof provider.requestSwitchAccount !== "function") throw new WalletSdkError("UNSUPPORTED", "wallet does not support switchAccount");
|
|
58
|
+
return provider.requestSwitchAccount(target);
|
|
59
|
+
},
|
|
55
60
|
signTransaction: (request) => requireProvider().signTransaction(request),
|
|
56
61
|
signAndSubmit: async (request, options) => {
|
|
57
62
|
const { txHash, txPacked } = await requireProvider().signTransaction(request);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injected.js","names":[],"sources":["../../src/client/injected.ts"],"sourcesContent":["/**\n * A framework-agnostic dApp client over the injected `window.amadeus` provider\n * (the browser extension). It wraps the raw provider with the ergonomics every\n * dApp currently hand-rolls: a single-account `connect`, sign-and-submit, and a\n * cached `ensureApiKey` that decodes expiry via the audited api-key module\n * (replacing the copies in hub / prime-hub).\n *\n * The mobile deep-link/QR path uses the transport module (connect handshake +\n * sealed envelopes) instead of an injected provider; this client is the\n * same-device, extension-present case.\n */\n\nimport { decodeApiKey } from '../crypto/apikey'\nimport { WalletSdkError } from '../errors'\nimport { submitTransaction } from '../tx'\nimport type {\n\tAmadeusEventPayloadMap,\n\tAmadeusProvider,\n\tAmadeusProviderEvent,\n\tSignTransactionRequest,\n\tSignTransactionResponse\n} from '../types'\nimport { getAmadeusProvider } from '../types'\n\n/** Where a cached api-key lives. Default is in-memory; dApps can pass localStorage-backed. */\nexport interface ApiKeyStore {\n\tget(): string | null\n\tset(apiKey: string): void\n}\n\nfunction memoryApiKeyStore(): ApiKeyStore {\n\tlet value: string | null = null\n\treturn { get: () => value, set: (apiKey) => (value = apiKey) }\n}\n\nfunction isApiKeyValid(apiKey: string, leewaySeconds: number): boolean {\n\ttry {\n\t\tconst { payload } = decodeApiKey(apiKey)\n\t\treturn payload.exp > Math.floor(Date.now() / 1000) + leewaySeconds\n\t} catch {\n\t\treturn false\n\t}\n}\n\nexport interface WalletClient {\n\tisAvailable(): boolean\n\tgetProvider(): AmadeusProvider | null\n\t/** Prompt connection; resolves to the connected account (Base58 address). */\n\tconnect(): Promise<string>\n\tgetAccount(): Promise<string | null>\n\tgetNetwork(): Promise<string>\n\tsignTransaction(request: SignTransactionRequest): Promise<SignTransactionResponse>\n\t/** Sign then submit the packed bytes to a node; resolves to the tx hash + node reply. */\n\tsignAndSubmit(\n\t\trequest: SignTransactionRequest,\n\t\toptions: { nodeUrl: string; wait?: boolean }\n\t): Promise<{ txHash: string; submitted: unknown }>\n\t/** Return a valid cached api-key, minting (and caching) a fresh one if needed. Coalesces concurrent calls. */\n\tensureApiKey(options: {\n\t\taud: string\n\t\texpIn: number\n\t\tstore?: ApiKeyStore\n\t\tleewaySeconds?: number\n\t}): Promise<string>\n\ton<E extends AmadeusProviderEvent>(\n\t\tevent: E,\n\t\tcb: (data: AmadeusEventPayloadMap[E]) => void\n\t): void\n\toff<E extends AmadeusProviderEvent>(\n\t\tevent: E,\n\t\tcb: (data: AmadeusEventPayloadMap[E]) => void\n\t): void\n}\n\n/**\n * Create a client bound to the injected provider. Pass `providerOverride` to\n * inject a provider (e.g. in tests); otherwise it reads `window.amadeus`.\n */\nexport function createInjectedWalletClient(providerOverride?: AmadeusProvider): WalletClient {\n\tconst getProvider = () => providerOverride ?? getAmadeusProvider()\n\tconst requireProvider = (): AmadeusProvider => {\n\t\tconst provider = getProvider()\n\t\tif (!provider)\n\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'Amadeus wallet is not available')\n\t\treturn provider\n\t}\n\n\tconst defaultStore = memoryApiKeyStore()\n\tlet pendingApiKey: Promise<string> | null = null\n\n\treturn {\n\t\tisAvailable: () => getProvider() !== null,\n\t\tgetProvider,\n\t\tconnect: async () => {\n\t\t\tconst accounts = await requireProvider().requestAccounts()\n\t\t\tif (!accounts.length)\n\t\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'no account returned')\n\t\t\treturn accounts[0]\n\t\t},\n\t\tgetAccount: () => requireProvider().getAccount(),\n\t\tgetNetwork: () => requireProvider().getNetwork(),\n\t\tsignTransaction: (request) => requireProvider().signTransaction(request),\n\t\tsignAndSubmit: async (request, options) => {\n\t\t\tconst { txHash, txPacked } = await requireProvider().signTransaction(request)\n\t\t\tconst submitted = await submitTransaction(txPacked, {\n\t\t\t\tnodeUrl: options.nodeUrl,\n\t\t\t\twait: options.wait\n\t\t\t})\n\t\t\treturn { txHash, submitted }\n\t\t},\n\t\tensureApiKey: ({ aud, expIn, store = defaultStore, leewaySeconds = 60 }) => {\n\t\t\tconst cached = store.get()\n\t\t\tif (cached && isApiKeyValid(cached, leewaySeconds)) return Promise.resolve(cached)\n\t\t\tif (!pendingApiKey) {\n\t\t\t\tpendingApiKey = requireProvider()\n\t\t\t\t\t.generateApiKey({ aud, exp_in: expIn })\n\t\t\t\t\t.then(({ apiKey }) => {\n\t\t\t\t\t\tstore.set(apiKey)\n\t\t\t\t\t\treturn apiKey\n\t\t\t\t\t})\n\t\t\t\t\t.finally(() => {\n\t\t\t\t\t\tpendingApiKey = null\n\t\t\t\t\t})\n\t\t\t}\n\t\t\treturn pendingApiKey\n\t\t},\n\t\ton: (event, cb) => requireProvider().on(event, cb),\n\t\toff: (event, cb) => requireProvider().off(event, cb)\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA8BA,SAAS,oBAAiC;CACzC,IAAI,QAAuB;CAC3B,OAAO;EAAE,WAAW;EAAO,MAAM,WAAY,QAAQ;CAAQ;AAC9D;AAEA,SAAS,cAAc,QAAgB,eAAgC;CACtE,IAAI;EACH,MAAM,EAAE,YAAY,aAAa,MAAM;EACvC,OAAO,QAAQ,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,IAAI;CACtD,QAAQ;EACP,OAAO;CACR;AACD;;;;;
|
|
1
|
+
{"version":3,"file":"injected.js","names":[],"sources":["../../src/client/injected.ts"],"sourcesContent":["/**\n * A framework-agnostic dApp client over the injected `window.amadeus` provider\n * (the browser extension). It wraps the raw provider with the ergonomics every\n * dApp currently hand-rolls: a single-account `connect`, sign-and-submit, and a\n * cached `ensureApiKey` that decodes expiry via the audited api-key module\n * (replacing the copies in hub / prime-hub).\n *\n * The mobile deep-link/QR path uses the transport module (connect handshake +\n * sealed envelopes) instead of an injected provider; this client is the\n * same-device, extension-present case.\n */\n\nimport { decodeApiKey } from '../crypto/apikey'\nimport { WalletSdkError } from '../errors'\nimport { submitTransaction } from '../tx'\nimport type {\n\tAmadeusEventPayloadMap,\n\tAmadeusProvider,\n\tAmadeusProviderEvent,\n\tSignTransactionRequest,\n\tSignTransactionResponse\n} from '../types'\nimport { getAmadeusProvider } from '../types'\n\n/** Where a cached api-key lives. Default is in-memory; dApps can pass localStorage-backed. */\nexport interface ApiKeyStore {\n\tget(): string | null\n\tset(apiKey: string): void\n}\n\nfunction memoryApiKeyStore(): ApiKeyStore {\n\tlet value: string | null = null\n\treturn { get: () => value, set: (apiKey) => (value = apiKey) }\n}\n\nfunction isApiKeyValid(apiKey: string, leewaySeconds: number): boolean {\n\ttry {\n\t\tconst { payload } = decodeApiKey(apiKey)\n\t\treturn payload.exp > Math.floor(Date.now() / 1000) + leewaySeconds\n\t} catch {\n\t\treturn false\n\t}\n}\n\nexport interface WalletClient {\n\tisAvailable(): boolean\n\tgetProvider(): AmadeusProvider | null\n\t/** Prompt connection; resolves to the connected account (Base58 address). */\n\tconnect(): Promise<string>\n\tgetAccount(): Promise<string | null>\n\tgetNetwork(): Promise<string>\n\t/** Ask the wallet to switch the active account (user-confirmed); resolves to the new address. */\n\tswitchAccount(target?: string): Promise<string>\n\tsignTransaction(request: SignTransactionRequest): Promise<SignTransactionResponse>\n\t/** Sign then submit the packed bytes to a node; resolves to the tx hash + node reply. */\n\tsignAndSubmit(\n\t\trequest: SignTransactionRequest,\n\t\toptions: { nodeUrl: string; wait?: boolean }\n\t): Promise<{ txHash: string; submitted: unknown }>\n\t/** Return a valid cached api-key, minting (and caching) a fresh one if needed. Coalesces concurrent calls. */\n\tensureApiKey(options: {\n\t\taud: string\n\t\texpIn: number\n\t\tstore?: ApiKeyStore\n\t\tleewaySeconds?: number\n\t}): Promise<string>\n\ton<E extends AmadeusProviderEvent>(\n\t\tevent: E,\n\t\tcb: (data: AmadeusEventPayloadMap[E]) => void\n\t): void\n\toff<E extends AmadeusProviderEvent>(\n\t\tevent: E,\n\t\tcb: (data: AmadeusEventPayloadMap[E]) => void\n\t): void\n}\n\n/**\n * Create a client bound to the injected provider. Pass `providerOverride` to\n * inject a provider (e.g. in tests); otherwise it reads `window.amadeus`.\n */\nexport function createInjectedWalletClient(providerOverride?: AmadeusProvider): WalletClient {\n\tconst getProvider = () => providerOverride ?? getAmadeusProvider()\n\tconst requireProvider = (): AmadeusProvider => {\n\t\tconst provider = getProvider()\n\t\tif (!provider)\n\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'Amadeus wallet is not available')\n\t\treturn provider\n\t}\n\n\tconst defaultStore = memoryApiKeyStore()\n\tlet pendingApiKey: Promise<string> | null = null\n\n\treturn {\n\t\tisAvailable: () => getProvider() !== null,\n\t\tgetProvider,\n\t\tconnect: async () => {\n\t\t\tconst accounts = await requireProvider().requestAccounts()\n\t\t\tif (!accounts.length)\n\t\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'no account returned')\n\t\t\treturn accounts[0]\n\t\t},\n\t\tgetAccount: () => requireProvider().getAccount(),\n\t\tgetNetwork: () => requireProvider().getNetwork(),\n\t\tswitchAccount: async (target) => {\n\t\t\tconst provider = requireProvider()\n\t\t\tif (typeof provider.requestSwitchAccount !== 'function')\n\t\t\t\tthrow new WalletSdkError('UNSUPPORTED', 'wallet does not support switchAccount')\n\t\t\treturn provider.requestSwitchAccount(target)\n\t\t},\n\t\tsignTransaction: (request) => requireProvider().signTransaction(request),\n\t\tsignAndSubmit: async (request, options) => {\n\t\t\tconst { txHash, txPacked } = await requireProvider().signTransaction(request)\n\t\t\tconst submitted = await submitTransaction(txPacked, {\n\t\t\t\tnodeUrl: options.nodeUrl,\n\t\t\t\twait: options.wait\n\t\t\t})\n\t\t\treturn { txHash, submitted }\n\t\t},\n\t\tensureApiKey: ({ aud, expIn, store = defaultStore, leewaySeconds = 60 }) => {\n\t\t\tconst cached = store.get()\n\t\t\tif (cached && isApiKeyValid(cached, leewaySeconds)) return Promise.resolve(cached)\n\t\t\tif (!pendingApiKey) {\n\t\t\t\tpendingApiKey = requireProvider()\n\t\t\t\t\t.generateApiKey({ aud, exp_in: expIn })\n\t\t\t\t\t.then(({ apiKey }) => {\n\t\t\t\t\t\tstore.set(apiKey)\n\t\t\t\t\t\treturn apiKey\n\t\t\t\t\t})\n\t\t\t\t\t.finally(() => {\n\t\t\t\t\t\tpendingApiKey = null\n\t\t\t\t\t})\n\t\t\t}\n\t\t\treturn pendingApiKey\n\t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,gBAAgB,OAAO;GAK5E,OAAO;IAAE;IAAQ,WAAA,MAJO,kBAAkB,UAAU;KACnD,SAAS,QAAQ;KACjB,MAAM,QAAQ;IACf,CAAC;GAC0B;EAC5B;EACA,eAAe,EAAE,KAAK,OAAO,QAAQ,cAAc,gBAAgB,SAAS;GAC3E,MAAM,SAAS,MAAM,IAAI;GACzB,IAAI,UAAU,cAAc,QAAQ,aAAa,GAAG,OAAO,QAAQ,QAAQ,MAAM;GACjF,IAAI,CAAC,eACJ,gBAAgB,gBAAgB,CAAC,CAC/B,eAAe;IAAE;IAAK,QAAQ;GAAM,CAAC,CAAC,CACtC,MAAM,EAAE,aAAa;IACrB,MAAM,IAAI,MAAM;IAChB,OAAO;GACR,CAAC,CAAC,CACD,cAAc;IACd,gBAAgB;GACjB,CAAC;GAEH,OAAO;EACR;EACA,KAAK,OAAO,OAAO,gBAAgB,CAAC,CAAC,GAAG,OAAO,EAAE;EACjD,MAAM,OAAO,OAAO,gBAAgB,CAAC,CAAC,IAAI,OAAO,EAAE;CACpD;AACD"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Stable error codes so callers can branch without string-matching messages. */
|
|
2
|
-
type WalletSdkErrorCode = 'INVALID_API_KEY' | 'BAD_SIGNATURE' | 'EXPIRED' | 'AUD_MISMATCH' | 'INVALID_ADDRESS' | 'INVALID_SIGNATURE' | 'INVALID_ARGUMENT' | 'SUBMIT_FAILED' | 'DECRYPT_FAILED';
|
|
2
|
+
type WalletSdkErrorCode = 'INVALID_API_KEY' | 'BAD_SIGNATURE' | 'EXPIRED' | 'AUD_MISMATCH' | 'INVALID_ADDRESS' | 'INVALID_SIGNATURE' | 'INVALID_ARGUMENT' | 'SUBMIT_FAILED' | 'DECRYPT_FAILED' | 'UNSUPPORTED';
|
|
3
3
|
declare class WalletSdkError extends Error {
|
|
4
4
|
readonly code: WalletSdkErrorCode;
|
|
5
5
|
constructor(code: WalletSdkErrorCode, message: string);
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","names":[],"sources":["../src/errors.ts"],"mappings":";KACY;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","names":[],"sources":["../src/errors.ts"],"mappings":";KACY;cAYC,uBAAuB;WAC1B,MAAM;EAEH,YAAA,MAAM,oBAAoB"}
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Stable error codes so callers can branch without string-matching messages. */\nexport type WalletSdkErrorCode =\n\t| 'INVALID_API_KEY'\n\t| 'BAD_SIGNATURE'\n\t| 'EXPIRED'\n\t| 'AUD_MISMATCH'\n\t| 'INVALID_ADDRESS'\n\t| 'INVALID_SIGNATURE'\n\t| 'INVALID_ARGUMENT'\n\t| 'SUBMIT_FAILED'\n\t| 'DECRYPT_FAILED'\n\nexport class WalletSdkError extends Error {\n\treadonly code: WalletSdkErrorCode\n\n\tconstructor(code: WalletSdkErrorCode, message: string) {\n\t\tsuper(message)\n\t\tthis.name = 'WalletSdkError'\n\t\tthis.code = code\n\t\t// Restore prototype chain for instanceof across transpile targets.\n\t\tObject.setPrototypeOf(this, WalletSdkError.prototype)\n\t}\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Stable error codes so callers can branch without string-matching messages. */\nexport type WalletSdkErrorCode =\n\t| 'INVALID_API_KEY'\n\t| 'BAD_SIGNATURE'\n\t| 'EXPIRED'\n\t| 'AUD_MISMATCH'\n\t| 'INVALID_ADDRESS'\n\t| 'INVALID_SIGNATURE'\n\t| 'INVALID_ARGUMENT'\n\t| 'SUBMIT_FAILED'\n\t| 'DECRYPT_FAILED'\n\t| 'UNSUPPORTED'\n\nexport class WalletSdkError extends Error {\n\treadonly code: WalletSdkErrorCode\n\n\tconstructor(code: WalletSdkErrorCode, message: string) {\n\t\tsuper(message)\n\t\tthis.name = 'WalletSdkError'\n\t\tthis.code = code\n\t\t// Restore prototype chain for instanceof across transpile targets.\n\t\tObject.setPrototypeOf(this, WalletSdkError.prototype)\n\t}\n}\n"],"mappings":";AAaA,IAAa,iBAAb,MAAa,uBAAuB,MAAM;CACzC;CAEA,YAAY,MAA0B,SAAiB;EACtD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;EAEZ,OAAO,eAAe,MAAM,eAAe,SAAS;CACrD;AACD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { bytesToUtf8, concatBytes, equalBytes, randomBytes, randomId, u32be, utf
|
|
|
4
4
|
import { BYTES_TAG, TaggedBytes, decodeBinaryValues, describeBinaryValues, encodeBinaryValues, isTaggedBytes } from "./binary.js";
|
|
5
5
|
import { SignTransactionParams, SignedTransaction, SubmitTransactionOptions, signTransaction, submitTransaction } from "./tx.js";
|
|
6
6
|
import { AmadeusEventPayloadMap, AmadeusNetwork, AmadeusProvider, AmadeusProviderEvent, GenerateApiKeyRequest, GenerateApiKeyResponse, SignTransactionRequest, SignTransactionResponse, getAmadeusProvider, isProviderAvailable } from "./types.js";
|
|
7
|
-
import { ConnectTranscriptInput, GenerateApiKeyRequestInput, SignMessageRequestInput, SignTransactionRequestInput, addressSchema, connectTranscriptSchema, generateApiKeyRequestSchema, networkSchema, originSchema, sessionPublicKeySchema, signMessageRequestSchema, signTransactionRequestSchema } from "./schema.js";
|
|
7
|
+
import { ConnectTranscriptInput, GenerateApiKeyRequestInput, SignMessageRequestInput, SignTransactionRequestInput, SwitchAccountRequestInput, addressSchema, connectTranscriptSchema, generateApiKeyRequestSchema, networkSchema, originSchema, sessionPublicKeySchema, signMessageRequestSchema, signTransactionRequestSchema, switchAccountRequestSchema } from "./schema.js";
|
|
8
8
|
import { SignerKeys, deriveSigner, publicKeyFromAddress, signHashed, signatureFromBase58, verifyHashed } from "./crypto/bls.js";
|
|
9
9
|
import { ApiKeyPayload, DecodedApiKey, GenerateApiKeyParams, GenerateApiKeyResult, VerifyApiKeyOptions, VerifyApiKeyResult, decodeApiKey, generateApiKey, verifyApiKey } from "./crypto/apikey.js";
|
|
10
10
|
import { SignMessageParams, SignMessageResult, VerifyMessageParams, signMessage, verifyMessage } from "./crypto/message.js";
|
|
@@ -16,4 +16,4 @@ import { EstablishedSession, PendingConnect, WalletSession, approveConnect, comp
|
|
|
16
16
|
import { BridgeClient, BridgeClientOptions, BridgeFrame, assertAllowedBridgeUrl, deriveBridgeChannels, deriveConnectChannel } from "./transport/bridge.js";
|
|
17
17
|
import { WalletHandlerContext, handleRequest } from "./wallet/handler.js";
|
|
18
18
|
import { ApiKeyStore, WalletClient, createInjectedWalletClient } from "./client/injected.js";
|
|
19
|
-
export { API_KEY_DST, AmadeusEventPayloadMap, AmadeusNetwork, AmadeusProvider, AmadeusProviderEvent, ApiKeyPayload, ApiKeyStore, BYTES_TAG, BridgeClient, BridgeClientOptions, BridgeFrame, CONNECT_DST, CONNECT_TRANSCRIPT_LABEL, ConnectRequestParams, ConnectResponseParams, ConnectTranscript, ConnectTranscriptInput, DEFAULT_BRIDGE_URL, DecodedApiKey, EstablishedSession, GenerateApiKeyParams, GenerateApiKeyRequest, GenerateApiKeyRequestInput, GenerateApiKeyResponse, GenerateApiKeyResult, MAX_API_KEY_STRING_LENGTH, MAX_MESSAGE_LENGTH, MESSAGE_DST, NETWORKS, PROTOCOL_VERSION, PROVIDER_EVENTS, PROVIDER_GLOBAL, PUBLIC_KEY_BYTE_LENGTH, PendingConnect, SEED_BYTE_LENGTH, SESSION_NONCE_BYTE_LENGTH, SESSION_PUBLIC_KEY_BYTE_LENGTH, SESSION_SECRET_KEY_BYTE_LENGTH, SIGNATURE_BYTE_LENGTH, SealedEnvelope, SeenStore, SessionKeypair, SignConnectParams, SignMessageParams, SignMessageRequestInput, SignMessageResult, SignTransactionParams, SignTransactionRequest, SignTransactionRequestInput, SignTransactionResponse, SignedTransaction, SignerKeys, SubmitTransactionOptions, TX_DST, TaggedBytes, URI_SCHEME, VerifyApiKeyOptions, VerifyApiKeyResult, VerifyConnectParams, VerifyMessageParams, WALLET_INITIALIZED_EVENT, WALLET_METHODS, WALLET_WINDOW_EVENTS, WalletClient, WalletHandlerContext, WalletMethod, WalletRequest, WalletResponse, WalletSdkError, WalletSdkErrorCode, WalletSession, addressSchema, approveConnect, assertAllowedBridgeUrl, buildConnectResponseUri, buildConnectTranscript, buildConnectUri, bytesToUtf8, completeConnect, concatBytes, connectTranscriptSchema, createConnectRequest, createInjectedWalletClient, createMemorySeenStore, decodeApiKey, decodeBinaryValues, deriveBridgeChannels, deriveConnectChannel, deriveSharedKey, deriveSigner, describeBinaryValues, encodeBinaryValues, equalBytes, generateApiKey, generateApiKeyRequestSchema, generateSessionKeypair, getAmadeusProvider, guardRequest, handleRequest, isConnectRequestExpired, isProviderAvailable, isTaggedBytes, makeRequest, networkSchema, open, openRequest, openResponse, originSchema, parseConnectResponseUri, parseConnectUri, publicKeyFromAddress, randomBytes, randomId, seal, sealRequest, sealResponse, sessionPublicKeySchema, signConnect, signHashed, signMessage, signMessageRequestSchema, signTransaction, signTransactionRequestSchema, signatureFromBase58, submitTransaction, u32be, utf8ToBytes, verifyApiKey, verifyConnect, verifyHashed, verifyMessage };
|
|
19
|
+
export { API_KEY_DST, AmadeusEventPayloadMap, AmadeusNetwork, AmadeusProvider, AmadeusProviderEvent, ApiKeyPayload, ApiKeyStore, BYTES_TAG, BridgeClient, BridgeClientOptions, BridgeFrame, CONNECT_DST, CONNECT_TRANSCRIPT_LABEL, ConnectRequestParams, ConnectResponseParams, ConnectTranscript, ConnectTranscriptInput, DEFAULT_BRIDGE_URL, DecodedApiKey, EstablishedSession, GenerateApiKeyParams, GenerateApiKeyRequest, GenerateApiKeyRequestInput, GenerateApiKeyResponse, GenerateApiKeyResult, MAX_API_KEY_STRING_LENGTH, MAX_MESSAGE_LENGTH, MESSAGE_DST, NETWORKS, PROTOCOL_VERSION, PROVIDER_EVENTS, PROVIDER_GLOBAL, PUBLIC_KEY_BYTE_LENGTH, PendingConnect, SEED_BYTE_LENGTH, SESSION_NONCE_BYTE_LENGTH, SESSION_PUBLIC_KEY_BYTE_LENGTH, SESSION_SECRET_KEY_BYTE_LENGTH, SIGNATURE_BYTE_LENGTH, SealedEnvelope, SeenStore, SessionKeypair, SignConnectParams, SignMessageParams, SignMessageRequestInput, SignMessageResult, SignTransactionParams, SignTransactionRequest, SignTransactionRequestInput, SignTransactionResponse, SignedTransaction, SignerKeys, SubmitTransactionOptions, SwitchAccountRequestInput, TX_DST, TaggedBytes, URI_SCHEME, VerifyApiKeyOptions, VerifyApiKeyResult, VerifyConnectParams, VerifyMessageParams, WALLET_INITIALIZED_EVENT, WALLET_METHODS, WALLET_WINDOW_EVENTS, WalletClient, WalletHandlerContext, WalletMethod, WalletRequest, WalletResponse, WalletSdkError, WalletSdkErrorCode, WalletSession, addressSchema, approveConnect, assertAllowedBridgeUrl, buildConnectResponseUri, buildConnectTranscript, buildConnectUri, bytesToUtf8, completeConnect, concatBytes, connectTranscriptSchema, createConnectRequest, createInjectedWalletClient, createMemorySeenStore, decodeApiKey, decodeBinaryValues, deriveBridgeChannels, deriveConnectChannel, deriveSharedKey, deriveSigner, describeBinaryValues, encodeBinaryValues, equalBytes, generateApiKey, generateApiKeyRequestSchema, generateSessionKeypair, getAmadeusProvider, guardRequest, handleRequest, isConnectRequestExpired, isProviderAvailable, isTaggedBytes, makeRequest, networkSchema, open, openRequest, openResponse, originSchema, parseConnectResponseUri, parseConnectUri, publicKeyFromAddress, randomBytes, randomId, seal, sealRequest, sealResponse, sessionPublicKeySchema, signConnect, signHashed, signMessage, signMessageRequestSchema, signTransaction, signTransactionRequestSchema, signatureFromBase58, submitTransaction, switchAccountRequestSchema, u32be, utf8ToBytes, verifyApiKey, verifyConnect, verifyHashed, verifyMessage };
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { bytesToUtf8, concatBytes, equalBytes, randomBytes, randomId, u32be, utf
|
|
|
4
4
|
import { BYTES_TAG, decodeBinaryValues, describeBinaryValues, encodeBinaryValues, isTaggedBytes } from "./binary.js";
|
|
5
5
|
import { signTransaction, submitTransaction } from "./tx.js";
|
|
6
6
|
import { getAmadeusProvider, isProviderAvailable } from "./types.js";
|
|
7
|
-
import { addressSchema, connectTranscriptSchema, generateApiKeyRequestSchema, networkSchema, originSchema, sessionPublicKeySchema, signMessageRequestSchema, signTransactionRequestSchema } from "./schema.js";
|
|
7
|
+
import { addressSchema, connectTranscriptSchema, generateApiKeyRequestSchema, networkSchema, originSchema, sessionPublicKeySchema, signMessageRequestSchema, signTransactionRequestSchema, switchAccountRequestSchema } from "./schema.js";
|
|
8
8
|
import { deriveSigner, publicKeyFromAddress, signHashed, signatureFromBase58, verifyHashed } from "./crypto/bls.js";
|
|
9
9
|
import { decodeApiKey, generateApiKey, verifyApiKey } from "./crypto/apikey.js";
|
|
10
10
|
import { signMessage, verifyMessage } from "./crypto/message.js";
|
|
@@ -16,4 +16,4 @@ import { approveConnect, completeConnect, createConnectRequest, isConnectRequest
|
|
|
16
16
|
import { BridgeClient, assertAllowedBridgeUrl, deriveBridgeChannels, deriveConnectChannel } from "./transport/bridge.js";
|
|
17
17
|
import { handleRequest } from "./wallet/handler.js";
|
|
18
18
|
import { createInjectedWalletClient } from "./client/injected.js";
|
|
19
|
-
export { API_KEY_DST, BYTES_TAG, BridgeClient, CONNECT_DST, CONNECT_TRANSCRIPT_LABEL, DEFAULT_BRIDGE_URL, MAX_API_KEY_STRING_LENGTH, MAX_MESSAGE_LENGTH, MESSAGE_DST, NETWORKS, PROTOCOL_VERSION, PROVIDER_EVENTS, PROVIDER_GLOBAL, PUBLIC_KEY_BYTE_LENGTH, SEED_BYTE_LENGTH, SESSION_NONCE_BYTE_LENGTH, SESSION_PUBLIC_KEY_BYTE_LENGTH, SESSION_SECRET_KEY_BYTE_LENGTH, SIGNATURE_BYTE_LENGTH, TX_DST, URI_SCHEME, WALLET_INITIALIZED_EVENT, WALLET_METHODS, WALLET_WINDOW_EVENTS, WalletSdkError, addressSchema, approveConnect, assertAllowedBridgeUrl, buildConnectResponseUri, buildConnectTranscript, buildConnectUri, bytesToUtf8, completeConnect, concatBytes, connectTranscriptSchema, createConnectRequest, createInjectedWalletClient, createMemorySeenStore, decodeApiKey, decodeBinaryValues, deriveBridgeChannels, deriveConnectChannel, deriveSharedKey, deriveSigner, describeBinaryValues, encodeBinaryValues, equalBytes, generateApiKey, generateApiKeyRequestSchema, generateSessionKeypair, getAmadeusProvider, guardRequest, handleRequest, isConnectRequestExpired, isProviderAvailable, isTaggedBytes, makeRequest, networkSchema, open, openRequest, openResponse, originSchema, parseConnectResponseUri, parseConnectUri, publicKeyFromAddress, randomBytes, randomId, seal, sealRequest, sealResponse, sessionPublicKeySchema, signConnect, signHashed, signMessage, signMessageRequestSchema, signTransaction, signTransactionRequestSchema, signatureFromBase58, submitTransaction, u32be, utf8ToBytes, verifyApiKey, verifyConnect, verifyHashed, verifyMessage };
|
|
19
|
+
export { API_KEY_DST, BYTES_TAG, BridgeClient, CONNECT_DST, CONNECT_TRANSCRIPT_LABEL, DEFAULT_BRIDGE_URL, MAX_API_KEY_STRING_LENGTH, MAX_MESSAGE_LENGTH, MESSAGE_DST, NETWORKS, PROTOCOL_VERSION, PROVIDER_EVENTS, PROVIDER_GLOBAL, PUBLIC_KEY_BYTE_LENGTH, SEED_BYTE_LENGTH, SESSION_NONCE_BYTE_LENGTH, SESSION_PUBLIC_KEY_BYTE_LENGTH, SESSION_SECRET_KEY_BYTE_LENGTH, SIGNATURE_BYTE_LENGTH, TX_DST, URI_SCHEME, WALLET_INITIALIZED_EVENT, WALLET_METHODS, WALLET_WINDOW_EVENTS, WalletSdkError, addressSchema, approveConnect, assertAllowedBridgeUrl, buildConnectResponseUri, buildConnectTranscript, buildConnectUri, bytesToUtf8, completeConnect, concatBytes, connectTranscriptSchema, createConnectRequest, createInjectedWalletClient, createMemorySeenStore, decodeApiKey, decodeBinaryValues, deriveBridgeChannels, deriveConnectChannel, deriveSharedKey, deriveSigner, describeBinaryValues, encodeBinaryValues, equalBytes, generateApiKey, generateApiKeyRequestSchema, generateSessionKeypair, getAmadeusProvider, guardRequest, handleRequest, isConnectRequestExpired, isProviderAvailable, isTaggedBytes, makeRequest, networkSchema, open, openRequest, openResponse, originSchema, parseConnectResponseUri, parseConnectUri, publicKeyFromAddress, randomBytes, randomId, seal, sealRequest, sealResponse, sessionPublicKeySchema, signConnect, signHashed, signMessage, signMessageRequestSchema, signTransaction, signTransactionRequestSchema, signatureFromBase58, submitTransaction, switchAccountRequestSchema, u32be, utf8ToBytes, verifyApiKey, verifyConnect, verifyHashed, verifyMessage };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ interface UseWalletResult {
|
|
|
9
9
|
isAvailable: boolean;
|
|
10
10
|
connect: () => Promise<void>;
|
|
11
11
|
disconnect: () => void;
|
|
12
|
+
/** Switch the active account (user-confirmed in the wallet); `account` reflects the change via the provider's accountsChanged event. */
|
|
13
|
+
switchAccount: (target?: string) => Promise<string>;
|
|
12
14
|
signTransaction: (request: SignTransactionRequest) => Promise<SignTransactionResponse>;
|
|
13
15
|
signAndSubmit: WalletClient['signAndSubmit'];
|
|
14
16
|
ensureApiKey: WalletClient['ensureApiKey'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/react/index.ts"],"mappings":";;KAoBY;UAEK;EAChB,QAAQ;EACR,QAAQ;EACR;EACA;EACA;EACA,eAAe;EACf;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/react/index.ts"],"mappings":";;KAoBY;UAEK;EAChB,QAAQ;EACR,QAAQ;EACR;EACA;EACA;EACA,eAAe;EACf;;EAEA,gBAAgB,oBAAoB;EACpC,kBAAkB,SAAS,2BAA2B,QAAQ;EAC9D,eAAe;EACf,cAAc;;iBAGC,aAAa"}
|
package/dist/react/index.js
CHANGED
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/react/index.ts"],"sourcesContent":["/**\n * React ergonomics for dApps: a single `useWallet()` hook over the injected\n * provider client. It fixes the `amadeus#initialized` vs `amadeus-wallet#initialized`\n * detection bug once (dApps historically listened for the wrong name) and wires\n * the provider's account/network/disconnect events into state.\n *\n * Imported from the `@amadeus-protocol/wallet-sdk/react` subpath so non-React\n * consumers (the mobile wallet, node verifiers) never pull in React.\n */\n\nimport { useCallback, useEffect, useMemo, useState } from 'react'\n\nimport { createInjectedWalletClient, type WalletClient } from '../client/injected'\nimport { WALLET_INITIALIZED_EVENT } from '../constants'\nimport type {\n\tAmadeusEventPayloadMap,\n\tSignTransactionRequest,\n\tSignTransactionResponse\n} from '../types'\n\nexport type WalletStatus = 'unavailable' | 'disconnected' | 'connecting' | 'connected'\n\nexport interface UseWalletResult {\n\tclient: WalletClient\n\tstatus: WalletStatus\n\taccount: string | null\n\tnetwork: string | null\n\tisAvailable: boolean\n\tconnect: () => Promise<void>\n\tdisconnect: () => void\n\tsignTransaction: (request: SignTransactionRequest) => Promise<SignTransactionResponse>\n\tsignAndSubmit: WalletClient['signAndSubmit']\n\tensureApiKey: WalletClient['ensureApiKey']\n}\n\nexport function useWallet(): UseWalletResult {\n\tconst client = useMemo(() => createInjectedWalletClient(), [])\n\tconst [status, setStatus] = useState<WalletStatus>(() =>\n\t\tclient.isAvailable() ? 'disconnected' : 'unavailable'\n\t)\n\tconst [account, setAccount] = useState<string | null>(null)\n\tconst [network, setNetwork] = useState<string | null>(null)\n\n\t// Detect a (possibly late-injected) provider, then read initial account/network.\n\tuseEffect(() => {\n\t\tif (typeof window === 'undefined') return\n\t\tconst onInit = () => {\n\t\t\tif (client.isAvailable()) setStatus((s) => (s === 'unavailable' ? 'disconnected' : s))\n\t\t}\n\t\twindow.addEventListener(WALLET_INITIALIZED_EVENT, onInit)\n\t\tif (client.isAvailable()) {\n\t\t\tclient\n\t\t\t\t.getAccount()\n\t\t\t\t.then((a) => {\n\t\t\t\t\tif (a) {\n\t\t\t\t\t\tsetAccount(a)\n\t\t\t\t\t\tsetStatus('connected')\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch(() => {})\n\t\t\tclient\n\t\t\t\t.getNetwork()\n\t\t\t\t.then(setNetwork)\n\t\t\t\t.catch(() => {})\n\t\t}\n\t\treturn () => window.removeEventListener(WALLET_INITIALIZED_EVENT, onInit)\n\t}, [client])\n\n\t// Mirror provider events into state.\n\tuseEffect(() => {\n\t\tif (!client.isAvailable()) return\n\t\tconst applyAccounts = (accounts: string[]) => {\n\t\t\tconst next = accounts[0] ?? null\n\t\t\tsetAccount(next)\n\t\t\tsetStatus(next ? 'connected' : 'disconnected')\n\t\t}\n\t\tconst onAccountsChanged = (d: AmadeusEventPayloadMap['accountsChanged']) =>\n\t\t\tapplyAccounts(d.accounts)\n\t\tconst onConnect = (d: AmadeusEventPayloadMap['connect']) => {\n\t\t\tapplyAccounts(d.accounts)\n\t\t\tsetNetwork(d.network)\n\t\t}\n\t\tconst onDisconnect = () => {\n\t\t\tsetAccount(null)\n\t\t\tsetStatus('disconnected')\n\t\t}\n\t\tconst onNetworkChanged = (d: AmadeusEventPayloadMap['networkChanged']) =>\n\t\t\tsetNetwork(d.network)\n\n\t\tclient.on('accountsChanged', onAccountsChanged)\n\t\tclient.on('connect', onConnect)\n\t\tclient.on('disconnect', onDisconnect)\n\t\tclient.on('networkChanged', onNetworkChanged)\n\t\treturn () => {\n\t\t\tclient.off('accountsChanged', onAccountsChanged)\n\t\t\tclient.off('connect', onConnect)\n\t\t\tclient.off('disconnect', onDisconnect)\n\t\t\tclient.off('networkChanged', onNetworkChanged)\n\t\t}\n\t}, [client])\n\n\tconst connect = useCallback(async () => {\n\t\tsetStatus('connecting')\n\t\ttry {\n\t\t\tconst a = await client.connect()\n\t\t\tsetAccount(a)\n\t\t\tsetStatus('connected')\n\t\t} catch (error) {\n\t\t\tsetStatus(client.isAvailable() ? 'disconnected' : 'unavailable')\n\t\t\tthrow error\n\t\t}\n\t}, [client])\n\n\tconst disconnect = useCallback(() => {\n\t\tsetAccount(null)\n\t\tsetStatus('disconnected')\n\t}, [])\n\n\treturn {\n\t\tclient,\n\t\tstatus,\n\t\taccount,\n\t\tnetwork,\n\t\tisAvailable: client.isAvailable(),\n\t\tconnect,\n\t\tdisconnect,\n\t\tsignTransaction: client.signTransaction,\n\t\tsignAndSubmit: client.signAndSubmit,\n\t\tensureApiKey: client.ensureApiKey\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/react/index.ts"],"sourcesContent":["/**\n * React ergonomics for dApps: a single `useWallet()` hook over the injected\n * provider client. It fixes the `amadeus#initialized` vs `amadeus-wallet#initialized`\n * detection bug once (dApps historically listened for the wrong name) and wires\n * the provider's account/network/disconnect events into state.\n *\n * Imported from the `@amadeus-protocol/wallet-sdk/react` subpath so non-React\n * consumers (the mobile wallet, node verifiers) never pull in React.\n */\n\nimport { useCallback, useEffect, useMemo, useState } from 'react'\n\nimport { createInjectedWalletClient, type WalletClient } from '../client/injected'\nimport { WALLET_INITIALIZED_EVENT } from '../constants'\nimport type {\n\tAmadeusEventPayloadMap,\n\tSignTransactionRequest,\n\tSignTransactionResponse\n} from '../types'\n\nexport type WalletStatus = 'unavailable' | 'disconnected' | 'connecting' | 'connected'\n\nexport interface UseWalletResult {\n\tclient: WalletClient\n\tstatus: WalletStatus\n\taccount: string | null\n\tnetwork: string | null\n\tisAvailable: boolean\n\tconnect: () => Promise<void>\n\tdisconnect: () => void\n\t/** Switch the active account (user-confirmed in the wallet); `account` reflects the change via the provider's accountsChanged event. */\n\tswitchAccount: (target?: string) => Promise<string>\n\tsignTransaction: (request: SignTransactionRequest) => Promise<SignTransactionResponse>\n\tsignAndSubmit: WalletClient['signAndSubmit']\n\tensureApiKey: WalletClient['ensureApiKey']\n}\n\nexport function useWallet(): UseWalletResult {\n\tconst client = useMemo(() => createInjectedWalletClient(), [])\n\tconst [status, setStatus] = useState<WalletStatus>(() =>\n\t\tclient.isAvailable() ? 'disconnected' : 'unavailable'\n\t)\n\tconst [account, setAccount] = useState<string | null>(null)\n\tconst [network, setNetwork] = useState<string | null>(null)\n\n\t// Detect a (possibly late-injected) provider, then read initial account/network.\n\tuseEffect(() => {\n\t\tif (typeof window === 'undefined') return\n\t\tconst onInit = () => {\n\t\t\tif (client.isAvailable()) setStatus((s) => (s === 'unavailable' ? 'disconnected' : s))\n\t\t}\n\t\twindow.addEventListener(WALLET_INITIALIZED_EVENT, onInit)\n\t\tif (client.isAvailable()) {\n\t\t\tclient\n\t\t\t\t.getAccount()\n\t\t\t\t.then((a) => {\n\t\t\t\t\tif (a) {\n\t\t\t\t\t\tsetAccount(a)\n\t\t\t\t\t\tsetStatus('connected')\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch(() => {})\n\t\t\tclient\n\t\t\t\t.getNetwork()\n\t\t\t\t.then(setNetwork)\n\t\t\t\t.catch(() => {})\n\t\t}\n\t\treturn () => window.removeEventListener(WALLET_INITIALIZED_EVENT, onInit)\n\t}, [client])\n\n\t// Mirror provider events into state.\n\tuseEffect(() => {\n\t\tif (!client.isAvailable()) return\n\t\tconst applyAccounts = (accounts: string[]) => {\n\t\t\tconst next = accounts[0] ?? null\n\t\t\tsetAccount(next)\n\t\t\tsetStatus(next ? 'connected' : 'disconnected')\n\t\t}\n\t\tconst onAccountsChanged = (d: AmadeusEventPayloadMap['accountsChanged']) =>\n\t\t\tapplyAccounts(d.accounts)\n\t\tconst onConnect = (d: AmadeusEventPayloadMap['connect']) => {\n\t\t\tapplyAccounts(d.accounts)\n\t\t\tsetNetwork(d.network)\n\t\t}\n\t\tconst onDisconnect = () => {\n\t\t\tsetAccount(null)\n\t\t\tsetStatus('disconnected')\n\t\t}\n\t\tconst onNetworkChanged = (d: AmadeusEventPayloadMap['networkChanged']) =>\n\t\t\tsetNetwork(d.network)\n\n\t\tclient.on('accountsChanged', onAccountsChanged)\n\t\tclient.on('connect', onConnect)\n\t\tclient.on('disconnect', onDisconnect)\n\t\tclient.on('networkChanged', onNetworkChanged)\n\t\treturn () => {\n\t\t\tclient.off('accountsChanged', onAccountsChanged)\n\t\t\tclient.off('connect', onConnect)\n\t\t\tclient.off('disconnect', onDisconnect)\n\t\t\tclient.off('networkChanged', onNetworkChanged)\n\t\t}\n\t}, [client])\n\n\tconst connect = useCallback(async () => {\n\t\tsetStatus('connecting')\n\t\ttry {\n\t\t\tconst a = await client.connect()\n\t\t\tsetAccount(a)\n\t\t\tsetStatus('connected')\n\t\t} catch (error) {\n\t\t\tsetStatus(client.isAvailable() ? 'disconnected' : 'unavailable')\n\t\t\tthrow error\n\t\t}\n\t}, [client])\n\n\tconst disconnect = useCallback(() => {\n\t\tsetAccount(null)\n\t\tsetStatus('disconnected')\n\t}, [])\n\n\treturn {\n\t\tclient,\n\t\tstatus,\n\t\taccount,\n\t\tnetwork,\n\t\tisAvailable: client.isAvailable(),\n\t\tconnect,\n\t\tdisconnect,\n\t\tswitchAccount: client.switchAccount,\n\t\tsignTransaction: client.signTransaction,\n\t\tsignAndSubmit: client.signAndSubmit,\n\t\tensureApiKey: client.ensureApiKey\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;AAqCA,SAAgB,YAA6B;CAC5C,MAAM,SAAS,cAAc,2BAA2B,GAAG,CAAC,CAAC;CAC7D,MAAM,CAAC,QAAQ,aAAa,eAC3B,OAAO,YAAY,IAAI,iBAAiB,aACzC;CACA,MAAM,CAAC,SAAS,cAAc,SAAwB,IAAI;CAC1D,MAAM,CAAC,SAAS,cAAc,SAAwB,IAAI;CAG1D,gBAAgB;EACf,IAAI,OAAO,WAAW,aAAa;EACnC,MAAM,eAAe;GACpB,IAAI,OAAO,YAAY,GAAG,WAAW,MAAO,MAAM,gBAAgB,iBAAiB,CAAE;EACtF;EACA,OAAO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iBAAiB,aAAa;GAC/D,MAAM;EACP;CACD,GAAG,CAAC,MAAM,CAAC;CAEX,MAAM,aAAa,kBAAkB;EACpC,WAAW,IAAI;EACf,UAAU,cAAc;CACzB,GAAG,CAAC,CAAC;CAEL,OAAO;EACN;EACA;EACA;EACA;EACA,aAAa,OAAO,YAAY;EAChC;EACA;EACA,eAAe,OAAO;EACtB,iBAAiB,OAAO;EACxB,eAAe,OAAO;EACtB,cAAc,OAAO;CACtB;AACD"}
|
package/dist/schema.d.ts
CHANGED
|
@@ -42,6 +42,14 @@ declare const signMessageRequestSchema: z.ZodObject<{
|
|
|
42
42
|
}, {
|
|
43
43
|
message: string;
|
|
44
44
|
}>;
|
|
45
|
+
/** `switchAccount` params — optional Base58 address hint; when absent the wallet shows its own account chooser. */
|
|
46
|
+
declare const switchAccountRequestSchema: z.ZodObject<{
|
|
47
|
+
account: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
48
|
+
}, "strip", z.ZodTypeAny, {
|
|
49
|
+
account?: string | undefined;
|
|
50
|
+
}, {
|
|
51
|
+
account?: string | undefined;
|
|
52
|
+
}>;
|
|
45
53
|
/** The connect transcript fields carried by a deep link / QR payload. */
|
|
46
54
|
declare const connectTranscriptSchema: z.ZodObject<{
|
|
47
55
|
origin: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -65,6 +73,7 @@ declare const connectTranscriptSchema: z.ZodObject<{
|
|
|
65
73
|
type SignTransactionRequestInput = z.infer<typeof signTransactionRequestSchema>;
|
|
66
74
|
type GenerateApiKeyRequestInput = z.infer<typeof generateApiKeyRequestSchema>;
|
|
67
75
|
type SignMessageRequestInput = z.infer<typeof signMessageRequestSchema>;
|
|
76
|
+
type SwitchAccountRequestInput = z.infer<typeof switchAccountRequestSchema>;
|
|
68
77
|
type ConnectTranscriptInput = z.infer<typeof connectTranscriptSchema>;
|
|
69
|
-
export { ConnectTranscriptInput, GenerateApiKeyRequestInput, SignMessageRequestInput, SignTransactionRequestInput, addressSchema, connectTranscriptSchema, generateApiKeyRequestSchema, networkSchema, originSchema, sessionPublicKeySchema, signMessageRequestSchema, signTransactionRequestSchema };
|
|
78
|
+
export { ConnectTranscriptInput, GenerateApiKeyRequestInput, SignMessageRequestInput, SignTransactionRequestInput, SwitchAccountRequestInput, addressSchema, connectTranscriptSchema, generateApiKeyRequestSchema, networkSchema, originSchema, sessionPublicKeySchema, signMessageRequestSchema, signTransactionRequestSchema, switchAccountRequestSchema };
|
|
70
79
|
//# sourceMappingURL=schema.d.ts.map
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","names":[],"sources":["../src/schema.ts"],"mappings":";;cAiCa,cAAY,EAAA,WAAA,EAAA;;cAKZ,eAAa,EAAA,WAAA,EAAA;;cAGb,wBAAsB,EAAA,WAAA,EAAA;cAKtB,eAAa,EAAA;;cAGb,8BAA4B,EAAA;;;;;;;;;;;;;;;;;cAQ5B,6BAA2B,EAAA;;;;;;;;;;;cAM3B,0BAAwB,EAAA;;;;;;;;cAKxB,yBAAuB,EAAA;;;;;;;;;;;;;;;;;;;KAQxB,8BAA8B,EAAE,aAAa;KAC7C,6BAA6B,EAAE,aAAa;KAC5C,0BAA0B,EAAE,aAAa;KACzC,yBAAyB,EAAE,aAAa"}
|
|
1
|
+
{"version":3,"file":"schema.d.ts","names":[],"sources":["../src/schema.ts"],"mappings":";;cAiCa,cAAY,EAAA,WAAA,EAAA;;cAKZ,eAAa,EAAA,WAAA,EAAA;;cAGb,wBAAsB,EAAA,WAAA,EAAA;cAKtB,eAAa,EAAA;;cAGb,8BAA4B,EAAA;;;;;;;;;;;;;;;;;cAQ5B,6BAA2B,EAAA;;;;;;;;;;;cAM3B,0BAAwB,EAAA;;;;;;;;cAKxB,4BAA0B,EAAA;;;;;;;;cAK1B,yBAAuB,EAAA;;;;;;;;;;;;;;;;;;;KAQxB,8BAA8B,EAAE,aAAa;KAC7C,6BAA6B,EAAE,aAAa;KAC5C,0BAA0B,EAAE,aAAa;KACzC,4BAA4B,EAAE,aAAa;KAC3C,yBAAyB,EAAE,aAAa"}
|
package/dist/schema.js
CHANGED
|
@@ -40,6 +40,8 @@ const generateApiKeyRequestSchema = z.object({
|
|
|
40
40
|
});
|
|
41
41
|
/** `signMessage` params — an arbitrary UTF-8 message, bounded for safety. */
|
|
42
42
|
const signMessageRequestSchema = z.object({ message: z.string().min(1).max(MAX_MESSAGE_LENGTH) });
|
|
43
|
+
/** `switchAccount` params — optional Base58 address hint; when absent the wallet shows its own account chooser. */
|
|
44
|
+
const switchAccountRequestSchema = z.object({ account: addressSchema.optional() });
|
|
43
45
|
/** The connect transcript fields carried by a deep link / QR payload. */
|
|
44
46
|
const connectTranscriptSchema = z.object({
|
|
45
47
|
origin: originSchema,
|
|
@@ -48,6 +50,6 @@ const connectTranscriptSchema = z.object({
|
|
|
48
50
|
challenge: z.string().min(1),
|
|
49
51
|
requestId: z.string().min(1)
|
|
50
52
|
});
|
|
51
|
-
export { addressSchema, connectTranscriptSchema, generateApiKeyRequestSchema, networkSchema, originSchema, sessionPublicKeySchema, signMessageRequestSchema, signTransactionRequestSchema };
|
|
53
|
+
export { addressSchema, connectTranscriptSchema, generateApiKeyRequestSchema, networkSchema, originSchema, sessionPublicKeySchema, signMessageRequestSchema, signTransactionRequestSchema, switchAccountRequestSchema };
|
|
52
54
|
|
|
53
55
|
//# sourceMappingURL=schema.js.map
|
package/dist/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":[],"sources":["../src/schema.ts"],"sourcesContent":["/**\n * Runtime validation for untrusted wire input (deep links, QR payloads, bridge\n * frames, cross-origin messages). Validate BEFORE any request is shown for\n * approval or signed. Zod is used here because it is already the schema library\n * on the wallet + dApp side; the lower-level SDK uses `effect` internally, which\n * is intentionally not a dependency of this package.\n */\n\nimport { fromBase58 } from '@amadeus-protocol/sdk'\nimport { z } from 'zod'\n\nimport {\n\tMAX_MESSAGE_LENGTH,\n\tNETWORKS,\n\tPUBLIC_KEY_BYTE_LENGTH,\n\tSESSION_PUBLIC_KEY_BYTE_LENGTH\n} from './constants'\n\n/** A Base58 string that decodes to exactly `length` bytes. */\nfunction base58OfLength(length: number, label: string) {\n\treturn z.string().refine(\n\t\t(v) => {\n\t\t\ttry {\n\t\t\t\treturn fromBase58(v).length === length\n\t\t\t} catch {\n\t\t\t\treturn false\n\t\t\t}\n\t\t},\n\t\t{ message: `${label} must decode to ${length} bytes` }\n\t)\n}\n\n/** http(s) origin, matching the extension's `originSchema`. */\nexport const originSchema = z\n\t.string()\n\t.refine((v) => /^https?:\\/\\//.test(v), { message: 'origin must be an http(s) URL' })\n\n/** A Base58 string that decodes to a 48-byte Amadeus public key / address. */\nexport const addressSchema = base58OfLength(PUBLIC_KEY_BYTE_LENGTH, 'address')\n\n/** A Base58 string that decodes to a 32-byte x25519 session public key. */\nexport const sessionPublicKeySchema = base58OfLength(\n\tSESSION_PUBLIC_KEY_BYTE_LENGTH,\n\t'session public key'\n)\n\nexport const networkSchema = z.enum(NETWORKS)\n\n/** `signTransaction` params — mirrors `ExternalSignRequestMessageSchema`. */\nexport const signTransactionRequestSchema = z.object({\n\tcontract: z.string().min(1),\n\tmethod: z.string().min(1),\n\targs: z.array(z.unknown()),\n\tdescription: z.string().optional()\n})\n\n/** `generateApiKey` params — mirrors `ExternalApiKeyRequestMessageSchema`. */\nexport const generateApiKeyRequestSchema = z.object({\n\taud: z.string().min(1),\n\texp_in: z.number().int().positive()\n})\n\n/** `signMessage` params — an arbitrary UTF-8 message, bounded for safety. */\nexport const signMessageRequestSchema = z.object({\n\tmessage: z.string().min(1).max(MAX_MESSAGE_LENGTH)\n})\n\n/** The connect transcript fields carried by a deep link / QR payload. */\nexport const connectTranscriptSchema = z.object({\n\torigin: originSchema,\n\tdappPublicKey: sessionPublicKeySchema,\n\twalletPublicKey: sessionPublicKeySchema,\n\tchallenge: z.string().min(1),\n\trequestId: z.string().min(1)\n})\n\nexport type SignTransactionRequestInput = z.infer<typeof signTransactionRequestSchema>\nexport type GenerateApiKeyRequestInput = z.infer<typeof generateApiKeyRequestSchema>\nexport type SignMessageRequestInput = z.infer<typeof signMessageRequestSchema>\nexport type ConnectTranscriptInput = z.infer<typeof connectTranscriptSchema>\n"],"mappings":";;;;;;;;;;;;AAmBA,SAAS,eAAe,QAAgB,OAAe;CACtD,OAAO,EAAE,OAAO,CAAC,CAAC,QAChB,MAAM;EACN,IAAI;GACH,OAAO,WAAW,CAAC,CAAC,CAAC,WAAW;EACjC,QAAQ;GACP,OAAO;EACR;CACD,GACA,EAAE,SAAS,GAAG,MAAM,kBAAkB,OAAO,QAAQ,CACtD;AACD;;AAGA,MAAa,eAAe,EAC1B,OAAO,CAAC,CACR,QAAQ,MAAM,eAAe,KAAK,CAAC,GAAG,EAAE,SAAS,gCAAgC,CAAC;;AAGpF,MAAa,gBAAgB,eAAA,IAAuC,SAAS;;AAG7E,MAAa,yBAAyB,eAAA,IAErC,oBACD;AAEA,MAAa,gBAAgB,EAAE,KAAK,QAAQ;;AAG5C,MAAa,+BAA+B,EAAE,OAAO;CACpD,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CAC1B,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACxB,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC;CACzB,aAAa,EAAE,OAAO,CAAC,CAAC,SAAS;AAClC,CAAC;;AAGD,MAAa,8BAA8B,EAAE,OAAO;CACnD,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACrB,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS;AACnC,CAAC;;AAGD,MAAa,2BAA2B,EAAE,OAAO,EAChD,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,kBAAkB,EAClD,CAAC;;AAGD,MAAa,0BAA0B,EAAE,OAAO;CAC/C,QAAQ;CACR,eAAe;CACf,iBAAiB;CACjB,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CAC3B,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;AAC5B,CAAC"}
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../src/schema.ts"],"sourcesContent":["/**\n * Runtime validation for untrusted wire input (deep links, QR payloads, bridge\n * frames, cross-origin messages). Validate BEFORE any request is shown for\n * approval or signed. Zod is used here because it is already the schema library\n * on the wallet + dApp side; the lower-level SDK uses `effect` internally, which\n * is intentionally not a dependency of this package.\n */\n\nimport { fromBase58 } from '@amadeus-protocol/sdk'\nimport { z } from 'zod'\n\nimport {\n\tMAX_MESSAGE_LENGTH,\n\tNETWORKS,\n\tPUBLIC_KEY_BYTE_LENGTH,\n\tSESSION_PUBLIC_KEY_BYTE_LENGTH\n} from './constants'\n\n/** A Base58 string that decodes to exactly `length` bytes. */\nfunction base58OfLength(length: number, label: string) {\n\treturn z.string().refine(\n\t\t(v) => {\n\t\t\ttry {\n\t\t\t\treturn fromBase58(v).length === length\n\t\t\t} catch {\n\t\t\t\treturn false\n\t\t\t}\n\t\t},\n\t\t{ message: `${label} must decode to ${length} bytes` }\n\t)\n}\n\n/** http(s) origin, matching the extension's `originSchema`. */\nexport const originSchema = z\n\t.string()\n\t.refine((v) => /^https?:\\/\\//.test(v), { message: 'origin must be an http(s) URL' })\n\n/** A Base58 string that decodes to a 48-byte Amadeus public key / address. */\nexport const addressSchema = base58OfLength(PUBLIC_KEY_BYTE_LENGTH, 'address')\n\n/** A Base58 string that decodes to a 32-byte x25519 session public key. */\nexport const sessionPublicKeySchema = base58OfLength(\n\tSESSION_PUBLIC_KEY_BYTE_LENGTH,\n\t'session public key'\n)\n\nexport const networkSchema = z.enum(NETWORKS)\n\n/** `signTransaction` params — mirrors `ExternalSignRequestMessageSchema`. */\nexport const signTransactionRequestSchema = z.object({\n\tcontract: z.string().min(1),\n\tmethod: z.string().min(1),\n\targs: z.array(z.unknown()),\n\tdescription: z.string().optional()\n})\n\n/** `generateApiKey` params — mirrors `ExternalApiKeyRequestMessageSchema`. */\nexport const generateApiKeyRequestSchema = z.object({\n\taud: z.string().min(1),\n\texp_in: z.number().int().positive()\n})\n\n/** `signMessage` params — an arbitrary UTF-8 message, bounded for safety. */\nexport const signMessageRequestSchema = z.object({\n\tmessage: z.string().min(1).max(MAX_MESSAGE_LENGTH)\n})\n\n/** `switchAccount` params — optional Base58 address hint; when absent the wallet shows its own account chooser. */\nexport const switchAccountRequestSchema = z.object({\n\taccount: addressSchema.optional()\n})\n\n/** The connect transcript fields carried by a deep link / QR payload. */\nexport const connectTranscriptSchema = z.object({\n\torigin: originSchema,\n\tdappPublicKey: sessionPublicKeySchema,\n\twalletPublicKey: sessionPublicKeySchema,\n\tchallenge: z.string().min(1),\n\trequestId: z.string().min(1)\n})\n\nexport type SignTransactionRequestInput = z.infer<typeof signTransactionRequestSchema>\nexport type GenerateApiKeyRequestInput = z.infer<typeof generateApiKeyRequestSchema>\nexport type SignMessageRequestInput = z.infer<typeof signMessageRequestSchema>\nexport type SwitchAccountRequestInput = z.infer<typeof switchAccountRequestSchema>\nexport type ConnectTranscriptInput = z.infer<typeof connectTranscriptSchema>\n"],"mappings":";;;;;;;;;;;;AAmBA,SAAS,eAAe,QAAgB,OAAe;CACtD,OAAO,EAAE,OAAO,CAAC,CAAC,QAChB,MAAM;EACN,IAAI;GACH,OAAO,WAAW,CAAC,CAAC,CAAC,WAAW;EACjC,QAAQ;GACP,OAAO;EACR;CACD,GACA,EAAE,SAAS,GAAG,MAAM,kBAAkB,OAAO,QAAQ,CACtD;AACD;;AAGA,MAAa,eAAe,EAC1B,OAAO,CAAC,CACR,QAAQ,MAAM,eAAe,KAAK,CAAC,GAAG,EAAE,SAAS,gCAAgC,CAAC;;AAGpF,MAAa,gBAAgB,eAAA,IAAuC,SAAS;;AAG7E,MAAa,yBAAyB,eAAA,IAErC,oBACD;AAEA,MAAa,gBAAgB,EAAE,KAAK,QAAQ;;AAG5C,MAAa,+BAA+B,EAAE,OAAO;CACpD,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CAC1B,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACxB,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC;CACzB,aAAa,EAAE,OAAO,CAAC,CAAC,SAAS;AAClC,CAAC;;AAGD,MAAa,8BAA8B,EAAE,OAAO;CACnD,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACrB,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS;AACnC,CAAC;;AAGD,MAAa,2BAA2B,EAAE,OAAO,EAChD,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,kBAAkB,EAClD,CAAC;;AAGD,MAAa,6BAA6B,EAAE,OAAO,EAClD,SAAS,cAAc,SAAS,EACjC,CAAC;;AAGD,MAAa,0BAA0B,EAAE,OAAO;CAC/C,QAAQ;CACR,eAAe;CACf,iBAAiB;CACjB,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CAC3B,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;AAC5B,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SealedEnvelope } from "../crypto/box.js";
|
|
2
|
-
declare const WALLET_METHODS: readonly ["amadeus_signTransaction", "amadeus_signMessage", "amadeus_getAccounts", "amadeus_generateApiKey", "amadeus_switchNetwork"];
|
|
2
|
+
declare const WALLET_METHODS: readonly ["amadeus_signTransaction", "amadeus_signMessage", "amadeus_getAccounts", "amadeus_generateApiKey", "amadeus_switchNetwork", "amadeus_switchAccount"];
|
|
3
3
|
type WalletMethod = (typeof WALLET_METHODS)[number];
|
|
4
4
|
interface WalletRequest {
|
|
5
5
|
/** Protocol version. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelope.d.ts","names":[],"sources":["../../src/transport/envelope.ts"],"mappings":";cAiBa;
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","names":[],"sources":["../../src/transport/envelope.ts"],"mappings":";cAiBa;KASD,uBAAuB;UAElB;;EAEhB;;EAEA;EACA,QAAQ;;EAER;EACA;;EAEA;;;;;;EAMA;;KAGW;EACP;EAAW;EAAY;EAAU;;EACjC;EAAW;EAAY;EAAW;IAAS;IAAc;;;;iBA4B9C,YAAY;EAC3B;EACA,QAAQ;EACR;EACA;EACA;EACA;EACA;IACG;iBAaY,YAAY,WAAW,YAAY,SAAS,gBAAgB;;;;;;;iBAU5D,YAAY,WAAW,YAAY,UAAU,iBAAiB;iBAe9D,aAAa,WAAW,YAAY,UAAU,iBAAiB;;;;;iBAQ/D,aACf,WAAW,YACX,UAAU,gBACV,sBACE;;;;;;;UAyBc;EAChB,IAAI;EACJ,IAAI;;iBAGW,sBAAsB,sBAAsB;;;;;;iBAgB5C,aAAa,SAAS,eAAe,OAAO,WAAW"}
|
|
@@ -18,7 +18,8 @@ const WALLET_METHODS = [
|
|
|
18
18
|
"amadeus_signMessage",
|
|
19
19
|
"amadeus_getAccounts",
|
|
20
20
|
"amadeus_generateApiKey",
|
|
21
|
-
"amadeus_switchNetwork"
|
|
21
|
+
"amadeus_switchNetwork",
|
|
22
|
+
"amadeus_switchAccount"
|
|
22
23
|
];
|
|
23
24
|
const walletRequestSchema = z.object({
|
|
24
25
|
v: z.number().int(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelope.js","names":[],"sources":["../../src/transport/envelope.ts"],"sourcesContent":["/**\n * The encrypted request/response envelope that flows over ANY transport (deep\n * link, QR, or the cross-device bridge). Post-connect, both sides hold the x25519\n * shared key, so every request and response is sealed — even same-device deep\n * links carry ciphertext, so a hijacked scheme yields an unusable blob.\n *\n * Methods mirror the wallet extension's provider vocabulary so a dApp integrates\n * once against the same names on every transport.\n */\n\nimport { z } from 'zod'\n\nimport { PROTOCOL_VERSION } from '../constants'\nimport { bytesToUtf8, utf8ToBytes } from '../bytes'\nimport { open, seal, type SealedEnvelope } from '../crypto/box'\nimport { WalletSdkError } from '../errors'\n\nexport const WALLET_METHODS = [\n\t'amadeus_signTransaction',\n\t'amadeus_signMessage',\n\t'amadeus_getAccounts',\n\t'amadeus_generateApiKey',\n\t'amadeus_switchNetwork'\n] as const\n\nexport type WalletMethod = (typeof WALLET_METHODS)[number]\n\nexport interface WalletRequest {\n\t/** Protocol version. */\n\tv: number\n\t/** Unique, one-time request id (replay key). */\n\tid: string\n\tmethod: WalletMethod\n\t/** The dApp origin, echoed for display in the approval UI. */\n\torigin: string\n\tparams: unknown\n\t/** Unix-seconds expiry. */\n\texp: number\n\t/**\n\t * Optional Base58 address the dApp wants to act with. The wallet resolves the\n\t * matching account's seed to sign; absent → the session's bound account. Lets\n\t * a multi-account dApp choose which account signs without reconnecting.\n\t */\n\taccount?: string\n}\n\nexport type WalletResponse =\n\t| { v: number; id: string; ok: true; result: unknown }\n\t| { v: number; id: string; ok: false; error: { code: string; message: string } }\n\nconst walletRequestSchema = z.object({\n\tv: z.number().int(),\n\tid: z.string().min(1).max(128),\n\tmethod: z.enum(WALLET_METHODS),\n\torigin: z.string().min(1),\n\tparams: z.unknown(),\n\texp: z.number().int(),\n\taccount: z.string().min(1).max(128).optional()\n})\n\nconst walletResponseSchema = z.union([\n\tz.object({\n\t\tv: z.number().int(),\n\t\tid: z.string().min(1).max(128),\n\t\tok: z.literal(true),\n\t\tresult: z.unknown()\n\t}),\n\tz.object({\n\t\tv: z.number().int(),\n\t\tid: z.string().min(1).max(128),\n\t\tok: z.literal(false),\n\t\terror: z.object({ code: z.string(), message: z.string() })\n\t})\n])\n\n/** Build an unsealed request with the current protocol version and a TTL. */\nexport function makeRequest(params: {\n\tid: string\n\tmethod: WalletMethod\n\torigin: string\n\tparams: unknown\n\taccount?: string\n\tttlSeconds?: number\n\tnow?: number\n}): WalletRequest {\n\tconst nowSec = Math.floor((params.now ?? Date.now()) / 1000)\n\treturn {\n\t\tv: PROTOCOL_VERSION,\n\t\tid: params.id,\n\t\tmethod: params.method,\n\t\torigin: params.origin,\n\t\tparams: params.params,\n\t\texp: nowSec + (params.ttlSeconds ?? 120),\n\t\t...(params.account ? { account: params.account } : {})\n\t}\n}\n\nexport function sealRequest(sharedKey: Uint8Array, request: WalletRequest): SealedEnvelope {\n\treturn seal(sharedKey, utf8ToBytes(JSON.stringify(request)))\n}\n\n/**\n * Decrypt + structurally validate an inbound request. Throws `DECRYPT_FAILED` if\n * the envelope is not authentic, `INVALID_ARGUMENT` if the plaintext is not a\n * well-formed request. Does NOT check expiry/replay — call `guardRequest` for\n * that policy step (kept separate so the crypto and the policy are distinct).\n */\nexport function openRequest(sharedKey: Uint8Array, envelope: SealedEnvelope): WalletRequest {\n\tconst bytes = open(sharedKey, envelope)\n\tlet parsed: unknown\n\ttry {\n\t\tparsed = JSON.parse(bytesToUtf8(bytes))\n\t} catch {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'request is not valid JSON')\n\t}\n\tconst result = walletRequestSchema.safeParse(parsed)\n\tif (!result.success) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'request failed schema validation')\n\t}\n\treturn result.data as WalletRequest\n}\n\nexport function sealResponse(sharedKey: Uint8Array, response: WalletResponse): SealedEnvelope {\n\treturn seal(sharedKey, utf8ToBytes(JSON.stringify(response)))\n}\n\n/**\n * Decrypt + validate an inbound response, optionally asserting it answers\n * `expectedId` (defends against a swapped/mismatched reply).\n */\nexport function openResponse(\n\tsharedKey: Uint8Array,\n\tenvelope: SealedEnvelope,\n\texpectedId?: string\n): WalletResponse {\n\tconst bytes = open(sharedKey, envelope)\n\tlet parsed: unknown\n\ttry {\n\t\tparsed = JSON.parse(bytesToUtf8(bytes))\n\t} catch {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'response is not valid JSON')\n\t}\n\tconst result = walletResponseSchema.safeParse(parsed)\n\tif (!result.success) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'response failed schema validation')\n\t}\n\tconst response = result.data as WalletResponse\n\tif (expectedId !== undefined && response.id !== expectedId) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'response id does not match the request')\n\t}\n\treturn response\n}\n\n/**\n * A one-time-id store for replay defense. The in-memory default is fine for a\n * single process; the mobile wallet should supply a PERSISTED implementation\n * (e.g. expo-secure-store) so a crash/relaunch inside the TTL window can't let a\n * captured approval replay. `has`+`add` must be atomic in the persisted impl.\n */\nexport interface SeenStore {\n\thas(id: string): boolean\n\tadd(id: string): void\n}\n\nexport function createMemorySeenStore(maxEntries = 10_000): SeenStore {\n\tconst ids = new Set<string>()\n\treturn {\n\t\thas: (id) => ids.has(id),\n\t\tadd: (id) => {\n\t\t\tif (ids.size >= maxEntries) ids.delete(ids.values().next().value as string)\n\t\t\tids.add(id)\n\t\t}\n\t}\n}\n\n/**\n * Policy gate: enforce expiry + one-time id BEFORE acting on a request (i.e.\n * before building/signing anything). Atomic check-and-add against `store`.\n * Throws `EXPIRED` or `INVALID_ARGUMENT` (duplicate).\n */\nexport function guardRequest(request: WalletRequest, store: SeenStore, now?: number): void {\n\tconst nowSec = Math.floor((now ?? Date.now()) / 1000)\n\tif (request.exp <= nowSec) {\n\t\tthrow new WalletSdkError('EXPIRED', 'request has expired')\n\t}\n\tif (store.has(request.id)) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'duplicate request id (replay)')\n\t}\n\tstore.add(request.id)\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,MAAa,iBAAiB;CAC7B;CACA;CACA;CACA;CACA;AACD;AA2BA,MAAM,sBAAsB,EAAE,OAAO;CACpC,GAAG,EAAE,OAAO,CAAC,CAAC,IAAI;CAClB,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG;CAC7B,QAAQ,EAAE,KAAK,cAAc;CAC7B,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACxB,QAAQ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E;AACrB"}
|
|
1
|
+
{"version":3,"file":"envelope.js","names":[],"sources":["../../src/transport/envelope.ts"],"sourcesContent":["/**\n * The encrypted request/response envelope that flows over ANY transport (deep\n * link, QR, or the cross-device bridge). Post-connect, both sides hold the x25519\n * shared key, so every request and response is sealed — even same-device deep\n * links carry ciphertext, so a hijacked scheme yields an unusable blob.\n *\n * Methods mirror the wallet extension's provider vocabulary so a dApp integrates\n * once against the same names on every transport.\n */\n\nimport { z } from 'zod'\n\nimport { PROTOCOL_VERSION } from '../constants'\nimport { bytesToUtf8, utf8ToBytes } from '../bytes'\nimport { open, seal, type SealedEnvelope } from '../crypto/box'\nimport { WalletSdkError } from '../errors'\n\nexport const WALLET_METHODS = [\n\t'amadeus_signTransaction',\n\t'amadeus_signMessage',\n\t'amadeus_getAccounts',\n\t'amadeus_generateApiKey',\n\t'amadeus_switchNetwork',\n\t'amadeus_switchAccount'\n] as const\n\nexport type WalletMethod = (typeof WALLET_METHODS)[number]\n\nexport interface WalletRequest {\n\t/** Protocol version. */\n\tv: number\n\t/** Unique, one-time request id (replay key). */\n\tid: string\n\tmethod: WalletMethod\n\t/** The dApp origin, echoed for display in the approval UI. */\n\torigin: string\n\tparams: unknown\n\t/** Unix-seconds expiry. */\n\texp: number\n\t/**\n\t * Optional Base58 address the dApp wants to act with. The wallet resolves the\n\t * matching account's seed to sign; absent → the session's bound account. Lets\n\t * a multi-account dApp choose which account signs without reconnecting.\n\t */\n\taccount?: string\n}\n\nexport type WalletResponse =\n\t| { v: number; id: string; ok: true; result: unknown }\n\t| { v: number; id: string; ok: false; error: { code: string; message: string } }\n\nconst walletRequestSchema = z.object({\n\tv: z.number().int(),\n\tid: z.string().min(1).max(128),\n\tmethod: z.enum(WALLET_METHODS),\n\torigin: z.string().min(1),\n\tparams: z.unknown(),\n\texp: z.number().int(),\n\taccount: z.string().min(1).max(128).optional()\n})\n\nconst walletResponseSchema = z.union([\n\tz.object({\n\t\tv: z.number().int(),\n\t\tid: z.string().min(1).max(128),\n\t\tok: z.literal(true),\n\t\tresult: z.unknown()\n\t}),\n\tz.object({\n\t\tv: z.number().int(),\n\t\tid: z.string().min(1).max(128),\n\t\tok: z.literal(false),\n\t\terror: z.object({ code: z.string(), message: z.string() })\n\t})\n])\n\n/** Build an unsealed request with the current protocol version and a TTL. */\nexport function makeRequest(params: {\n\tid: string\n\tmethod: WalletMethod\n\torigin: string\n\tparams: unknown\n\taccount?: string\n\tttlSeconds?: number\n\tnow?: number\n}): WalletRequest {\n\tconst nowSec = Math.floor((params.now ?? Date.now()) / 1000)\n\treturn {\n\t\tv: PROTOCOL_VERSION,\n\t\tid: params.id,\n\t\tmethod: params.method,\n\t\torigin: params.origin,\n\t\tparams: params.params,\n\t\texp: nowSec + (params.ttlSeconds ?? 120),\n\t\t...(params.account ? { account: params.account } : {})\n\t}\n}\n\nexport function sealRequest(sharedKey: Uint8Array, request: WalletRequest): SealedEnvelope {\n\treturn seal(sharedKey, utf8ToBytes(JSON.stringify(request)))\n}\n\n/**\n * Decrypt + structurally validate an inbound request. Throws `DECRYPT_FAILED` if\n * the envelope is not authentic, `INVALID_ARGUMENT` if the plaintext is not a\n * well-formed request. Does NOT check expiry/replay — call `guardRequest` for\n * that policy step (kept separate so the crypto and the policy are distinct).\n */\nexport function openRequest(sharedKey: Uint8Array, envelope: SealedEnvelope): WalletRequest {\n\tconst bytes = open(sharedKey, envelope)\n\tlet parsed: unknown\n\ttry {\n\t\tparsed = JSON.parse(bytesToUtf8(bytes))\n\t} catch {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'request is not valid JSON')\n\t}\n\tconst result = walletRequestSchema.safeParse(parsed)\n\tif (!result.success) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'request failed schema validation')\n\t}\n\treturn result.data as WalletRequest\n}\n\nexport function sealResponse(sharedKey: Uint8Array, response: WalletResponse): SealedEnvelope {\n\treturn seal(sharedKey, utf8ToBytes(JSON.stringify(response)))\n}\n\n/**\n * Decrypt + validate an inbound response, optionally asserting it answers\n * `expectedId` (defends against a swapped/mismatched reply).\n */\nexport function openResponse(\n\tsharedKey: Uint8Array,\n\tenvelope: SealedEnvelope,\n\texpectedId?: string\n): WalletResponse {\n\tconst bytes = open(sharedKey, envelope)\n\tlet parsed: unknown\n\ttry {\n\t\tparsed = JSON.parse(bytesToUtf8(bytes))\n\t} catch {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'response is not valid JSON')\n\t}\n\tconst result = walletResponseSchema.safeParse(parsed)\n\tif (!result.success) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'response failed schema validation')\n\t}\n\tconst response = result.data as WalletResponse\n\tif (expectedId !== undefined && response.id !== expectedId) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'response id does not match the request')\n\t}\n\treturn response\n}\n\n/**\n * A one-time-id store for replay defense. The in-memory default is fine for a\n * single process; the mobile wallet should supply a PERSISTED implementation\n * (e.g. expo-secure-store) so a crash/relaunch inside the TTL window can't let a\n * captured approval replay. `has`+`add` must be atomic in the persisted impl.\n */\nexport interface SeenStore {\n\thas(id: string): boolean\n\tadd(id: string): void\n}\n\nexport function createMemorySeenStore(maxEntries = 10_000): SeenStore {\n\tconst ids = new Set<string>()\n\treturn {\n\t\thas: (id) => ids.has(id),\n\t\tadd: (id) => {\n\t\t\tif (ids.size >= maxEntries) ids.delete(ids.values().next().value as string)\n\t\t\tids.add(id)\n\t\t}\n\t}\n}\n\n/**\n * Policy gate: enforce expiry + one-time id BEFORE acting on a request (i.e.\n * before building/signing anything). Atomic check-and-add against `store`.\n * Throws `EXPIRED` or `INVALID_ARGUMENT` (duplicate).\n */\nexport function guardRequest(request: WalletRequest, store: SeenStore, now?: number): void {\n\tconst nowSec = Math.floor((now ?? Date.now()) / 1000)\n\tif (request.exp <= nowSec) {\n\t\tthrow new WalletSdkError('EXPIRED', 'request has expired')\n\t}\n\tif (store.has(request.id)) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'dupl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I,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,KAAe;GAC1E,IAAI,IAAI,EAAE;EACX;CACD;AACD;;;;;;AAOA,SAAgB,aAAa,SAAwB,OAAkB,KAAoB;CAC1F,MAAM,SAAS,KAAK,OAAO,OAAO,KAAK,IAAI,KAAK,GAAI;CACpD,IAAI,QAAQ,OAAO,QAClB,MAAM,IAAI,eAAe,WAAW,qBAAqB;CAE1D,IAAI,MAAM,IAAI,QAAQ,EAAE,GACvB,MAAM,IAAI,eAAe,oBAAoB,+BAA+B;CAE7E,MAAM,IAAI,QAAQ,EAAE;AACrB"}
|
package/dist/types.d.ts
CHANGED
|
@@ -62,6 +62,14 @@ interface AmadeusProvider {
|
|
|
62
62
|
getNetwork(): Promise<string>;
|
|
63
63
|
requestAccounts(): Promise<string[]>;
|
|
64
64
|
requestSwitchNetwork(network: string): Promise<string>;
|
|
65
|
+
/**
|
|
66
|
+
* Ask the wallet to make another of its accounts active. `target` is an optional
|
|
67
|
+
* Base58 address hint; the wallet always confirms with the user (and presents its
|
|
68
|
+
* own account chooser) before switching, so a dApp can never switch silently.
|
|
69
|
+
* Resolves to the new active account's Base58 address. Optional: wallets that
|
|
70
|
+
* predate it lack the method.
|
|
71
|
+
*/
|
|
72
|
+
requestSwitchAccount?(target?: string): Promise<string>;
|
|
65
73
|
signTransaction(params: SignTransactionRequest): Promise<SignTransactionResponse>;
|
|
66
74
|
generateApiKey(params: GenerateApiKeyRequest): Promise<GenerateApiKeyResponse>;
|
|
67
75
|
on<E extends AmadeusProviderEvent>(event: E, callback: (data: AmadeusEventPayloadMap[E]) => void): void;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";KASY,yBAAyB;KAEzB,+BAA+B;UAE1B;EAChB;EACA;EAEA;EACA;;UAGgB;EAChB;;EAEA;;UAGgB;EAChB;;EAEA;;UAGgB;EAChB;;;UAIgB;EAChB;IAAmB;IAAoB;IAA4B;;EACnE;IAAW;IAAoB;IAAiB;;EAChD;IAAc;IAAiB;;EAC/B;IAAQ;IAAiB;;EACzB;IAAU;IAAoB;IAAiB;;EAC/C;IAAkB;IAAiB;IAAyB;;;;;;;UAO5C;WACP;EACT,eAAe;EACf,cAAc;EACd,cAAc;EACd,mBAAmB;EACnB,qBAAqB,kBAAkB;
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";KASY,yBAAyB;KAEzB,+BAA+B;UAE1B;EAChB;EACA;EAEA;EACA;;UAGgB;EAChB;;EAEA;;UAGgB;EAChB;;EAEA;;UAGgB;EAChB;;;UAIgB;EAChB;IAAmB;IAAoB;IAA4B;;EACnE;IAAW;IAAoB;IAAiB;;EAChD;IAAc;IAAiB;;EAC/B;IAAQ;IAAiB;;EACzB;IAAU;IAAoB;IAAiB;;EAC/C;IAAkB;IAAiB;IAAyB;;;;;;;UAO5C;WACP;EACT,eAAe;EACf,cAAc;EACd,cAAc;EACd,mBAAmB;EACnB,qBAAqB,kBAAkB;;;;;;;;EAQvC,sBAAsB,kBAAkB;EACxC,gBAAgB,QAAQ,yBAAyB,QAAQ;EACzD,eAAe,QAAQ,wBAAwB,QAAQ;EACvD,GAAG,UAAU,sBACZ,OAAO,GACP,WAAW,MAAM,uBAAuB;EAEzC,IAAI,UAAU,sBACb,OAAO,GACP,WAAW,MAAM,uBAAuB;;QAIlC;MACH,SAAS;;;iBAIE,sBAAsB;;iBAMtB"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\n * The typed public contract every Amadeus dApp already depends on — the injected\n * `window.amadeus` provider — plus the request/response shapes and event names.\n * These mirror the wallet extension exactly; changing a name or shape breaks live\n * dApps, so treat this file as the compatibility surface.\n */\n\nimport { NETWORKS, PROVIDER_EVENTS } from './constants'\n\nexport type AmadeusNetwork = (typeof NETWORKS)[number]\n\nexport type AmadeusProviderEvent = (typeof PROVIDER_EVENTS)[number]\n\nexport interface SignTransactionRequest {\n\tcontract: string\n\tmethod: string\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\targs: any[]\n\tdescription?: string\n}\n\nexport interface SignTransactionResponse {\n\ttxHash: string\n\t/** Packed transaction bytes as a plain number[] (fed into `new Uint8Array(...)`). */\n\ttxPacked: number[]\n}\n\nexport interface GenerateApiKeyRequest {\n\taud: string\n\t/** Lifetime in seconds. */\n\texp_in: number\n}\n\nexport interface GenerateApiKeyResponse {\n\tapiKey: string\n}\n\n/** Event payloads emitted through the provider's `.on(name, cb)` channel. */\nexport interface AmadeusEventPayloadMap {\n\taccountsChanged: { accounts: string[]; previousAccounts: string[]; timestamp: number }\n\tconnect: { accounts: string[]; network: string; timestamp: number }\n\tdisconnect: { reason?: string; timestamp: number }\n\tlock: { reason?: string; timestamp: number }\n\tunlock: { accounts: string[]; network: string; timestamp: number }\n\tnetworkChanged: { network: string; previousNetwork: string; timestamp: number }\n}\n\n/**\n * The injected provider interface. This is the object a dApp reads off\n * `window.amadeus`. Do not rename methods — dApps call them directly.\n */\nexport interface AmadeusProvider {\n\treadonly isAmadeus: boolean\n\tisConnected(): Promise<boolean>\n\tgetAccount(): Promise<string | null>\n\tgetNetwork(): Promise<string>\n\trequestAccounts(): Promise<string[]>\n\trequestSwitchNetwork(network: string): Promise<string>\n\tsignTransaction(params: SignTransactionRequest): Promise<SignTransactionResponse>\n\tgenerateApiKey(params: GenerateApiKeyRequest): Promise<GenerateApiKeyResponse>\n\ton<E extends AmadeusProviderEvent>(\n\t\tevent: E,\n\t\tcallback: (data: AmadeusEventPayloadMap[E]) => void\n\t): void\n\toff<E extends AmadeusProviderEvent>(\n\t\tevent: E,\n\t\tcallback: (data: AmadeusEventPayloadMap[E]) => void\n\t): void\n}\n\ndeclare global {\n\tvar amadeus: AmadeusProvider | undefined\n}\n\n/** Return the injected provider if present and genuine, else null. Browser-only. */\nexport function getAmadeusProvider(): AmadeusProvider | null {\n\tconst candidate = (globalThis as { amadeus?: AmadeusProvider }).amadeus\n\treturn candidate && candidate.isAmadeus === true ? candidate : null\n}\n\n/** Whether a genuine Amadeus provider is currently injected. */\nexport function isProviderAvailable(): boolean {\n\treturn getAmadeusProvider() !== null\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\n * The typed public contract every Amadeus dApp already depends on — the injected\n * `window.amadeus` provider — plus the request/response shapes and event names.\n * These mirror the wallet extension exactly; changing a name or shape breaks live\n * dApps, so treat this file as the compatibility surface.\n */\n\nimport { NETWORKS, PROVIDER_EVENTS } from './constants'\n\nexport type AmadeusNetwork = (typeof NETWORKS)[number]\n\nexport type AmadeusProviderEvent = (typeof PROVIDER_EVENTS)[number]\n\nexport interface SignTransactionRequest {\n\tcontract: string\n\tmethod: string\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\targs: any[]\n\tdescription?: string\n}\n\nexport interface SignTransactionResponse {\n\ttxHash: string\n\t/** Packed transaction bytes as a plain number[] (fed into `new Uint8Array(...)`). */\n\ttxPacked: number[]\n}\n\nexport interface GenerateApiKeyRequest {\n\taud: string\n\t/** Lifetime in seconds. */\n\texp_in: number\n}\n\nexport interface GenerateApiKeyResponse {\n\tapiKey: string\n}\n\n/** Event payloads emitted through the provider's `.on(name, cb)` channel. */\nexport interface AmadeusEventPayloadMap {\n\taccountsChanged: { accounts: string[]; previousAccounts: string[]; timestamp: number }\n\tconnect: { accounts: string[]; network: string; timestamp: number }\n\tdisconnect: { reason?: string; timestamp: number }\n\tlock: { reason?: string; timestamp: number }\n\tunlock: { accounts: string[]; network: string; timestamp: number }\n\tnetworkChanged: { network: string; previousNetwork: string; timestamp: number }\n}\n\n/**\n * The injected provider interface. This is the object a dApp reads off\n * `window.amadeus`. Do not rename methods — dApps call them directly.\n */\nexport interface AmadeusProvider {\n\treadonly isAmadeus: boolean\n\tisConnected(): Promise<boolean>\n\tgetAccount(): Promise<string | null>\n\tgetNetwork(): Promise<string>\n\trequestAccounts(): Promise<string[]>\n\trequestSwitchNetwork(network: string): Promise<string>\n\t/**\n\t * Ask the wallet to make another of its accounts active. `target` is an optional\n\t * Base58 address hint; the wallet always confirms with the user (and presents its\n\t * own account chooser) before switching, so a dApp can never switch silently.\n\t * Resolves to the new active account's Base58 address. Optional: wallets that\n\t * predate it lack the method.\n\t */\n\trequestSwitchAccount?(target?: string): Promise<string>\n\tsignTransaction(params: SignTransactionRequest): Promise<SignTransactionResponse>\n\tgenerateApiKey(params: GenerateApiKeyRequest): Promise<GenerateApiKeyResponse>\n\ton<E extends AmadeusProviderEvent>(\n\t\tevent: E,\n\t\tcallback: (data: AmadeusEventPayloadMap[E]) => void\n\t): void\n\toff<E extends AmadeusProviderEvent>(\n\t\tevent: E,\n\t\tcallback: (data: AmadeusEventPayloadMap[E]) => void\n\t): void\n}\n\ndeclare global {\n\tvar amadeus: AmadeusProvider | undefined\n}\n\n/** Return the injected provider if present and genuine, else null. Browser-only. */\nexport function getAmadeusProvider(): AmadeusProvider | null {\n\tconst candidate = (globalThis as { amadeus?: AmadeusProvider }).amadeus\n\treturn candidate && candidate.isAmadeus === true ? candidate : null\n}\n\n/** Whether a genuine Amadeus provider is currently injected. */\nexport function isProviderAvailable(): boolean {\n\treturn getAmadeusProvider() !== null\n}\n"],"mappings":";;AAmFA,SAAgB,qBAA6C;CAC5D,MAAM,YAAa,WAA6C;CAChE,OAAO,aAAa,UAAU,cAAc,OAAO,YAAY;AAChE;;AAGA,SAAgB,sBAA+B;CAC9C,OAAO,mBAAmB,MAAM;AACjC"}
|
package/dist/wallet/handler.d.ts
CHANGED
|
@@ -14,8 +14,9 @@ interface WalletHandlerContext {
|
|
|
14
14
|
/**
|
|
15
15
|
* Service one approved request and return a response ready to seal. Never throws
|
|
16
16
|
* — failures come back as `{ ok: false, error }` so the transport can always
|
|
17
|
-
* reply. `amadeus_switchNetwork`
|
|
18
|
-
* wallet runtime state), signalled with a
|
|
17
|
+
* reply. `amadeus_switchNetwork` and `amadeus_switchAccount` are deliberately
|
|
18
|
+
* delegated to the app (they mutate wallet runtime state), signalled with a
|
|
19
|
+
* distinct error the caller can branch on.
|
|
19
20
|
*/
|
|
20
21
|
declare function handleRequest(request: WalletRequest, ctx: WalletHandlerContext): WalletResponse;
|
|
21
22
|
export { WalletHandlerContext, handleRequest };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","names":[],"sources":["../../src/wallet/handler.ts"],"mappings":";;UAyBiB;;EAEhB;;EAEA;;;;;EAKA,UAAU
|
|
1
|
+
{"version":3,"file":"handler.d.ts","names":[],"sources":["../../src/wallet/handler.ts"],"mappings":";;UAyBiB;;EAEhB;;EAEA;;;;;EAKA,UAAU;;;;;;;;;iBAoBK,cAAc,SAAS,eAAe,KAAK,uBAAuB"}
|
package/dist/wallet/handler.js
CHANGED
|
@@ -27,8 +27,9 @@ function fail(id, error) {
|
|
|
27
27
|
/**
|
|
28
28
|
* Service one approved request and return a response ready to seal. Never throws
|
|
29
29
|
* — failures come back as `{ ok: false, error }` so the transport can always
|
|
30
|
-
* reply. `amadeus_switchNetwork`
|
|
31
|
-
* wallet runtime state), signalled with a
|
|
30
|
+
* reply. `amadeus_switchNetwork` and `amadeus_switchAccount` are deliberately
|
|
31
|
+
* delegated to the app (they mutate wallet runtime state), signalled with a
|
|
32
|
+
* distinct error the caller can branch on.
|
|
32
33
|
*/
|
|
33
34
|
function handleRequest(request, ctx) {
|
|
34
35
|
try {
|
|
@@ -67,6 +68,7 @@ function handleRequest(request, ctx) {
|
|
|
67
68
|
return ok(request.id, signed);
|
|
68
69
|
}
|
|
69
70
|
case "amadeus_switchNetwork": throw new WalletSdkError("INVALID_ARGUMENT", "amadeus_switchNetwork must be handled by the wallet app (it changes runtime state)");
|
|
71
|
+
case "amadeus_switchAccount": throw new WalletSdkError("INVALID_ARGUMENT", "amadeus_switchAccount must be handled by the wallet app (it changes the active account)");
|
|
70
72
|
default: throw new WalletSdkError("INVALID_ARGUMENT", `unknown method`);
|
|
71
73
|
}
|
|
72
74
|
} catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","names":[],"sources":["../../src/wallet/handler.ts"],"sourcesContent":["/**\n * Wallet-side request dispatch. Once the mobile app has opened + guarded an\n * inbound request and the user has approved it, this turns the request into a\n * signed response by routing to the right primitive. Keeping it here means the\n * app's approval screen only has to call one function; the wallet and extension\n * share identical request semantics.\n *\n * IMPORTANT: call this only AFTER `guardRequest` (expiry + replay) has passed and\n * the user has approved. It signs with the bound account's seed.\n */\n\nimport type { NetworkType } from '@amadeus-protocol/sdk'\n\nimport { PROTOCOL_VERSION } from '../constants'\nimport { generateApiKey } from '../crypto/apikey'\nimport { signMessage } from '../crypto/message'\nimport { WalletSdkError } from '../errors'\nimport {\n\tgenerateApiKeyRequestSchema,\n\tsignMessageRequestSchema,\n\tsignTransactionRequestSchema\n} from '../schema'\nimport { signTransaction } from '../tx'\nimport type { WalletRequest, WalletResponse } from '../transport/envelope'\n\nexport interface WalletHandlerContext {\n\t/** Seed (private key) of the account bound to this session. */\n\tseed: string\n\t/** Address (Base58 public key) of the bound account. */\n\taddress: string\n\t/**\n\t * Active network. Transactions are signed with this network's DST so a tx\n\t * signed on one network can't be replayed on another. Defaults to mainnet.\n\t */\n\tnetwork?: NetworkType\n}\n\nfunction ok(id: string, result: unknown): WalletResponse {\n\treturn { v: PROTOCOL_VERSION, id, ok: true, result }\n}\n\nfunction fail(id: string, error: unknown): WalletResponse {\n\tconst code = error instanceof WalletSdkError ? error.code : 'INTERNAL'\n\tconst message = error instanceof Error ? error.message : 'unexpected error'\n\treturn { v: PROTOCOL_VERSION, id, ok: false, error: { code, message } }\n}\n\n/**\n * Service one approved request and return a response ready to seal. Never throws\n * — failures come back as `{ ok: false, error }` so the transport can always\n * reply. `amadeus_switchNetwork`
|
|
1
|
+
{"version":3,"file":"handler.js","names":[],"sources":["../../src/wallet/handler.ts"],"sourcesContent":["/**\n * Wallet-side request dispatch. Once the mobile app has opened + guarded an\n * inbound request and the user has approved it, this turns the request into a\n * signed response by routing to the right primitive. Keeping it here means the\n * app's approval screen only has to call one function; the wallet and extension\n * share identical request semantics.\n *\n * IMPORTANT: call this only AFTER `guardRequest` (expiry + replay) has passed and\n * the user has approved. It signs with the bound account's seed.\n */\n\nimport type { NetworkType } from '@amadeus-protocol/sdk'\n\nimport { PROTOCOL_VERSION } from '../constants'\nimport { generateApiKey } from '../crypto/apikey'\nimport { signMessage } from '../crypto/message'\nimport { WalletSdkError } from '../errors'\nimport {\n\tgenerateApiKeyRequestSchema,\n\tsignMessageRequestSchema,\n\tsignTransactionRequestSchema\n} from '../schema'\nimport { signTransaction } from '../tx'\nimport type { WalletRequest, WalletResponse } from '../transport/envelope'\n\nexport interface WalletHandlerContext {\n\t/** Seed (private key) of the account bound to this session. */\n\tseed: string\n\t/** Address (Base58 public key) of the bound account. */\n\taddress: string\n\t/**\n\t * Active network. Transactions are signed with this network's DST so a tx\n\t * signed on one network can't be replayed on another. Defaults to mainnet.\n\t */\n\tnetwork?: NetworkType\n}\n\nfunction ok(id: string, result: unknown): WalletResponse {\n\treturn { v: PROTOCOL_VERSION, id, ok: true, result }\n}\n\nfunction fail(id: string, error: unknown): WalletResponse {\n\tconst code = error instanceof WalletSdkError ? error.code : 'INTERNAL'\n\tconst message = error instanceof Error ? error.message : 'unexpected error'\n\treturn { v: PROTOCOL_VERSION, id, ok: false, error: { code, message } }\n}\n\n/**\n * Service one approved request and return a response ready to seal. Never throws\n * — failures come back as `{ ok: false, error }` so the transport can always\n * reply. `amadeus_switchNetwork` and `amadeus_switchAccount` are deliberately\n * delegated to the app (they mutate wallet runtime state), signalled with a\n * distinct error the caller can branch on.\n */\nexport function handleRequest(request: WalletRequest, ctx: WalletHandlerContext): WalletResponse {\n\ttry {\n\t\tswitch (request.method) {\n\t\t\tcase 'amadeus_signTransaction': {\n\t\t\t\tconst parsed = signTransactionRequestSchema.safeParse(request.params)\n\t\t\t\tif (!parsed.success) {\n\t\t\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'invalid signTransaction params')\n\t\t\t\t}\n\t\t\t\tconst signed = signTransaction({\n\t\t\t\t\tseed: ctx.seed,\n\t\t\t\t\tcontract: parsed.data.contract,\n\t\t\t\t\tmethod: parsed.data.method,\n\t\t\t\t\targs: parsed.data.args,\n\t\t\t\t\tdescription: parsed.data.description,\n\t\t\t\t\tnetwork: ctx.network\n\t\t\t\t})\n\t\t\t\treturn ok(request.id, signed)\n\t\t\t}\n\t\t\tcase 'amadeus_generateApiKey': {\n\t\t\t\tconst parsed = generateApiKeyRequestSchema.safeParse(request.params)\n\t\t\t\tif (!parsed.success) {\n\t\t\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'invalid generateApiKey params')\n\t\t\t\t}\n\t\t\t\tconst { apiKey } = generateApiKey({\n\t\t\t\t\tseed: ctx.seed,\n\t\t\t\t\taud: parsed.data.aud,\n\t\t\t\t\texpIn: parsed.data.exp_in\n\t\t\t\t})\n\t\t\t\treturn ok(request.id, { apiKey })\n\t\t\t}\n\t\t\tcase 'amadeus_getAccounts':\n\t\t\t\treturn ok(request.id, { accounts: [ctx.address] })\n\t\t\tcase 'amadeus_signMessage': {\n\t\t\t\tconst parsed = signMessageRequestSchema.safeParse(request.params)\n\t\t\t\tif (!parsed.success) {\n\t\t\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'invalid signMessage params')\n\t\t\t\t}\n\t\t\t\tconst signed = signMessage({ seed: ctx.seed, message: parsed.data.message })\n\t\t\t\treturn ok(request.id, signed)\n\t\t\t}\n\t\t\tcase 'amadeus_switchNetwork':\n\t\t\t\tthrow new WalletSdkError(\n\t\t\t\t\t'INVALID_ARGUMENT',\n\t\t\t\t\t'amadeus_switchNetwork must be handled by the wallet app (it changes runtime state)'\n\t\t\t\t)\n\t\t\tcase 'amadeus_switchAccount':\n\t\t\t\tthrow new WalletSdkError(\n\t\t\t\t\t'INVALID_ARGUMENT',\n\t\t\t\t\t'amadeus_switchAccount must be handled by the wallet app (it changes the active account)'\n\t\t\t\t)\n\t\t\tdefault:\n\t\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', `unknown method`)\n\t\t}\n\t} catch (error) {\n\t\treturn fail(request.id, error)\n\t}\n}\n"],"mappings":";;;;;;;AAqCA,SAAS,GAAG,IAAY,QAAiC;CACxD,OAAO;EAAE,GAAA;EAAqB;EAAI,IAAI;EAAM;CAAO;AACpD;AAEA,SAAS,KAAK,IAAY,OAAgC;CAGzD,OAAO;EAAE,GAAA;EAAqB;EAAI,IAAI;EAAO,OAAO;GAAE,MAFzC,iBAAiB,iBAAiB,MAAM,OAAO;GAEA,SAD5C,iBAAiB,QAAQ,MAAM,UAAU;EACW;CAAE;AACvE;;;;;;;;AASA,SAAgB,cAAc,SAAwB,KAA2C;CAChG,IAAI;EACH,QAAQ,QAAQ,QAAhB;GACC,KAAK,2BAA2B;IAC/B,MAAM,SAAS,6BAA6B,UAAU,QAAQ,MAAM;IACpE,IAAI,CAAC,OAAO,SACX,MAAM,IAAI,eAAe,oBAAoB,gCAAgC;IAE9E,MAAM,SAAS,gBAAgB;KAC9B,MAAM,IAAI;KACV,UAAU,OAAO,KAAK;KACtB,QAAQ,OAAO,KAAK;KACpB,MAAM,OAAO,KAAK;KAClB,aAAa,OAAO,KAAK;KACzB,SAAS,IAAI;IACd,CAAC;IACD,OAAO,GAAG,QAAQ,IAAI,MAAM;GAC7B;GACA,KAAK,0BAA0B;IAC9B,MAAM,SAAS,4BAA4B,UAAU,QAAQ,MAAM;IACnE,IAAI,CAAC,OAAO,SACX,MAAM,IAAI,eAAe,oBAAoB,+BAA+B;IAE7E,MAAM,EAAE,WAAW,eAAe;KACjC,MAAM,IAAI;KACV,KAAK,OAAO,KAAK;KACjB,OAAO,OAAO,KAAK;IACpB,CAAC;IACD,OAAO,GAAG,QAAQ,IAAI,EAAE,OAAO,CAAC;GACjC;GACA,KAAK,uBACJ,OAAO,GAAG,QAAQ,IAAI,EAAE,UAAU,CAAC,IAAI,OAAO,EAAE,CAAC;GAClD,KAAK,uBAAuB;IAC3B,MAAM,SAAS,yBAAyB,UAAU,QAAQ,MAAM;IAChE,IAAI,CAAC,OAAO,SACX,MAAM,IAAI,eAAe,oBAAoB,4BAA4B;IAE1E,MAAM,SAAS,YAAY;KAAE,MAAM,IAAI;KAAM,SAAS,OAAO,KAAK;IAAQ,CAAC;IAC3E,OAAO,GAAG,QAAQ,IAAI,MAAM;GAC7B;GACA,KAAK,yBACJ,MAAM,IAAI,eACT,oBACA,oFACD;GACD,KAAK,yBACJ,MAAM,IAAI,eACT,oBACA,yFACD;GACD,SACC,MAAM,IAAI,eAAe,oBAAoB,gBAAgB;EAC/D;CACD,SAAS,OAAO;EACf,OAAO,KAAK,QAAQ,IAAI,KAAK;CAC9B;AACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amadeus-protocol/wallet-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Shared dApp <-> wallet connection layer for Amadeus Protocol: BLS API-key tokens, transaction signing, message/connect signing, and the typed provider contract. One audited implementation for the wallet, the extension, and every dApp.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|