@miden-sdk/miden-wallet-adapter-base 0.16.0 → 0.16.3
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/AGENTS.md +77 -0
- package/dist/adapter.js.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/helpers.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/signer.js.map +1 -1
- package/dist/transaction.js.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +9 -3
- package/skills/wallet-adapter-integration/SKILL.md +335 -0
- package/__tests__/adapter.test.ts +0 -82
- package/__tests__/errors.test.ts +0 -100
- package/__tests__/helpers.test.ts +0 -39
- package/__tests__/signer.test.ts +0 -20
- package/__tests__/transaction.test.ts +0 -166
- package/adapter.ts +0 -146
- package/dist/__tests__/adapter.test.d.ts +0 -1
- package/dist/__tests__/adapter.test.js +0 -66
- package/dist/__tests__/adapter.test.js.map +0 -1
- package/dist/__tests__/errors.test.d.ts +0 -1
- package/dist/__tests__/errors.test.js +0 -70
- package/dist/__tests__/errors.test.js.map +0 -1
- package/dist/__tests__/helpers.test.d.ts +0 -1
- package/dist/__tests__/helpers.test.js +0 -35
- package/dist/__tests__/helpers.test.js.map +0 -1
- package/dist/__tests__/signer.test.d.ts +0 -1
- package/dist/__tests__/signer.test.js +0 -18
- package/dist/__tests__/signer.test.js.map +0 -1
- package/dist/__tests__/transaction.test.d.ts +0 -1
- package/dist/__tests__/transaction.test.js +0 -113
- package/dist/__tests__/transaction.test.js.map +0 -1
- package/dist/vitest.config.d.ts +0 -2
- package/dist/vitest.config.js +0 -8
- package/dist/vitest.config.js.map +0 -1
- package/docs/@miden-sdk/namespaces/EventEmitter/README.md +0 -24
- package/docs/@miden-sdk/namespaces/EventEmitter/interfaces/EventEmitterStatic.md +0 -17
- package/docs/@miden-sdk/namespaces/EventEmitter/interfaces/ListenerFn.md +0 -25
- package/docs/@miden-sdk/namespaces/EventEmitter/type-aliases/ArgumentMap.md +0 -15
- package/docs/@miden-sdk/namespaces/EventEmitter/type-aliases/EventArgs.md +0 -19
- package/docs/@miden-sdk/namespaces/EventEmitter/type-aliases/EventListener.md +0 -19
- package/docs/@miden-sdk/namespaces/EventEmitter/type-aliases/EventNames.md +0 -15
- package/docs/@miden-sdk/namespaces/EventEmitter/type-aliases/ValidEventTypes.md +0 -17
- package/docs/@miden-sdk/namespaces/EventEmitter/variables/EventEmitter.md +0 -9
- package/docs/README.md +0 -88
- package/docs/classes/BaseMessageSignerWalletAdapter.md +0 -755
- package/docs/classes/BaseSignerWalletAdapter.md +0 -579
- package/docs/classes/BaseWalletAdapter.md +0 -535
- package/docs/classes/ConsumeTransaction.md +0 -93
- package/docs/classes/CustomTransaction.md +0 -93
- package/docs/classes/EventEmitter.md +0 -305
- package/docs/classes/SendTransaction.md +0 -107
- package/docs/classes/Transaction.md +0 -151
- package/docs/classes/WalletAccountError.md +0 -223
- package/docs/classes/WalletAddressError.md +0 -223
- package/docs/classes/WalletConfigError.md +0 -223
- package/docs/classes/WalletConnectionError.md +0 -223
- package/docs/classes/WalletDecryptionError.md +0 -223
- package/docs/classes/WalletDecryptionNotAllowedError.md +0 -223
- package/docs/classes/WalletDisconnectedError.md +0 -223
- package/docs/classes/WalletDisconnectionError.md +0 -223
- package/docs/classes/WalletError.md +0 -244
- package/docs/classes/WalletKeypairError.md +0 -223
- package/docs/classes/WalletLoadError.md +0 -223
- package/docs/classes/WalletNotConnectedError.md +0 -223
- package/docs/classes/WalletNotReadyError.md +0 -223
- package/docs/classes/WalletNotSelectedError.md +0 -223
- package/docs/classes/WalletPrivateDataPermissionError.md +0 -223
- package/docs/classes/WalletRecordsError.md +0 -223
- package/docs/classes/WalletSendTransactionError.md +0 -223
- package/docs/classes/WalletSignMessageError.md +0 -223
- package/docs/classes/WalletSignTransactionError.md +0 -223
- package/docs/classes/WalletTimeoutError.md +0 -223
- package/docs/classes/WalletTransactionError.md +0 -223
- package/docs/classes/WalletWindowBlockedError.md +0 -223
- package/docs/classes/WalletWindowClosedError.md +0 -223
- package/docs/enumerations/AllowedPrivateData.md +0 -37
- package/docs/enumerations/PrivateDataPermission.md +0 -19
- package/docs/enumerations/TransactionType.md +0 -25
- package/docs/enumerations/WalletAdapterNetwork.md +0 -19
- package/docs/enumerations/WalletReadyState.md +0 -49
- package/docs/functions/b64ToU8.md +0 -19
- package/docs/functions/scopePollingDetectionStrategy.md +0 -19
- package/docs/functions/u8ToB64.md +0 -19
- package/docs/interfaces/Asset.md +0 -19
- package/docs/interfaces/IFailedTransactionOutput.md +0 -13
- package/docs/interfaces/MessageSignerWalletAdapterProps.md +0 -293
- package/docs/interfaces/MidenConsumeTransaction.md +0 -37
- package/docs/interfaces/MidenCustomTransaction.md +0 -37
- package/docs/interfaces/MidenSendTransaction.md +0 -43
- package/docs/interfaces/MidenTransaction.md +0 -19
- package/docs/interfaces/SignerWalletAdapterProps.md +0 -149
- package/docs/interfaces/TransactionOutput.md +0 -19
- package/docs/interfaces/WalletAdapterEvents.md +0 -69
- package/docs/interfaces/WalletAdapterProps.md +0 -106
- package/docs/interfaces/WalletTransactionSuccessOutput.md +0 -19
- package/docs/type-aliases/Adapter.md +0 -9
- package/docs/type-aliases/FungibleAssetDetails.md +0 -21
- package/docs/type-aliases/InputNoteDetails.md +0 -45
- package/docs/type-aliases/MessageSignerWalletAdapter.md +0 -15
- package/docs/type-aliases/NoteTypeString.md +0 -9
- package/docs/type-aliases/SignKind.md +0 -9
- package/docs/type-aliases/SignerWalletAdapter.md +0 -15
- package/docs/type-aliases/SupportedTransactionVersions.md +0 -9
- package/docs/type-aliases/TransactionOrVersionedTransaction.md +0 -15
- package/docs/type-aliases/TransactionPayload.md +0 -9
- package/docs/type-aliases/WalletAdapter.md +0 -15
- package/docs/type-aliases/WalletName.md +0 -21
- package/docs/type-aliases/WalletTransactionOutput.md +0 -9
- package/errors.ts +0 -97
- package/helpers.ts +0 -28
- package/index.ts +0 -6
- package/signer.ts +0 -84
- package/transaction.ts +0 -178
- package/tsconfig.json +0 -15
- package/types.ts +0 -93
- package/vitest.config.ts +0 -8
package/AGENTS.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# @miden-sdk/miden-wallet-adapter-base - Agent Guide
|
|
2
|
+
|
|
3
|
+
**Audience: AI coding agents** writing code against the Miden wallet adapter.
|
|
4
|
+
Humans are welcome to read it, but it is written to be loaded into an agent's
|
|
5
|
+
context and followed.
|
|
6
|
+
|
|
7
|
+
This file ships inside the published package. The copy at
|
|
8
|
+
`node_modules/@miden-sdk/miden-wallet-adapter-base/AGENTS.md` always matches
|
|
9
|
+
the version you have installed, so **prefer it over your training data**, which
|
|
10
|
+
is likely to describe an older API. Miden is pre-1.0 and the surface still
|
|
11
|
+
moves between minor versions.
|
|
12
|
+
|
|
13
|
+
## Load the skill
|
|
14
|
+
|
|
15
|
+
`node_modules/@miden-sdk/miden-wallet-adapter-base/skills/wallet-adapter-integration/SKILL.md`
|
|
16
|
+
is the full integration guide: provider wiring, the readiness lifecycle, the
|
|
17
|
+
request surface, transaction shapes, the error taxonomy, when to drive
|
|
18
|
+
`MidenClient` instead, and the failures that only appear in production. Read it
|
|
19
|
+
before writing connect or transaction code. It ships here rather than in the
|
|
20
|
+
React packages because every other adapter package depends on this one, so the
|
|
21
|
+
path resolves whichever of them you installed.
|
|
22
|
+
|
|
23
|
+
## What is in this package
|
|
24
|
+
|
|
25
|
+
This is the contract layer. It talks to no wallet and renders nothing.
|
|
26
|
+
|
|
27
|
+
- **`BaseWalletAdapter` / `BaseSignerWalletAdapter` /
|
|
28
|
+
`BaseMessageSignerWalletAdapter`** - abstract classes an adapter extends.
|
|
29
|
+
They are `EventEmitter`s over `connect`, `disconnect`, `error` and
|
|
30
|
+
`readyStateChange`. `connected` is derived from `address`.
|
|
31
|
+
- **`WalletReadyState`** - `Installed`, `NotDetected`, `Loadable`,
|
|
32
|
+
`Unsupported`. The providers only connect on the first and third.
|
|
33
|
+
- **Errors** - `WalletError` and 22 subclasses. Each carries the underlying
|
|
34
|
+
failure on `.error` and a stable `.name`.
|
|
35
|
+
- **Transactions** - `SendTransaction`, `ConsumeTransaction`,
|
|
36
|
+
`CustomTransaction`, plus the `Transaction` envelope and `TransactionType`.
|
|
37
|
+
- **Enums** - `WalletAdapterNetwork` (`Devnet`, `Testnet`, `Localnet`),
|
|
38
|
+
`PrivateDataPermission`, `AllowedPrivateData`.
|
|
39
|
+
- **Helpers** - `scopePollingDetectionStrategy` for injection detection,
|
|
40
|
+
`u8ToB64` and `b64ToU8` for the wire encoding.
|
|
41
|
+
|
|
42
|
+
## Rules that are easy to get wrong
|
|
43
|
+
|
|
44
|
+
**Amounts here are `number`, not `bigint`.** `SendTransaction` and
|
|
45
|
+
`ConsumeTransaction` take a plain number, unlike `@miden-sdk/miden-sdk`, where
|
|
46
|
+
amounts are always `BigInt`. Convert at the boundary and do not copy a bigint
|
|
47
|
+
in from SDK code.
|
|
48
|
+
|
|
49
|
+
**Only six of the error classes are ever thrown** by the packages in this
|
|
50
|
+
family: `WalletNotSelectedError`, `WalletNotReadyError`,
|
|
51
|
+
`WalletConnectionError`, `WalletNotConnectedError`, `WalletTransactionError`
|
|
52
|
+
and `WalletDisconnectionError`. The rest are vocabulary for other adapters.
|
|
53
|
+
Writing a handler that waits for `WalletTimeoutError` waits forever.
|
|
54
|
+
|
|
55
|
+
**`AllowedPrivateData` is a bitmask.** `None`, `Assets`, `Notes`, `Storage`,
|
|
56
|
+
`All`. Combine with `|`. It decides what the wallet will answer for assets,
|
|
57
|
+
notes and storage, so a connect with `None` makes every read come back empty
|
|
58
|
+
rather than failing loudly.
|
|
59
|
+
|
|
60
|
+
**`CustomTransaction` serializes eagerly.** Its constructor calls
|
|
61
|
+
`serialize()` on the `TransactionRequest` you pass, so hand it a live object
|
|
62
|
+
from `@miden-sdk/miden-sdk`, not bytes you already encoded.
|
|
63
|
+
|
|
64
|
+
**This package has no runtime dependency on the SDK.** It imports
|
|
65
|
+
`@miden-sdk/miden-sdk` for types only, and declares it as a peer dependency.
|
|
66
|
+
The concrete adapter in `@miden-sdk/miden-wallet-adapter-miden` is the one
|
|
67
|
+
that pulls the WASM entry point in.
|
|
68
|
+
|
|
69
|
+
## Going deeper
|
|
70
|
+
|
|
71
|
+
- The type declarations shipped in `dist/` are authoritative for signatures.
|
|
72
|
+
When this guide and the types disagree, the types are right and this file is
|
|
73
|
+
a bug.
|
|
74
|
+
- The client behind a wallet-signed transaction documents itself at
|
|
75
|
+
`node_modules/@miden-sdk/miden-sdk/AGENTS.md`.
|
|
76
|
+
- Breaking changes and migration notes: the `CHANGELOG.md` in
|
|
77
|
+
[`0xMiden/web-sdk`](https://github.com/0xMiden/web-sdk).
|
package/dist/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../adapter.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,eAAe,CAAC;AASzC,OAAO,EAAE,YAAY,EAAE,CAAC;AAqCxB;;;;;;;;GAQG;AACH,MAAM,CAAN,IAAY,gBAkBX;AAlBD,WAAY,gBAAgB;IAC1B;;;;OAIG;IACH,2CAAuB,CAAA;IACvB,+CAA2B,CAAA;IAC3B;;;OAGG;IACH,yCAAqB,CAAA;IACrB;;;OAGG;IACH,+CAA2B,CAAA;AAC7B,CAAC,EAlBW,gBAAgB,KAAhB,gBAAgB,QAkB3B;AAED,MAAM,OAAgB,iBACpB,SAAQ,YAAiC;IAYzC,IAAI,SAAS;QACX,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;CAQF;AAED,MAAM,UAAU,6BAA6B,CAAC,MAAqB;IACjE,0CAA0C;IAC1C,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,QAAQ,KAAK,WAAW;QAAE,OAAO;IAE7E,MAAM,SAAS,GAAmB,EAAE,CAAC;IAErC,SAAS,gBAAgB;QACvB,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC;QAC1B,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AClC,CAAC;QACD,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAClE,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAC7E,CAAC;IAED,0CAA0C;IAC1C,gBAAgB,EAAE,CAAC;AACrB,CAAC","sourcesContent":["import EventEmitter from \"eventemitter3\";\nimport type { WalletError } from \"./errors\";\nimport type {\n AllowedPrivateData,\n PrivateDataPermission,\n SupportedTransactionVersions,\n WalletAdapterNetwork,\n} from \"./types\";\n\nexport { EventEmitter };\n\nexport interface WalletAdapterEvents {\n connect(address: string, allowedPrivateData?: AllowedPrivateData): void;\n disconnect(): void;\n error(error: WalletError): void;\n readyStateChange(readyState: WalletReadyState): void;\n}\n\n// WalletName is a nominal type that wallet adapters should use, e.g. `'MyCryptoWallet' as WalletName<'MyCryptoWallet'>`\n// https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d\nexport type WalletName<T extends string = string> = T & {\n __brand__: \"WalletName\";\n};\n\nexport interface WalletAdapterProps<Name extends string = string> {\n name: WalletName<Name>;\n url: string;\n icon: string;\n readyState: WalletReadyState;\n address: string | null;\n publicKey: Uint8Array | null;\n connecting: boolean;\n connected: boolean;\n supportedTransactionVersions: SupportedTransactionVersions;\n\n connect(\n privateDataPermission: PrivateDataPermission,\n network: WalletAdapterNetwork,\n allowedPrivateData?: AllowedPrivateData\n ): Promise<void>;\n disconnect(): Promise<void>;\n}\n\nexport type WalletAdapter<Name extends string = string> =\n WalletAdapterProps<Name> & EventEmitter<WalletAdapterEvents>;\n\n/**\n * A wallet's readiness describes a series of states that the wallet can be in,\n * depending on what kind of wallet it is. An installable wallet (eg. a browser\n * extension like Phantom) might be `Installed` if we've found the Phantom API\n * in the global scope, or `NotDetected` otherwise. A loadable, zero-install\n * runtime (eg. Torus Wallet) might simply signal that it's `Loadable`. Use this\n * metadata to personalize the wallet list for each user (eg. to show their\n * installed wallets first).\n */\nexport enum WalletReadyState {\n /**\n * User-installable wallets can typically be detected by scanning for an API\n * that they've injected into the global context. If such an API is present,\n * we consider the wallet to have been installed.\n */\n Installed = \"Installed\",\n NotDetected = \"NotDetected\",\n /**\n * Loadable wallets are always available to you. Since you can load them at\n * any time, it's meaningless to say that they have been detected.\n */\n Loadable = \"Loadable\",\n /**\n * If a wallet is not supported on a given platform (eg. server-rendering, or\n * mobile) then it will stay in the `Unsupported` state.\n */\n Unsupported = \"Unsupported\",\n}\n\nexport abstract class BaseWalletAdapter<Name extends string = string>\n extends EventEmitter<WalletAdapterEvents>\n implements WalletAdapter<Name>\n{\n abstract name: WalletName<Name>;\n abstract url: string;\n abstract icon: string;\n abstract readyState: WalletReadyState;\n abstract address: string | null;\n abstract publicKey: Uint8Array | null;\n abstract connecting: boolean;\n abstract supportedTransactionVersions: SupportedTransactionVersions;\n\n get connected() {\n return !!this.address;\n }\n\n abstract connect(\n privateDataPermission: PrivateDataPermission,\n network: WalletAdapterNetwork,\n allowedPrivateData?: AllowedPrivateData\n ): Promise<void>;\n abstract disconnect(): Promise<void>;\n}\n\nexport function scopePollingDetectionStrategy(detect: () => boolean): void {\n // Early return when server-side rendering\n if (typeof window === \"undefined\" || typeof document === \"undefined\") return;\n\n const disposers: (() => void)[] = [];\n\n function detectAndDispose() {\n const detected = detect();\n if (detected) {\n for (const dispose of disposers) {\n dispose();\n }\n }\n }\n\n // Strategy #1: Try detecting every second.\n const interval =\n // TODO: #334 Replace with idle callback strategy.\n setInterval(detectAndDispose, 1000);\n disposers.push(() => clearInterval(interval));\n\n // Strategy #2: Detect as soon as the DOM becomes 'ready'/'interactive'.\n if (\n // Implies that `DOMContentLoaded` has not yet fired.\n document.readyState === \"loading\"\n ) {\n document.addEventListener(\"DOMContentLoaded\", detectAndDispose, {\n once: true,\n });\n disposers.push(() =>\n document.removeEventListener(\"DOMContentLoaded\", detectAndDispose)\n );\n }\n\n // Strategy #3: Detect after the `window` has fully loaded.\n if (\n // If the `complete` state has been reached, we're too late.\n document.readyState !== \"complete\"\n ) {\n window.addEventListener(\"load\", detectAndDispose, { once: true });\n disposers.push(() => window.removeEventListener(\"load\", detectAndDispose));\n }\n\n // Strategy #4: Detect synchronously, now.\n detectAndDispose();\n}\n"]}
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,KAAK,CAAM;IAEX,6EAA6E;IAC7E,YAAY,OAAgB,EAAE,KAAW;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAClD,IAAI,GAAG,qBAAqB,CAAC;CAC9B;AAED,MAAM,OAAO,eAAgB,SAAQ,WAAW;IAC9C,IAAI,GAAG,iBAAiB,CAAC;CAC1B;AAED,MAAM,OAAO,iBAAkB,SAAQ,WAAW;IAChD,IAAI,GAAG,mBAAmB,CAAC;CAC5B;AAED,MAAM,OAAO,qBAAsB,SAAQ,WAAW;IACpD,IAAI,GAAG,uBAAuB,CAAC;CAChC;AAED,MAAM,OAAO,sBAAuB,SAAQ,WAAW;IACrD,IAAI,GAAG,wBAAwB,CAAC;CACjC;AAED,MAAM,OAAO,uBAAwB,SAAQ,WAAW;IACtD,IAAI,GAAG,yBAAyB,CAAC;CAClC;AAED,MAAM,OAAO,wBAAyB,SAAQ,WAAW;IACvD,IAAI,GAAG,0BAA0B,CAAC;CACnC;AAED,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IACjD,IAAI,GAAG,oBAAoB,CAAC;CAC7B;AAED,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IACjD,IAAI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C7B;AAED,MAAM,OAAO,wBAAyB,SAAQ,WAAW;IACvD,IAAI,GAAG,0BAA0B,CAAC;CACnC;AAED,MAAM,OAAO,uBAAwB,SAAQ,WAAW;IACtD,IAAI,GAAG,yBAAyB,CAAC;CAClC;AAED,MAAM,OAAO,+BAAgC,SAAQ,WAAW;IAC9D,IAAI,GAAG,iCAAiC,CAAC;CAC1C;AAED,MAAM,OAAO,gCAAiC,SAAQ,WAAW;IAC/D,IAAI,GAAG,kCAAkC,CAAC;CAC3C;AAED,MAAM,OAAO,qBAAsB,SAAQ,WAAW;IACpD,IAAI,GAAG,uBAAuB,CAAC;CAChC;AAED,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IACjD,IAAI,GAAG,oBAAoB,CAAC;CAC7B;AAED,MAAM,OAAO,sBAAuB,SAAQ,WAAW;IACrD,IAAI,GAAG,wBAAwB,CAAC;CACjC","sourcesContent":["export class WalletError extends Error {\n error: any;\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n constructor(message?: string, error?: any) {\n super(message);\n this.error = error;\n }\n}\n\nexport class WalletNotReadyError extends WalletError {\n name = \"WalletNotReadyError\";\n}\n\nexport class WalletLoadError extends WalletError {\n name = \"WalletLoadError\";\n}\n\nexport class WalletConfigError extends WalletError {\n name = \"WalletConfigError\";\n}\n\nexport class WalletConnectionError extends WalletError {\n name = \"WalletConnectionError\";\n}\n\nexport class WalletNotSelectedError extends WalletError {\n name = \"WalletNotSelectedError\";\n}\n\nexport class WalletDisconnectedError extends WalletError {\n name = \"WalletDisconnectedError\";\n}\n\nexport class WalletDisconnectionError extends WalletError {\n name = \"WalletDisconnectionError\";\n}\n\nexport class WalletAccountError extends WalletError {\n name = \"WalletAccountError\";\n}\n\nexport class WalletAddressError extends WalletError {\n name = \"WalletAddressError\";\n}\n\nexport class WalletKeypairError extends WalletError {\n name = \"WalletKeypairError\";\n}\n\nexport class WalletNotConnectedError extends WalletError {\n name = \"WalletNotConnectedError\";\n}\n\nexport class WalletSendTransactionError extends WalletError {\n name = \"WalletSendTransactionError\";\n}\n\nexport class WalletSignMessageError extends WalletError {\n name = \"WalletSignMessageError\";\n}\n\nexport class WalletSignTransactionError extends WalletError {\n name = \"WalletSignTransactionError\";\n}\n\nexport class WalletTimeoutError extends WalletError {\n name = \"WalletTimeoutError\";\n}\n\nexport class WalletWindowBlockedError extends WalletError {\n name = \"WalletWindowBlockedError\";\n}\n\nexport class WalletWindowClosedError extends WalletError {\n name = \"WalletWindowClosedError\";\n}\n\nexport class WalletDecryptionNotAllowedError extends WalletError {\n name = \"WalletDecryptionNotAllowedError\";\n}\n\nexport class WalletPrivateDataPermissionError extends WalletError {\n name = \"WalletPrivateDataPermissionError\";\n}\n\nexport class WalletDecryptionError extends WalletError {\n name = \"WalletDecryptionError\";\n}\n\nexport class WalletRecordsError extends WalletError {\n name = \"WalletRecordsError\";\n}\n\nexport class WalletTransactionError extends WalletError {\n name = \"WalletTransactionError\";\n}\n"]}
|
package/dist/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../helpers.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,MAAM,UAAU,OAAO,CAAC,EAAc;IACpC,yCAAyC;IACzC,IAAI,OAAO,UAAU,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QAC1C,IAAI,CAAC,GAAG,EAAE,CAAC;QACX,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE;YAAE,CAAC,IAAI,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACpE,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IACD,wEAAwE;IACxE,MAAM,GAAG,GAAS,UAAkB,CAAC,MAAM,CAAC;IAC5C,IAAI,GAAG;QAAE,OAAO,GAAG,CAAC,IAAI,CAAC,EA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AU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IACD,wEAAwE;IACxE,MAAM,GAAG,GAAS,UAAkB,CAAC,MAAM,CAAC;IAC5C,IAAI,GAAG;QAAE,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;AACrE,CAAC;AAED,8BAA8B;AAC9B,MAAM,UAAU,OAAO,CAAC,GAAW;IACjC,yCAAyC;IACzC,IAAI,OAAO,UAAU,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QAC1C,MAAM,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjC,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE;YAAE,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAChE,OAAO,GAAG,CAAC;IACb,CAAC;IACD,wEAAwE;IACxE,MAAM,GAAG,GAAS,UAAkB,CAAC,MAAM,CAAC;IAC5C,IAAI,GAAG;QAAE,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;IACxD,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;AACrE,CAAC","sourcesContent":["// Encode a Uint8Array to base64\nexport function u8ToB64(u8: Uint8Array): string {\n // Prefer browser builtins (no polyfills)\n if (typeof globalThis.btoa === \"function\") {\n let s = \"\";\n for (let i = 0; i < u8.length; i++) s += String.fromCharCode(u8[i]);\n return globalThis.btoa(s);\n }\n // Node/Buffer fallback (won’t be bundled if never executed in browsers)\n const Buf: any = (globalThis as any).Buffer;\n if (Buf) return Buf.from(u8).toString(\"base64\");\n throw new Error(\"No base64 encoder available in this environment\");\n}\n\n// Decode base64 to Uint8Array\nexport function b64ToU8(b64: string): Uint8Array {\n // Prefer browser builtins (no polyfills)\n if (typeof globalThis.atob === \"function\") {\n const bin = globalThis.atob(b64);\n const out = new Uint8Array(bin.length);\n for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);\n return out;\n }\n // Node/Buffer fallback (won’t be bundled if never executed in browsers)\n const Buf: any = (globalThis as any).Buffer;\n if (Buf) return new Uint8Array(Buf.from(b64, \"base64\"));\n throw new Error(\"No base64 decoder available in this environment\");\n}\n"]}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC","sourcesContent":["export * from \"./adapter\";\nexport * from \"./errors\";\nexport * from \"./signer\";\nexport * from \"./types\";\nexport * from \"./transaction\";\nexport * from \"./helpers\";\n"]}
|
package/dist/signer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../signer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AA2B9C,MAAM,OAAgB,uBACpB,SAAQ,iBAAuB;CACQ;AA2BzC,MAAM,OAAgB,8BAGpB,SAAQ,uBAA6B;CAsBtC"}
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../signer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AA2B9C,MAAM,OAAgB,uBACpB,SAAQ,iBAAuB;CACQ;AA2BzC,MAAM,OAAgB,8BAGpB,SAAQ,uBAA6B;CAsBtC","sourcesContent":["import type { NoteFilterTypes } from \"@miden-sdk/miden-sdk\";\nimport type { WalletAdapter, WalletAdapterProps } from \"./adapter\";\nimport { BaseWalletAdapter } from \"./adapter\";\nimport {\n MidenConsumeTransaction,\n MidenSendTransaction,\n MidenTransaction,\n} from \"./transaction\";\nimport {\n Asset,\n CreateAccountParams,\n GuardianInfo,\n InputNoteDetails,\n SignKind,\n TransactionOutput,\n} from \"./types\";\n\nexport type Adapter =\n | WalletAdapter\n | SignerWalletAdapter\n | MessageSignerWalletAdapter;\n\nexport interface SignerWalletAdapterProps<\n Name extends string = string,\n> extends WalletAdapterProps<Name> {}\n\nexport type SignerWalletAdapter<Name extends string = string> =\n WalletAdapter<Name> & SignerWalletAdapterProps<Name>;\n\nexport abstract class BaseSignerWalletAdapter<Name extends string = string>\n extends BaseWalletAdapter<Name>\n implements SignerWalletAdapter<Name> {}\n\nexport interface MessageSignerWalletAdapterProps<\n Name extends string = string,\n> extends WalletAdapterProps<Name> {\n requestTransaction(transaction: MidenTransaction): Promise<string>;\n requestAssets(): Promise<Asset[]>;\n requestGuardianInfo(): Promise<GuardianInfo>;\n requestPrivateNotes(\n noteFilterType: NoteFilterTypes,\n noteIds?: string[]\n ): Promise<InputNoteDetails[]>;\n signBytes(data: Uint8Array, kind: SignKind): Promise<Uint8Array>;\n importPrivateNote(note: Uint8Array): Promise<string>;\n requestConsumableNotes(): Promise<InputNoteDetails[]>;\n waitForTransaction(\n txId: string,\n timeout?: number\n ): Promise<TransactionOutput>;\n requestSend(transaction: MidenSendTransaction): Promise<string>;\n requestConsume(transaction: MidenConsumeTransaction): Promise<string>;\n createAccount(params?: CreateAccountParams): Promise<string>;\n}\n\nexport type MessageSignerWalletAdapter<Name extends string = string> =\n WalletAdapter<Name> & MessageSignerWalletAdapterProps<Name>;\n\nexport abstract class BaseMessageSignerWalletAdapter<\n Name extends string = string,\n>\n extends BaseSignerWalletAdapter<Name>\n implements MessageSignerWalletAdapter<Name>\n{\n abstract requestSend(transaction: MidenSendTransaction): Promise<string>;\n abstract requestConsume(\n transaction: MidenConsumeTransaction\n ): Promise<string>;\n abstract requestTransaction(transaction: MidenTransaction): Promise<string>;\n abstract requestAssets(): Promise<Asset[]>;\n abstract requestGuardianInfo(): Promise<GuardianInfo>;\n abstract requestPrivateNotes(\n noteFilterType: NoteFilterTypes,\n noteIds?: string[]\n ): Promise<InputNoteDetails[]>;\n abstract signBytes(data: Uint8Array, kind: SignKind): Promise<Uint8Array>;\n abstract importPrivateNote(note: Uint8Array): Promise<string>;\n abstract requestConsumableNotes(): Promise<InputNoteDetails[]>;\n abstract waitForTransaction(\n txId: string,\n timeout?: number\n ): Promise<TransactionOutput>;\n abstract createAccount(params?: CreateAccountParams): Promise<string>;\n}\n"]}
|
package/dist/transaction.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../transaction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAapC,MAAM,OAAO,eAAe;IAC1B,aAAa,CAAS;IACtB,gBAAgB,CAAS;IACzB,QAAQ,CAAS;IACjB,QAAQ,CAAiB;IACzB,MAAM,CAAS;IACf,YAAY,CAAU;IAEtB,YACE,MAAc,EACd,SAAiB,EACjB,QAAgB,EAChB,QAAwB,EACxB,MAAc,EACd,YAAqB;QAErB,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC;QAC5B,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;QAClC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAA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AEtB,MAAM,kBAAkB,GAAG,IAAI,kBAAkB,CAC/C,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,MAAM,EACN,SAAS,CACV,CAAC;QACF,OAAO,IAAI,WAAW,CAAC,eAAe,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;IACtE,CAAC;IAED,MAAM,CAAC,uBAAuB,CAC5B,OAAe,EACf,gBAAwB,EACxB,kBAAsC,EACtC,YAAuB,EACvB,SAAwB;QAExB,MAAM,gBAAgB,GAAG,IAAI,iBAAiB,CAC5C,OAAO,EACP,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,SAAS,CACV,CAAC;QACF,OAAO,IAAI,WAAW,CAAC,eAAe,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACnE,CAAC;CACF","sourcesContent":["import type { TransactionRequest } from \"@miden-sdk/miden-sdk\";\nimport { u8ToB64 } from \"./helpers\";\n\nexport type NoteTypeString = \"public\" | \"private\";\n\nexport interface MidenSendTransaction {\n senderAddress: string;\n recipientAddress: string;\n faucetId: string;\n noteType: NoteTypeString;\n amount: number;\n recallBlocks?: number;\n}\n\nexport class SendTransaction implements MidenSendTransaction {\n senderAddress: string;\n recipientAddress: string;\n faucetId: string;\n noteType: NoteTypeString;\n amount: number;\n recallBlocks?: number;\n\n constructor(\n sender: string,\n recipient: string,\n faucetId: string,\n noteType: NoteTypeString,\n amount: number,\n recallBlocks?: number\n ) {\n this.senderAddress = sender;\n this.recipientAddress = recipient;\n this.faucetId = faucetId;\n this.noteType = noteType;\n this.amount = amount;\n this.recallBlocks = recallBlocks;\n }\n}\n\nexport interface MidenConsumeTransaction {\n faucetId: string;\n noteId: string;\n noteType: NoteTypeString;\n amount: number;\n noteBytes?: string;\n}\n\nexport class ConsumeTransaction implements MidenConsumeTransaction {\n faucetId: string;\n noteId: string;\n noteType: NoteTypeString;\n amount: number;\n noteBytes?: string;\n\n constructor(\n faucetId: string,\n noteId: string,\n noteType: NoteTypeString,\n amount: number,\n noteBytes?: Uint8Array\n ) {\n this.faucetId = faucetId;\n this.noteId = noteId;\n this.noteType = noteType;\n this.amount = amount;\n this.noteBytes = noteBytes ? u8ToB64(noteBytes) : undefined;\n }\n}\n\nexport interface MidenCustomTransaction {\n address: string;\n recipientAddress: string;\n transactionRequest: string;\n inputNoteIds?: string[];\n importNotes?: string[];\n}\n\nexport class CustomTransaction implements MidenCustomTransaction {\n address: string;\n recipientAddress: string;\n transactionRequest: string;\n inputNoteIds?: string[];\n importNotes?: string[];\n\n constructor(\n address: string,\n recipientAddress: string,\n transactionRequest: TransactionRequest,\n inputNotesIds?: string[],\n inputNoteBytes?: Uint8Array[]\n ) {\n this.address = address;\n this.recipientAddress = recipientAddress;\n const requestBytes = transactionRequest.serialize();\n const base64 = u8ToB64(requestBytes);\n this.transactionRequest = base64;\n this.inputNoteIds = inputNotesIds;\n this.importNotes = inputNoteBytes?.map((note) => u8ToB64(note));\n }\n}\n\nexport enum TransactionType {\n Send = \"send\",\n Consume = \"consume\",\n Custom = \"custom\",\n}\nexport type TransactionPayload =\n | MidenSendTransaction\n | MidenConsumeTransaction\n | MidenCustomTransaction;\n\nexport interface MidenTransaction {\n type: TransactionType;\n payload: TransactionPayload;\n}\n\nexport class Transaction implements MidenTransaction {\n type: TransactionType;\n payload: TransactionPayload;\n\n constructor(type: TransactionType, payload: TransactionPayload) {\n this.type = type;\n this.payload = payload;\n }\n\n static createSendTransaction(\n sender: string,\n recipient: string,\n faucetId: string,\n noteType: NoteTypeString,\n amount: number,\n recallBlocks?: number\n ) {\n const sendTransaction = new SendTransaction(\n sender,\n recipient,\n faucetId,\n noteType,\n amount,\n recallBlocks\n );\n return new Transaction(TransactionType.Send, sendTransaction);\n }\n\n static createConsumeTransaction(\n faucetId: string,\n noteId: string,\n noteType: NoteTypeString,\n amount: number,\n noteBytes?: Uint8Array\n ) {\n const consumeTransaction = new ConsumeTransaction(\n faucetId,\n noteId,\n noteType,\n amount,\n noteBytes\n );\n return new Transaction(TransactionType.Consume, consumeTransaction);\n }\n\n static createCustomTransaction(\n address: string,\n recipientAddress: string,\n transactionRequest: TransactionRequest,\n inputNoteIds?: string[],\n noteBytes?: Uint8Array[]\n ) {\n const transactionBytes = new CustomTransaction(\n address,\n recipientAddress,\n transactionRequest,\n inputNoteIds,\n noteBytes\n );\n return new Transaction(TransactionType.Custom, transactionBytes);\n }\n}\n"]}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAN,IAAY,oBAIX;AAJD,WAAY,oBAAoB;IAC9B,yCAAiB,CAAA;IACjB,2CAAmB,CAAA;IACnB,6CAAqB,CAAA;AACvB,CAAC,EAJW,oBAAoB,KAApB,oBAAoB,QAI/B;AAQD,MAAM,CAAN,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAC/B,qDAA4B,CAAA;IAC5B,sCAAa,CAAA;AACf,CAAC,EAHW,qBAAqB,KAArB,qBAAqB,QAGhC;AAED,MAAM,CAAN,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC5B,2DAAQ,CAAA;IACR,+DAAe,CAAA;IACf,6DAAc,CAAA;IACd,iEAAgB,CAAA;IAChB,6DAAmB,CAAA;AACrB,CAAC,EANW,kBAAkB,KAAlB,kBAAkB,QAM7B"}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAN,IAAY,oBAIX;AAJD,WAAY,oBAAoB;IAC9B,yCAAiB,CAAA;IACjB,2CAAmB,CAAA;IACnB,6CAAqB,CAAA;AACvB,CAAC,EAJW,oBAAoB,KAApB,oBAAoB,QAI/B;AAQD,MAAM,CAAN,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAC/B,qDAA4B,CAAA;IAC5B,sCAAa,CAAA;AACf,CAAC,EAHW,qBAAqB,KAArB,qBAAqB,QAGhC;AAED,MAAM,CAAN,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC5B,2DAAQ,CAAA;IACR,+DAAe,CAAA;IACf,6DAAc,CAAA;IACd,iEAAgB,CAAA;IAChB,6DAAmB,CAAA;AACrB,CAAC,EANW,kBAAkB,KAAlB,kBAAkB,QAM7B","sourcesContent":["import type { InputNoteState, Note, NoteType } from \"@miden-sdk/miden-sdk\";\n\nexport enum WalletAdapterNetwork {\n Devnet = \"devnet\",\n Testnet = \"testnet\",\n Localnet = \"localnet\",\n}\n\nexport type SupportedTransactionVersions = ReadonlySet<any> | null;\n\nexport type TransactionOrVersionedTransaction<\n S extends SupportedTransactionVersions,\n> = S extends null ? any : any | any;\n\nexport enum PrivateDataPermission {\n UponRequest = \"UPON_REQUEST\", // The App must ask for permission to access private data every time\n Auto = \"AUTO\", // The App can access private data without confirmation\n}\n\nexport enum AllowedPrivateData {\n None = 0,\n Assets = 1 << 0, // 1\n Notes = 1 << 1, // 2\n Storage = 1 << 2, // 4\n All = (1 << 16) - 1, // 65535 (allows for new permissions without requiring a migration)\n}\n\nexport type SignKind = \"word\" | \"signingInputs\";\n\nexport interface Asset {\n faucetId: string;\n amount: string;\n}\n\nexport interface GuardianInfo {\n isGuardianAccount: boolean;\n guardianEndpoint: string | null;\n guardianProvider:\n | \"open-zeppelin\"\n | \"gateway\"\n | \"lambda-class\"\n | \"custom\"\n | null;\n guardianSyncStatus: \"in-sync\" | \"out-of-sync\" | null;\n}\n\nexport type InputNoteDetails = {\n noteId: string;\n senderAccountId: string | undefined;\n assets: FungibleAssetDetails[];\n noteType: NoteType | undefined;\n nullifier: string;\n state: InputNoteState;\n};\n\nexport type FungibleAssetDetails = {\n amount: string;\n faucetId: string;\n};\n\n// Developer-facing transaction output interface\n// Errors from the wallet are thrown as exceptions\nexport interface TransactionOutput {\n txHash: string;\n outputNotes: Note[];\n}\n\nexport interface IFailedTransactionOutput {\n errorMessage: string;\n}\n\n// Internal wallet response format - uses serialized note data (string[])\n// Converted to Note objects for the public API (TransactionOutput)\nexport interface WalletTransactionSuccessOutput {\n txHash: string;\n outputNotes: string[];\n}\n\nexport type WalletTransactionOutput =\n | WalletTransactionSuccessOutput\n | IFailedTransactionOutput;\n\nexport type CreateAccountType =\n | \"RegularAccountImmutableCode\"\n | \"RegularAccountUpdatableCode\";\n\nexport type CreateAccountStorageMode = \"private\" | \"public\";\n\nexport interface CreateAccountParams {\n accountType?: CreateAccountType;\n storageMode?: CreateAccountStorageMode;\n customComponents?: Uint8Array[];\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miden-sdk/miden-wallet-adapter-base",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.3",
|
|
4
4
|
"description": "Core infrastructure for connecting Miden-compatible wallets to your dApp.",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"AGENTS.md",
|
|
10
|
+
"skills"
|
|
11
|
+
],
|
|
7
12
|
"repository": {
|
|
8
13
|
"type": "git",
|
|
9
14
|
"url": "git+https://github.com/0xMiden/web-sdk.git",
|
|
@@ -17,17 +22,18 @@
|
|
|
17
22
|
"devDependencies": {
|
|
18
23
|
"jsdom": "^24.0.0",
|
|
19
24
|
"vitest": "^1.0.0",
|
|
20
|
-
"@miden-sdk/miden-sdk": "0.16.
|
|
25
|
+
"@miden-sdk/miden-sdk": "0.16.3"
|
|
21
26
|
},
|
|
22
27
|
"bugs": {
|
|
23
28
|
"url": "https://github.com/0xMiden/web-sdk/issues"
|
|
24
29
|
},
|
|
25
30
|
"peerDependencies": {
|
|
26
|
-
"@miden-sdk/miden-sdk": "^0.16.
|
|
31
|
+
"@miden-sdk/miden-sdk": "^0.16.3"
|
|
27
32
|
},
|
|
28
33
|
"homepage": "https://github.com/0xMiden/web-sdk",
|
|
29
34
|
"scripts": {
|
|
30
35
|
"build": "tsc",
|
|
36
|
+
"typecheck": "tsc --noEmit -p tsconfig.test.json",
|
|
31
37
|
"clean": "rimraf dist/ node_modules/",
|
|
32
38
|
"doc": "typedoc --disableSources --tsconfig ./tsconfig.json --plugin typedoc-plugin-markdown --entryPoints index.ts",
|
|
33
39
|
"test": "vitest run"
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: wallet-adapter-integration
|
|
3
|
+
description: Connect a dApp to a Miden wallet with @miden-sdk/miden-wallet-adapter. Covers provider wiring, the WalletReadyState lifecycle, the request* surface and transaction shapes, the Wallet*Error taxonomy, the wallet-as-signer path into MidenClient, and the traps that only show up in production. Use when adding wallet connect to an app, debugging a connect or transaction failure, or writing a new wallet adapter.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Miden wallet adapter integration
|
|
7
|
+
|
|
8
|
+
The adapter is a thin, typed channel between your page and a wallet that
|
|
9
|
+
injects itself into `window`. It holds no keys, no client and no chain state.
|
|
10
|
+
Every call is a request the wallet may prompt on, refuse, or answer from its
|
|
11
|
+
own store.
|
|
12
|
+
|
|
13
|
+
## Pick the package
|
|
14
|
+
|
|
15
|
+
| Package | Install when |
|
|
16
|
+
| ----------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
|
|
17
|
+
| `@miden-sdk/miden-wallet-adapter` | React app. Re-exports the four below and serves the stylesheet at `@miden-sdk/miden-wallet-adapter/styles.css`. |
|
|
18
|
+
| `@miden-sdk/miden-wallet-adapter-base` | No React, or you are writing an adapter. Types, errors, transaction shapes, `BaseWalletAdapter`. |
|
|
19
|
+
| `@miden-sdk/miden-wallet-adapter-miden` | `MidenWalletAdapter`, the adapter for the Bread wallet extension. |
|
|
20
|
+
| `@miden-sdk/miden-wallet-adapter-react` | `WalletProvider`, `useWallet`, `MidenFiSignerProvider`. |
|
|
21
|
+
| `@miden-sdk/miden-wallet-adapter-reactui` | Prebuilt connect button, dropdown and wallet modal. |
|
|
22
|
+
|
|
23
|
+
Install the peers yourself: `@miden-sdk/miden-sdk` (base, miden and react all
|
|
24
|
+
declare it as a peer dependency) and, for anything that pulls the react
|
|
25
|
+
package, `@miden-sdk/react`. The react package's entry point imports
|
|
26
|
+
`SignerContext` from `@miden-sdk/react` even if you only ever call
|
|
27
|
+
`useWallet`, so the module must resolve at build time.
|
|
28
|
+
|
|
29
|
+
## Wiring: two shapes
|
|
30
|
+
|
|
31
|
+
### A. The wallet does the work
|
|
32
|
+
|
|
33
|
+
`WalletProvider` owns wallet selection and connection state. `useWallet`
|
|
34
|
+
exposes it.
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
// wallets.ts - module scope, so the array identity never changes
|
|
38
|
+
import { MidenWalletAdapter } from "@miden-sdk/miden-wallet-adapter";
|
|
39
|
+
export const wallets = [new MidenWalletAdapter({ appName: "My dApp" })];
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import {
|
|
44
|
+
AllowedPrivateData,
|
|
45
|
+
PrivateDataPermission,
|
|
46
|
+
WalletAdapterNetwork,
|
|
47
|
+
WalletModalProvider,
|
|
48
|
+
WalletMultiButton,
|
|
49
|
+
WalletProvider,
|
|
50
|
+
} from "@miden-sdk/miden-wallet-adapter";
|
|
51
|
+
import "@miden-sdk/miden-wallet-adapter/styles.css";
|
|
52
|
+
import { wallets } from "./wallets";
|
|
53
|
+
|
|
54
|
+
export function App() {
|
|
55
|
+
return (
|
|
56
|
+
<WalletProvider
|
|
57
|
+
wallets={wallets}
|
|
58
|
+
network={WalletAdapterNetwork.Testnet}
|
|
59
|
+
privateDataPermission={PrivateDataPermission.UponRequest}
|
|
60
|
+
allowedPrivateData={AllowedPrivateData.Assets | AllowedPrivateData.Notes}
|
|
61
|
+
onError={(error) => console.error(error.name, error.message)}
|
|
62
|
+
>
|
|
63
|
+
<WalletModalProvider>
|
|
64
|
+
<WalletMultiButton />
|
|
65
|
+
</WalletModalProvider>
|
|
66
|
+
</WalletProvider>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`network`, `privateDataPermission` and `allowedPrivateData` belong on the
|
|
72
|
+
provider. `connect()` takes no arguments in practice: the provider's `connect`
|
|
73
|
+
ignores anything passed to it and forwards its own props to the adapter.
|
|
74
|
+
|
|
75
|
+
### B. The wallet holds the key, your app drives `MidenClient`
|
|
76
|
+
|
|
77
|
+
`MidenFiSignerProvider` does everything `WalletProvider` does and also
|
|
78
|
+
publishes a `SignerContext` for `@miden-sdk/react`, so `MidenProvider` builds
|
|
79
|
+
a client whose signing callback is the wallet's `signBytes`.
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
import { MidenFiSignerProvider } from "@miden-sdk/miden-wallet-adapter-react";
|
|
83
|
+
import { WalletAdapterNetwork } from "@miden-sdk/miden-wallet-adapter-base";
|
|
84
|
+
import { MidenProvider } from "@miden-sdk/react";
|
|
85
|
+
|
|
86
|
+
<MidenFiSignerProvider appName="My dApp" network={WalletAdapterNetwork.Testnet}>
|
|
87
|
+
<MidenProvider config={{ rpcUrl: "testnet" }}>
|
|
88
|
+
<App />
|
|
89
|
+
</MidenProvider>
|
|
90
|
+
</MidenFiSignerProvider>;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`MidenProvider` must be a descendant, not an ancestor: the signer context is
|
|
94
|
+
provided by `MidenFiSignerProvider` and consumed by `MidenProvider`.
|
|
95
|
+
|
|
96
|
+
It creates a `MidenWalletAdapter` for you when you pass no `wallets`, and
|
|
97
|
+
auto-selects the wallet when exactly one is available. It also provides the
|
|
98
|
+
same context `useWallet` and every reactui component read, so the buttons and
|
|
99
|
+
the modal work underneath it.
|
|
100
|
+
|
|
101
|
+
The account it configures is the connected one: `accountConfig.importAccountId`
|
|
102
|
+
defaults to the wallet's `address`, `publicKeyCommitment` is the adapter's
|
|
103
|
+
`publicKey`, and the IndexedDB store is named `midenfi_<address>`. Override
|
|
104
|
+
with `importAccountId`, `accountType` (default
|
|
105
|
+
`"RegularAccountImmutableCode"`), `storageMode` (`"private" | "public"`,
|
|
106
|
+
default `"public"`) and `customComponents`.
|
|
107
|
+
|
|
108
|
+
Read wallet state inside it with `useMidenFiWallet()`, which throws if it is
|
|
109
|
+
rendered outside the provider, or with `useWallet()` from the same package.
|
|
110
|
+
|
|
111
|
+
## The readiness lifecycle
|
|
112
|
+
|
|
113
|
+
`WalletReadyState` on the adapter, mirrored per wallet in `useWallet().wallets`:
|
|
114
|
+
|
|
115
|
+
| State | Meaning |
|
|
116
|
+
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
117
|
+
| `Unsupported` | No DOM. `MidenWalletAdapter` enters this state when `window` or `document` is undefined at construction, and never leaves it. |
|
|
118
|
+
| `NotDetected` | DOM present, nothing injected yet. The starting state in a browser. |
|
|
119
|
+
| `Installed` | The wallet injected itself. `MidenWalletAdapter` polls for `window.midenWallet` or `window.miden` once a second, on `DOMContentLoaded`, on `load` and immediately, then emits `readyStateChange`. |
|
|
120
|
+
| `Loadable` | A wallet that needs no install. No adapter in this repo reports it, but the providers treat it as connectable. |
|
|
121
|
+
|
|
122
|
+
The connect path is: `select(name)` writes the wallet name to
|
|
123
|
+
`localStorage` (key `walletName`, override with `localStorageKey`), the
|
|
124
|
+
provider resolves it to an adapter, then `connect()` drives the handshake.
|
|
125
|
+
With `WalletProvider` you must select first or `connect()` throws
|
|
126
|
+
`WalletNotSelectedError`.
|
|
127
|
+
|
|
128
|
+
If `readyState` is neither `Installed` nor `Loadable`, the provider's
|
|
129
|
+
`connect()` clears the stored name, opens `adapter.url` in a new tab (the
|
|
130
|
+
extension's store listing) and throws `WalletNotReadyError`.
|
|
131
|
+
|
|
132
|
+
`autoConnect` is off by default. When on, it connects as soon as a stored
|
|
133
|
+
wallet resolves to a ready adapter, and clears the stored name if that fails.
|
|
134
|
+
It never rethrows; the failure reaches you through `onError` only.
|
|
135
|
+
|
|
136
|
+
Connecting twice is deliberately not a no-op. A second `connect()` re-drives
|
|
137
|
+
the handshake so a dApp whose JS context survived a park and restore gets its
|
|
138
|
+
account back. The cost is that a wallet that locked in the meantime may
|
|
139
|
+
prompt for unlock.
|
|
140
|
+
|
|
141
|
+
## Calling the wallet
|
|
142
|
+
|
|
143
|
+
`useWallet()` and `useMidenFiWallet()` return each method as
|
|
144
|
+
`fn | undefined`. They are `undefined` until a wallet is selected, and reject
|
|
145
|
+
with `WalletNotConnectedError` while disconnected. Always guard.
|
|
146
|
+
|
|
147
|
+
| Method | Returns | Notes |
|
|
148
|
+
| --------------------------------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
149
|
+
| `requestSend(tx)` | transaction id | `MidenSendTransaction` payload. |
|
|
150
|
+
| `requestConsume(tx)` | transaction id | `MidenConsumeTransaction` payload. |
|
|
151
|
+
| `requestTransaction(tx)` | transaction id | A `MidenTransaction` envelope. Dispatches by `type` to the send and consume endpoints; anything else goes to the wallet's generalized endpoint. |
|
|
152
|
+
| `waitForTransaction(txId, timeout?)` | `{ txHash, outputNotes }` | `outputNotes` are `Note` objects from `@miden-sdk/miden-sdk`. |
|
|
153
|
+
| `requestAssets()` | `{ faucetId, amount }[]` | `amount` is a string. |
|
|
154
|
+
| `requestConsumableNotes()` | `InputNoteDetails[]` | From the wallet's store. |
|
|
155
|
+
| `requestPrivateNotes(filter, noteIds?)` | `InputNoteDetails[]` | `filter` is a `NoteFilterTypes` from `@miden-sdk/miden-sdk`. |
|
|
156
|
+
| `importPrivateNote(bytes)` | note id | `bytes` is a serialized note. |
|
|
157
|
+
| `signBytes(data, kind)` | `Uint8Array` | `kind` is `"word"` or `"signingInputs"`. |
|
|
158
|
+
| `createAccount(params?)` | account id | Only on `MidenFiSignerProvider`'s context. See the traps. |
|
|
159
|
+
| `requestGuardianInfo()` | `GuardianInfo` | Whether the connected account is a guardian account, and its endpoint, provider and sync status. |
|
|
160
|
+
|
|
161
|
+
Everything the wallet returns about private state is gated by the
|
|
162
|
+
`AllowedPrivateData` bitmask you connected with: `None`, `Assets`, `Notes`,
|
|
163
|
+
`Storage`, `All`. Combine with `|`. `PrivateDataPermission.UponRequest` makes
|
|
164
|
+
the wallet ask every time; `Auto` lets it answer without a prompt.
|
|
165
|
+
|
|
166
|
+
## Transaction shapes
|
|
167
|
+
|
|
168
|
+
All three are plain objects you can build by hand, with classes and static
|
|
169
|
+
factories in `@miden-sdk/miden-wallet-adapter-base` that build them for you.
|
|
170
|
+
The constructor signatures:
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
SendTransaction(sender, recipient, faucetId, noteType, amount, recallBlocks?)
|
|
174
|
+
ConsumeTransaction(faucetId, noteId, noteType, amount, noteBytes?)
|
|
175
|
+
CustomTransaction(address, recipientAddress, transactionRequest,
|
|
176
|
+
inputNoteIds?, inputNoteBytes?)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
`amount` is a `number`, not a `bigint`, unlike everything in
|
|
180
|
+
`@miden-sdk/miden-sdk`.
|
|
181
|
+
|
|
182
|
+
`noteType` is the string `"public"` or `"private"`. `ConsumeTransaction` and
|
|
183
|
+
`CustomTransaction` base64-encode the `Uint8Array` arguments for you, and
|
|
184
|
+
`CustomTransaction` calls `transactionRequest.serialize()` on the live
|
|
185
|
+
`TransactionRequest` you hand it, so build that with `@miden-sdk/miden-sdk`
|
|
186
|
+
first.
|
|
187
|
+
|
|
188
|
+
`requestTransaction` wants the envelope, not a bare payload:
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
import { Transaction } from "@miden-sdk/miden-wallet-adapter";
|
|
192
|
+
|
|
193
|
+
const tx = Transaction.createCustomTransaction(
|
|
194
|
+
address,
|
|
195
|
+
recipientAddress,
|
|
196
|
+
transactionRequest
|
|
197
|
+
);
|
|
198
|
+
const txId = await requestTransaction(tx);
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
`Transaction.createSendTransaction` and `Transaction.createConsumeTransaction`
|
|
202
|
+
build the other two envelopes, and the adapter routes them back to the
|
|
203
|
+
dedicated endpoints.
|
|
204
|
+
|
|
205
|
+
## Confirming a transaction
|
|
206
|
+
|
|
207
|
+
The id a request resolves with names a transaction the wallet **accepted**,
|
|
208
|
+
not one that landed. Poll for the on-chain result:
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
const txId = await requestSend({
|
|
212
|
+
senderAddress: address,
|
|
213
|
+
recipientAddress: recipient,
|
|
214
|
+
faucetId,
|
|
215
|
+
noteType: "public",
|
|
216
|
+
amount: 100,
|
|
217
|
+
});
|
|
218
|
+
const { txHash, outputNotes } = await waitForTransaction(txId);
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
A wallet that resolves with no id at all is treated as a silent drop and
|
|
222
|
+
throws `WalletTransactionError`. A wallet that reports a failed transaction
|
|
223
|
+
from `waitForTransaction` also throws `WalletTransactionError`, carrying the
|
|
224
|
+
wallet's `errorMessage`.
|
|
225
|
+
|
|
226
|
+
## Error taxonomy
|
|
227
|
+
|
|
228
|
+
Every error extends `WalletError`, which carries the underlying failure on
|
|
229
|
+
`.error` and a stable `.name`. Switch on `error.name` or use `instanceof`.
|
|
230
|
+
|
|
231
|
+
| Error | Thrown when | Do |
|
|
232
|
+
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------- |
|
|
233
|
+
| `WalletNotSelectedError` | `connect()` with no wallet selected. | Call `select(name)`, or open the modal. |
|
|
234
|
+
| `WalletNotReadyError` | `connect()` while the adapter is not `Installed` or `Loadable`. The provider has already opened the install page. | Tell the user to install or unlock, then retry. |
|
|
235
|
+
| `WalletConnectionError` | The wallet rejected the handshake, or returned no address. | Surface it. A rejection here is usually the user declining. |
|
|
236
|
+
| `WalletNotConnectedError` | Any request while no wallet is connected. | Gate your UI on `connected`. |
|
|
237
|
+
| `WalletTransactionError` | The wallet rejected a request, returned no transaction id, or reported a failed transaction. | Read `.error` for the wallet's own message. |
|
|
238
|
+
| `WalletDisconnectionError` | `disconnect()` failed wallet-side. Emitted on the `error` event, never thrown: `disconnect()` still resolves and still emits `disconnect`. | Do not rely on try/catch around `disconnect()`. |
|
|
239
|
+
|
|
240
|
+
`base` exports many more (`WalletLoadError`, `WalletConfigError`,
|
|
241
|
+
`WalletDisconnectedError`, `WalletAccountError`, `WalletAddressError`,
|
|
242
|
+
`WalletKeypairError`, `WalletSendTransactionError`, `WalletSignMessageError`,
|
|
243
|
+
`WalletSignTransactionError`, `WalletTimeoutError`, `WalletWindowBlockedError`,
|
|
244
|
+
`WalletWindowClosedError`, `WalletDecryptionError`,
|
|
245
|
+
`WalletDecryptionNotAllowedError`, `WalletPrivateDataPermissionError`,
|
|
246
|
+
`WalletRecordsError`). Nothing in these packages throws them; they exist for
|
|
247
|
+
other adapters to use. Do not write handlers that wait for them.
|
|
248
|
+
|
|
249
|
+
Errors reach you twice: the provider calls `onError` (or `console.error` when
|
|
250
|
+
you pass none) **and** the promise rejects. Report in one place or the user
|
|
251
|
+
sees the same failure twice. `importPrivateNote` and `requestConsumableNotes`
|
|
252
|
+
emit the wallet's raw error rather than a `WalletError` subclass, so an
|
|
253
|
+
`onError` handler must not assume `error.name` is one of the names above.
|
|
254
|
+
|
|
255
|
+
## Adapter or `MidenClient` directly?
|
|
256
|
+
|
|
257
|
+
- **Wallet builds, signs, submits.** `requestSend`, `requestConsume`,
|
|
258
|
+
`requestTransaction`. The wallet shows its own confirmation UI and your app
|
|
259
|
+
never touches a key or a prover. Simplest, and the right default.
|
|
260
|
+
- **Your app builds, the wallet signs.** `MidenFiSignerProvider` plus
|
|
261
|
+
`MidenProvider`. You construct `TransactionRequest`s with
|
|
262
|
+
`@miden-sdk/miden-sdk` and the client calls back into `signBytes` for the
|
|
263
|
+
signature. Reach for this when you need transaction shapes the wallet's
|
|
264
|
+
endpoints do not express, or you want the client's local state.
|
|
265
|
+
- **Reads.** `requestAssets`, `requestConsumableNotes` and
|
|
266
|
+
`requestPrivateNotes` answer from the wallet's store and only within the
|
|
267
|
+
permission you connected with. If you need chain state your app controls,
|
|
268
|
+
sync your own client instead.
|
|
269
|
+
|
|
270
|
+
The two are not exclusive: a `CustomTransaction` carries a serialized
|
|
271
|
+
`TransactionRequest`, so building one already means having the SDK loaded.
|
|
272
|
+
|
|
273
|
+
## Traps
|
|
274
|
+
|
|
275
|
+
**Construct adapters once.** An adapter array built inline in JSX is a new
|
|
276
|
+
array with a new adapter on every render. The provider rewraps its wallet
|
|
277
|
+
list, the selected adapter's identity changes, and the effect that disconnects
|
|
278
|
+
the previous adapter fires. Module scope, or `useMemo` with a stable
|
|
279
|
+
dependency list.
|
|
280
|
+
|
|
281
|
+
**An adapter constructed without a DOM is `Unsupported` forever.** The
|
|
282
|
+
constructor decides `readyState` once and only starts detection when `window`
|
|
283
|
+
and `document` exist. Under SSR, construct adapters in a client-only module.
|
|
284
|
+
|
|
285
|
+
**Server and client render different wallet state.** Wallet selection is read
|
|
286
|
+
from `localStorage` inside a `useState` initializer. On the server that read
|
|
287
|
+
fails and is swallowed, so the server renders "no wallet". Gate
|
|
288
|
+
wallet-dependent markup on a mounted flag if you server-render.
|
|
289
|
+
|
|
290
|
+
**The miden package imports the SDK eagerly.** `MidenWalletAdapter` imports
|
|
291
|
+
`@miden-sdk/miden-sdk` at module scope to deserialize output notes, which
|
|
292
|
+
pulls the eager WASM entry point and its top-level await into any module graph
|
|
293
|
+
that reaches it. Keep it out of server-rendered modules.
|
|
294
|
+
|
|
295
|
+
**`connect()` arguments are dropped.** The reactui buttons and modal accept
|
|
296
|
+
`privateDataPermission`, `network` and `allowedPrivateData` props and pass
|
|
297
|
+
them to `connect()`, which ignores them. Whatever you set on the provider is
|
|
298
|
+
what the wallet is asked for. Setting the network on the modal and not on the
|
|
299
|
+
provider is a silent testnet default.
|
|
300
|
+
|
|
301
|
+
**`createAccount` is on the interface but not in the wallets.** The package
|
|
302
|
+
ships a conformance suite (`getSurfaceCases`, `getBehaviorCases`,
|
|
303
|
+
`runConformance` from the miden package) precisely because this method has
|
|
304
|
+
been on the published `MidenWallet` interface with no provider implementing it
|
|
305
|
+
and no wire message behind it. Calling it yields
|
|
306
|
+
`TypeError: wallet.createAccount is not a function`. It is also absent from
|
|
307
|
+
`WalletProvider`'s context; only `MidenFiSignerProvider` exposes it. Probe
|
|
308
|
+
before you call, and let the SDK create accounts instead.
|
|
309
|
+
|
|
310
|
+
**Treating the returned id as confirmation.** On a fast local node a queued
|
|
311
|
+
transaction lands before your next line runs, so skipping `waitForTransaction`
|
|
312
|
+
looks correct in development and drops results in production.
|
|
313
|
+
|
|
314
|
+
**The not-installed path is never exercised in development.** Your machine has
|
|
315
|
+
the extension. Test the `NotDetected` branch: `connect()` opens a store page
|
|
316
|
+
in a new tab and throws.
|
|
317
|
+
|
|
318
|
+
## Writing an adapter for another wallet
|
|
319
|
+
|
|
320
|
+
Extend `BaseMessageSignerWalletAdapter` from
|
|
321
|
+
`@miden-sdk/miden-wallet-adapter-base`. It is an `EventEmitter` over
|
|
322
|
+
`connect`, `disconnect`, `error` and `readyStateChange`, and requires
|
|
323
|
+
`name` (branded `WalletName`), `url`, `icon`, `readyState`, `address`,
|
|
324
|
+
`publicKey`, `connecting`, `supportedTransactionVersions`, `connect`,
|
|
325
|
+
`disconnect` and the full request surface. `connected` is derived from
|
|
326
|
+
`address`. Use `scopePollingDetectionStrategy` for injection detection: it
|
|
327
|
+
returns immediately without a DOM and disposes its listeners on first hit.
|
|
328
|
+
|
|
329
|
+
Emit `error` with a `WalletError` subclass before rethrowing, so a provider's
|
|
330
|
+
`onError` sees a typed failure. Then run the conformance suite from
|
|
331
|
+
`@miden-sdk/miden-wallet-adapter-miden` against your real provider object, not
|
|
332
|
+
against a mock: `getSurfaceCases` needs no connection and catches a missing
|
|
333
|
+
method, `getBehaviorCases` needs a live connected provider and checks the
|
|
334
|
+
response envelopes. Assert `CONFORMANCE_BUILD.real` first so a mocked module
|
|
335
|
+
cannot make the run pass vacuously.
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
WalletReadyState,
|
|
4
|
-
BaseWalletAdapter,
|
|
5
|
-
scopePollingDetectionStrategy,
|
|
6
|
-
} from "../adapter";
|
|
7
|
-
|
|
8
|
-
describe("WalletReadyState enum", () => {
|
|
9
|
-
it("has correct values", () => {
|
|
10
|
-
expect(WalletReadyState.Installed).toBe("Installed");
|
|
11
|
-
expect(WalletReadyState.NotDetected).toBe("NotDetected");
|
|
12
|
-
expect(WalletReadyState.Loadable).toBe("Loadable");
|
|
13
|
-
expect(WalletReadyState.Unsupported).toBe("Unsupported");
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe("BaseWalletAdapter", () => {
|
|
18
|
-
// Concrete subclass for testing
|
|
19
|
-
class TestAdapter extends BaseWalletAdapter {
|
|
20
|
-
name = "Test" as any;
|
|
21
|
-
url = "https://test.com";
|
|
22
|
-
icon = "icon";
|
|
23
|
-
readyState = WalletReadyState.Installed;
|
|
24
|
-
address: string | null = null;
|
|
25
|
-
publicKey: Uint8Array | null = null;
|
|
26
|
-
connecting = false;
|
|
27
|
-
supportedTransactionVersions = null;
|
|
28
|
-
|
|
29
|
-
async connect() {}
|
|
30
|
-
async disconnect() {}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
it("connected returns true when address is set", () => {
|
|
34
|
-
const adapter = new TestAdapter();
|
|
35
|
-
adapter.address = "0xabc";
|
|
36
|
-
expect(adapter.connected).toBe(true);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("connected returns false when address is null", () => {
|
|
40
|
-
const adapter = new TestAdapter();
|
|
41
|
-
expect(adapter.connected).toBe(false);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe("scopePollingDetectionStrategy", () => {
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
vi.useFakeTimers();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
afterEach(() => {
|
|
51
|
-
vi.useRealTimers();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("calls detect immediately and cleans up on detection", () => {
|
|
55
|
-
const detect = vi.fn().mockReturnValue(true);
|
|
56
|
-
scopePollingDetectionStrategy(detect);
|
|
57
|
-
expect(detect).toHaveBeenCalled();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("sets up polling interval when not immediately detected", () => {
|
|
61
|
-
let callCount = 0;
|
|
62
|
-
const detect = vi.fn(() => {
|
|
63
|
-
callCount++;
|
|
64
|
-
return callCount >= 3;
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
scopePollingDetectionStrategy(detect);
|
|
68
|
-
// First call is immediate (returns false)
|
|
69
|
-
expect(detect).toHaveBeenCalledTimes(1);
|
|
70
|
-
|
|
71
|
-
// Advance timer to trigger interval
|
|
72
|
-
vi.advanceTimersByTime(1000);
|
|
73
|
-
expect(detect).toHaveBeenCalledTimes(2);
|
|
74
|
-
|
|
75
|
-
vi.advanceTimersByTime(1000);
|
|
76
|
-
expect(detect).toHaveBeenCalledTimes(3);
|
|
77
|
-
|
|
78
|
-
// After detection (callCount >= 3), interval should be cleared
|
|
79
|
-
vi.advanceTimersByTime(1000);
|
|
80
|
-
expect(detect).toHaveBeenCalledTimes(3);
|
|
81
|
-
});
|
|
82
|
-
});
|