@amadeus-protocol/wallet-sdk 0.1.7 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +249 -69
- package/dist/client/injected.d.ts +4 -3
- package/dist/client/injected.d.ts.map +1 -1
- package/dist/client/injected.js +23 -15
- package/dist/client/injected.js.map +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +2 -1
- package/dist/constants.js.map +1 -1
- package/dist/crypto/box.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +2 -2
- package/dist/react/index.js.map +1 -1
- package/dist/transport/bridge.js +1 -1
- package/dist/transport/envelope.js +1 -1
- package/dist/transport/session.js +1 -1
- package/dist/tx.js +1 -1
- package/dist/types.d.ts +28 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/wallet/handler.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,74 +1,255 @@
|
|
|
1
1
|
# @amadeus-protocol/wallet-sdk
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
3
|
+
The connection layer between Amadeus dApps and Amadeus wallets: the typed
|
|
4
|
+
`window.amadeus` provider and a client for it, a React hook, Amadeus Connect (QR /
|
|
5
|
+
deep link + an end-to-end encrypted relay to the mobile wallet), the wallet-side
|
|
6
|
+
request handler, transaction and message signing, and BLS API-key tokens.
|
|
7
|
+
|
|
8
|
+
The Amadeus mobile wallet runs this package on its side of Amadeus Connect, so a
|
|
9
|
+
dApp that uses it runs the same crypto and protocol code as the wallet it talks to.
|
|
10
|
+
Key derivation, encoding and transaction building come from
|
|
11
|
+
[`@amadeus-protocol/sdk`](https://www.npmjs.com/package/@amadeus-protocol/sdk);
|
|
12
|
+
this package adds only the dApp ↔ wallet layer.
|
|
13
|
+
|
|
14
|
+
**Full documentation: [docs.ama.one/wallet-sdk](https://docs.ama.one/wallet-sdk)**
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install @amadeus-protocol/wallet-sdk @amadeus-protocol/sdk
|
|
20
|
+
# or
|
|
21
|
+
bun add @amadeus-protocol/wallet-sdk @amadeus-protocol/sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
- Peer dependency `@amadeus-protocol/sdk` `^1.3.0` (required); `react` `>=18`
|
|
25
|
+
only for the `/react` entry point.
|
|
26
|
+
- ESM only, Node.js 20+ on servers. Runs in browsers, Node.js and React Native
|
|
27
|
+
(Hermes; session keys, nonces and ids come from `crypto.getRandomValues`, so
|
|
28
|
+
polyfill it there, e.g. with `react-native-get-random-values`).
|
|
29
|
+
|
|
30
|
+
| Import path | Contents |
|
|
31
|
+
| ------------------------------------ | ----------------------------------------------------------- |
|
|
32
|
+
| `@amadeus-protocol/wallet-sdk` | Everything below except React |
|
|
33
|
+
| `@amadeus-protocol/wallet-sdk/react` | `useWallet` and its types `UseWalletResult`, `WalletStatus` |
|
|
34
|
+
|
|
35
|
+
## What's in the package
|
|
36
|
+
|
|
37
|
+
| Area | Main exports | Docs |
|
|
38
|
+
| --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------- |
|
|
39
|
+
| **Injected client** (browser extension) | `createInjectedWalletClient`, `WalletClient`, `ApiKeyStore` | [Connect a dApp](https://docs.ama.one/wallet-sdk/connect-a-dapp) |
|
|
40
|
+
| **React** | `useWallet` (from `/react`) | [React](https://docs.ama.one/wallet-sdk/react) |
|
|
41
|
+
| **Provider contract** | `AmadeusProvider`, `getAmadeusProvider`, `isProviderAvailable`, `AmadeusEventPayloadMap`, `PROVIDER_EVENTS`, `WALLET_WINDOW_EVENTS`, `WALLET_INITIALIZED_EVENT` | [Provider reference](https://docs.ama.one/wallet-sdk/provider-reference) |
|
|
42
|
+
| **Amadeus Connect** (dApp side) | `createConnectRequest`, `completeConnect`, `parseConnectResponseUri`, `BridgeClient`, `deriveConnectChannel`, `deriveBridgeChannels`, `makeRequest`, `sealRequest`, `openResponse`, `DEFAULT_BRIDGE_URL` | [Amadeus Connect](https://docs.ama.one/wallet-sdk/amadeus-connect) |
|
|
43
|
+
| **Wallet side** | `parseConnectUri`, `isConnectRequestExpired`, `assertAllowedBridgeUrl`, `approveConnect`, `buildConnectResponseUri`, `openRequest`, `guardRequest`, `createMemorySeenStore`, `handleRequest`, `sealResponse`, `WALLET_METHODS` | [Wallet integration](https://docs.ama.one/wallet-sdk/wallet-integration) |
|
|
44
|
+
| **Transactions** | `signTransaction`, `submitTransaction`, `encodeBinaryValues`, `decodeBinaryValues`, `describeBinaryValues` | [Signing and API keys](https://docs.ama.one/wallet-sdk/signing-and-api-keys) |
|
|
45
|
+
| **Messages** | `signMessage`, `verifyMessage` | [Signing and API keys](https://docs.ama.one/wallet-sdk/signing-and-api-keys) |
|
|
46
|
+
| **API keys** | `generateApiKey`, `verifyApiKey`, `decodeApiKey` | [Signing and API keys](https://docs.ama.one/wallet-sdk/signing-and-api-keys) |
|
|
47
|
+
| **Wire validation** | zod schemas: `signTransactionRequestSchema`, `signMessageRequestSchema`, `generateApiKeyRequestSchema`, `switchAccountRequestSchema`, `connectTranscriptSchema`, `addressSchema`, `originSchema`, `networkSchema` | [Provider reference](https://docs.ama.one/wallet-sdk/provider-reference) |
|
|
48
|
+
| **Low-level crypto** | `signConnect`, `verifyConnect`, `buildConnectTranscript`, `generateSessionKeypair`, `deriveSharedKey`, `seal`, `open`, `deriveSigner`, `signHashed`, `verifyHashed` | [Signing and API keys](https://docs.ama.one/wallet-sdk/signing-and-api-keys) |
|
|
49
|
+
| **Constants and errors** | DSTs (`TX_DST`, `MESSAGE_DST`, `API_KEY_DST`, `CONNECT_DST`), byte lengths, `PROTOCOL_VERSION`, `NETWORKS`; `WalletSdkError` with a stable `code` | [Overview](https://docs.ama.one/wallet-sdk) |
|
|
50
|
+
|
|
51
|
+
`signTransaction`, `signMessage` and `generateApiKey` take a seed: they are what a
|
|
52
|
+
wallet runs. A dApp asks the wallet for their results instead.
|
|
53
|
+
|
|
54
|
+
## Browser extension
|
|
55
|
+
|
|
56
|
+
`createInjectedWalletClient()` wraps the injected `window.amadeus` provider. The
|
|
57
|
+
wallet only signs; `signAndSubmit` posts the signed bytes to the node you pass,
|
|
58
|
+
and `nodeUrl` must include `/api`.
|
|
34
59
|
|
|
35
60
|
```ts
|
|
36
|
-
import {
|
|
61
|
+
import { toAtomicAma } from '@amadeus-protocol/sdk'
|
|
62
|
+
import { createInjectedWalletClient } from '@amadeus-protocol/wallet-sdk'
|
|
63
|
+
|
|
64
|
+
const recipient = '<Base58 address>'
|
|
65
|
+
const wallet = createInjectedWalletClient()
|
|
66
|
+
|
|
67
|
+
if (wallet.isAvailable()) {
|
|
68
|
+
const account = await wallet.connect()
|
|
69
|
+
const { txHash } = await wallet.signAndSubmit(
|
|
70
|
+
{
|
|
71
|
+
contract: 'Coin',
|
|
72
|
+
method: 'transfer',
|
|
73
|
+
args: [recipient, String(toAtomicAma(1.5)), 'AMA']
|
|
74
|
+
},
|
|
75
|
+
{ nodeUrl: 'https://mainnet-rpc.ama.one/api', wait: true }
|
|
76
|
+
)
|
|
77
|
+
console.log(`${account} sent ${txHash}`)
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The client also has `getAccount`, `getNetwork`, `signTransaction`, `on` / `off`
|
|
82
|
+
for provider events, `ensureApiKey` (returns a cached API key signed by the
|
|
83
|
+
active account or asks the wallet for a new one) and `switchAccount(target?)`.
|
|
84
|
+
`switchAccount` asks the wallet to change the active account; the extension asks
|
|
85
|
+
the user to approve (it resolves at once only when `target` is already active),
|
|
86
|
+
and the call throws `WalletSdkError` code `UNSUPPORTED` on extension builds
|
|
87
|
+
without `requestSwitchAccount`.
|
|
88
|
+
|
|
89
|
+
The extension can inject `window.amadeus` after your script runs. Listen for
|
|
90
|
+
`WALLET_INITIALIZED_EVENT` (`amadeus-wallet#initialized`, not
|
|
91
|
+
`amadeus#initialized`), or use the React hook, which does it for you.
|
|
37
92
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
93
|
+
## React
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
import { useWallet } from '@amadeus-protocol/wallet-sdk/react'
|
|
97
|
+
|
|
98
|
+
export function WalletButton() {
|
|
99
|
+
const { status, account, connect, switchAccount } = useWallet()
|
|
100
|
+
|
|
101
|
+
if (status === 'unavailable') return <p>Install the Amadeus Wallet extension</p>
|
|
102
|
+
if (status !== 'connected') {
|
|
103
|
+
return (
|
|
104
|
+
<button onClick={() => void connect()} disabled={status === 'connecting'}>
|
|
105
|
+
Connect wallet
|
|
106
|
+
</button>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
return <button onClick={() => void switchAccount()}>{account}</button>
|
|
110
|
+
}
|
|
42
111
|
```
|
|
43
112
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
113
|
+
`useWallet()` returns `status` (`unavailable`, `disconnected`, `connecting`,
|
|
114
|
+
`connected`), `account`, `network`, `isAvailable`, the underlying `client`, and
|
|
115
|
+
`connect`, `disconnect`, `switchAccount`, `signTransaction`, `signAndSubmit`,
|
|
116
|
+
`ensureApiKey`. It moves from `unavailable` to `disconnected` when the provider
|
|
117
|
+
is injected late. If the provider is present when the hook mounts, it also reads
|
|
118
|
+
the current account and network and keeps them in sync with the wallet's events.
|
|
119
|
+
`disconnect()` only clears the hook's local state.
|
|
120
|
+
|
|
121
|
+
## Amadeus Connect (mobile wallet)
|
|
122
|
+
|
|
123
|
+
For the Amadeus mobile wallet, on another device or the same one:
|
|
124
|
+
|
|
125
|
+
1. The dApp calls `createConnectRequest({ origin })` and shows the returned
|
|
126
|
+
`amadeus://v1/connect?...` URI as a QR code or link. Requests expire after 120
|
|
127
|
+
seconds by default and carry a relay URL (`https://bridge.ama.one` unless you
|
|
128
|
+
pass `bridgeUrl`).
|
|
129
|
+
2. The wallet signs a transcript binding the origin, both session keys, the
|
|
130
|
+
challenge and the request id, and returns its address. The dApp receives it
|
|
131
|
+
over the relay (`deriveConnectChannel`) or the redirect link and calls
|
|
132
|
+
`completeConnect`, which verifies the signature and derives the shared key.
|
|
133
|
+
3. Requests (`amadeus_signTransaction`, `amadeus_signMessage`,
|
|
134
|
+
`amadeus_getAccounts`, `amadeus_generateApiKey`) then travel as sealed
|
|
135
|
+
envelopes over `BridgeClient`, on two channels derived from the shared key.
|
|
136
|
+
|
|
137
|
+
Over Amadeus Connect, `amadeus_switchNetwork` and `amadeus_switchAccount` come
|
|
138
|
+
back as error responses from `handleRequest`; switching is left to the wallet app.
|
|
139
|
+
See [Amadeus Connect](https://docs.ama.one/wallet-sdk/amadeus-connect) for a
|
|
140
|
+
complete dApp implementation.
|
|
141
|
+
|
|
142
|
+
## Wallet side
|
|
143
|
+
|
|
144
|
+
A wallet answers Amadeus Connect with a few calls. Check expiry and replay before
|
|
145
|
+
showing anything to the user, and sign only after they approve:
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
import type { NetworkType } from '@amadeus-protocol/sdk'
|
|
149
|
+
import {
|
|
150
|
+
approveConnect,
|
|
151
|
+
assertAllowedBridgeUrl,
|
|
152
|
+
createMemorySeenStore,
|
|
153
|
+
guardRequest,
|
|
154
|
+
handleRequest,
|
|
155
|
+
isConnectRequestExpired,
|
|
156
|
+
openRequest,
|
|
157
|
+
parseConnectUri,
|
|
158
|
+
sealResponse,
|
|
159
|
+
type SealedEnvelope,
|
|
160
|
+
type WalletRequest
|
|
161
|
+
} from '@amadeus-protocol/wallet-sdk'
|
|
162
|
+
|
|
163
|
+
interface Account {
|
|
164
|
+
seed: string
|
|
165
|
+
address: string
|
|
166
|
+
network: NetworkType
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Use a persisted store in a real wallet so replays fail across restarts.
|
|
170
|
+
const seenRequests = createMemorySeenStore()
|
|
171
|
+
|
|
172
|
+
export function acceptConnect(uri: string, account: Account) {
|
|
173
|
+
const request = parseConnectUri(uri)
|
|
174
|
+
if (isConnectRequestExpired(request)) throw new Error('Connect request expired')
|
|
175
|
+
if (request.bridgeUrl) assertAllowedBridgeUrl(request.bridgeUrl)
|
|
176
|
+
// Ask the user to approve request.origin before this line.
|
|
177
|
+
return approveConnect(request, { seed: account.seed, address: account.address })
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export async function answer(
|
|
181
|
+
sharedKey: Uint8Array,
|
|
182
|
+
envelope: SealedEnvelope,
|
|
183
|
+
accountFor: (address?: string) => Account,
|
|
184
|
+
confirm: (request: WalletRequest) => Promise<boolean>
|
|
185
|
+
): Promise<SealedEnvelope | null> {
|
|
186
|
+
const request = openRequest(sharedKey, envelope)
|
|
187
|
+
guardRequest(request, seenRequests)
|
|
188
|
+
if (!(await confirm(request))) return null
|
|
189
|
+
return sealResponse(sharedKey, handleRequest(request, accountFor(request.account)))
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
`request.account` is set when the dApp picks which of your accounts signs; when it
|
|
194
|
+
is absent, sign with the account bound at connect. `handleRequest` never throws:
|
|
195
|
+
failures come back as `{ ok: false, error }`.
|
|
196
|
+
Transactions are signed for `network` (mainnet when omitted), so a testnet
|
|
197
|
+
transaction cannot be replayed on mainnet. See
|
|
198
|
+
[Wallet integration](https://docs.ama.one/wallet-sdk/wallet-integration).
|
|
199
|
+
|
|
200
|
+
## API-key tokens
|
|
201
|
+
|
|
202
|
+
`generateApiKey` produces the BLS bearer token `kbs.ama.one` verifies:
|
|
203
|
+
`base58( json{aud,exp} ‖ pubkey48 ‖ sig96 )`, signed over `sha256(json ‖ pubkey)`
|
|
204
|
+
under the `_APIKEY_` DST. A test asserts it is byte-identical to the recipe the
|
|
205
|
+
extension and hub used before. Verification needs no wallet and no network:
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
import { verifyApiKey } from '@amadeus-protocol/wallet-sdk'
|
|
209
|
+
|
|
210
|
+
export function authenticate(authorization: string): string {
|
|
211
|
+
const result = verifyApiKey(authorization.replace(/^Bearer /, ''), { aud: 'amadeus' })
|
|
212
|
+
if (!result.valid) throw new Error(`Rejected API key: ${result.reason}`)
|
|
213
|
+
return result.address
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
The token's address is the public key of the `seed` you sign with. A recovery
|
|
218
|
+
phrase can open two addresses (standard `eip2333`, and `legacy` for wallets
|
|
219
|
+
created by older extension and app builds), so when you start from a phrase,
|
|
220
|
+
resolve the seed with `resolveCandidateForAddress` (`@amadeus-protocol/sdk`
|
|
221
|
+
1.6.0+). It returns `null` if neither derivation opens the address and throws on
|
|
222
|
+
an invalid phrase:
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
import { resolveCandidateForAddress } from '@amadeus-protocol/sdk'
|
|
226
|
+
import { generateApiKey } from '@amadeus-protocol/wallet-sdk'
|
|
227
|
+
|
|
228
|
+
export function apiKeyForAddress(phrase: string, walletAddress: string): string {
|
|
229
|
+
const candidate = resolveCandidateForAddress(phrase, walletAddress)
|
|
230
|
+
if (!candidate) throw new Error('This phrase does not open that address')
|
|
231
|
+
return generateApiKey({ seed: candidate.seed, aud: 'amadeus', expIn: 3600 }).apiKey
|
|
232
|
+
}
|
|
233
|
+
```
|
|
60
234
|
|
|
61
235
|
## Security notes
|
|
62
236
|
|
|
63
|
-
- **Distinct DSTs** (`_TX_`, `_APIKEY_`, `_CONNECT_`) make a signature
|
|
64
|
-
context
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
237
|
+
- **Distinct DSTs** (`_TX_`, `_MSG_`, `_APIKEY_`, `_CONNECT_`) make a signature
|
|
238
|
+
from one context unusable in another. Testnet transactions use the core SDK's
|
|
239
|
+
separate `_TX_TESTNET_` tag.
|
|
240
|
+
- **Message signing** (`signMessage`) signs a UTF-8 string of at most 4096
|
|
241
|
+
characters under its own `_MSG_` tag, so a signed message can never verify as a
|
|
242
|
+
transaction, an API key or a connect proof.
|
|
243
|
+
- **Connect auth signs the full transcript**: origin, both session keys,
|
|
244
|
+
challenge and request id, not just a nonce, which closes key substitution.
|
|
245
|
+
- **Session box**: x25519 + XChaCha20-Poly1305 via `@noble` (Hermes-safe). It
|
|
246
|
+
fails closed on any tamper.
|
|
247
|
+
- **Replay and expiry**: `guardRequest` rejects expired requests and reused ids.
|
|
248
|
+
Give it a persisted store in production.
|
|
249
|
+
- **Untrusted relay**: after connect, channel ids derive from the shared key, so
|
|
250
|
+
the relay sees only ciphertext between opaque ids. The connect response itself
|
|
251
|
+
is plaintext, protected by the connect signature. Bridge URLs must be https
|
|
252
|
+
(http only for localhost).
|
|
72
253
|
|
|
73
254
|
## Develop
|
|
74
255
|
|
|
@@ -76,15 +257,14 @@ if (result.valid) console.log(result.address)
|
|
|
76
257
|
bun install
|
|
77
258
|
bun run test # vitest
|
|
78
259
|
bun run typecheck
|
|
260
|
+
bun run lint
|
|
79
261
|
bun run build # tsdown -> dist/
|
|
262
|
+
bun run examples/e2e-demo.mjs # connect + encrypted sign round trip, after build
|
|
80
263
|
```
|
|
81
264
|
|
|
82
|
-
|
|
265
|
+
`examples/dapp-demo` is a minimal browser dApp that connects to the wallet by QR
|
|
266
|
+
over the relay.
|
|
267
|
+
|
|
268
|
+
## License
|
|
83
269
|
|
|
84
|
-
|
|
85
|
-
self-hosted encrypted bridge, all speaking one envelope.
|
|
86
|
-
2. **`/react`** — `WalletProvider` + `useWallet()` so dApps stop copy-pasting
|
|
87
|
-
provider glue (and the `amadeus#initialized` vs `amadeus-wallet#initialized`
|
|
88
|
-
bug gets fixed once).
|
|
89
|
-
3. **Adoption** — migrate the extension, `hub`, and `prime-hub` off their
|
|
90
|
-
hand-rolled crypto onto this package.
|
|
270
|
+
MIT
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { AmadeusEventPayloadMap, AmadeusProvider, AmadeusProviderEvent, SignTransactionRequest, SignTransactionResponse } from "../types.js";
|
|
2
2
|
/** Where a cached api-key lives. Default is in-memory; dApps can pass localStorage-backed. */
|
|
3
3
|
interface ApiKeyStore {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
/** `aud` is passed so a store can keep one key per audience. */
|
|
5
|
+
get(aud?: string): string | null;
|
|
6
|
+
set(apiKey: string, aud?: string): void;
|
|
6
7
|
}
|
|
7
8
|
interface WalletClient {
|
|
8
9
|
isAvailable(): boolean;
|
|
@@ -22,7 +23,7 @@ interface WalletClient {
|
|
|
22
23
|
txHash: string;
|
|
23
24
|
submitted: unknown;
|
|
24
25
|
}>;
|
|
25
|
-
/** Return a valid cached api-key, minting (and caching) a fresh one if needed. Coalesces concurrent calls. */
|
|
26
|
+
/** Return a valid cached api-key for `aud` signed by the active account, minting (and caching) a fresh one if needed. Coalesces concurrent calls per account + aud. */
|
|
26
27
|
ensureApiKey(options: {
|
|
27
28
|
aud: string;
|
|
28
29
|
expIn: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injected.d.ts","names":[],"sources":["../../src/client/injected.ts"],"mappings":";;UAyBiB;
|
|
1
|
+
{"version":3,"file":"injected.d.ts","names":[],"sources":["../../src/client/injected.ts"],"mappings":";;UAyBiB;;EAEhB,IAAI;EACJ,IAAI,gBAAgB;;UA+BJ;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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { decodeApiKey } from "../crypto/apikey.js";
|
|
1
2
|
import { WalletSdkError } from "../errors.js";
|
|
2
3
|
import { submitTransaction } from "../tx.js";
|
|
3
4
|
import { getAmadeusProvider } from "../types.js";
|
|
4
|
-
import { decodeApiKey } from "../crypto/apikey.js";
|
|
5
5
|
// src/client/injected.ts
|
|
6
6
|
/**
|
|
7
7
|
* A framework-agnostic dApp client over the injected `window.amadeus` provider
|
|
@@ -15,16 +15,18 @@ import { decodeApiKey } from "../crypto/apikey.js";
|
|
|
15
15
|
* same-device, extension-present case.
|
|
16
16
|
*/
|
|
17
17
|
function memoryApiKeyStore() {
|
|
18
|
-
|
|
18
|
+
const keysByAud = /* @__PURE__ */ new Map();
|
|
19
19
|
return {
|
|
20
|
-
get: () =>
|
|
21
|
-
set: (apiKey) =>
|
|
20
|
+
get: (aud = "") => keysByAud.get(aud) ?? null,
|
|
21
|
+
set: (apiKey, aud = "") => {
|
|
22
|
+
keysByAud.set(aud, apiKey);
|
|
23
|
+
}
|
|
22
24
|
};
|
|
23
25
|
}
|
|
24
|
-
function isApiKeyValid(apiKey, leewaySeconds) {
|
|
26
|
+
function isApiKeyValid(apiKey, aud, account, leewaySeconds) {
|
|
25
27
|
try {
|
|
26
|
-
const { payload } = decodeApiKey(apiKey);
|
|
27
|
-
return payload.exp > Math.floor(Date.now() / 1e3) + leewaySeconds;
|
|
28
|
+
const { payload, address } = decodeApiKey(apiKey);
|
|
29
|
+
return address === account && payload.aud === aud && payload.exp > Math.floor(Date.now() / 1e3) + leewaySeconds;
|
|
28
30
|
} catch {
|
|
29
31
|
return false;
|
|
30
32
|
}
|
|
@@ -41,7 +43,7 @@ function createInjectedWalletClient(providerOverride) {
|
|
|
41
43
|
return provider;
|
|
42
44
|
};
|
|
43
45
|
const defaultStore = memoryApiKeyStore();
|
|
44
|
-
|
|
46
|
+
const pendingApiKeys = /* @__PURE__ */ new Map();
|
|
45
47
|
return {
|
|
46
48
|
isAvailable: () => getProvider() !== null,
|
|
47
49
|
getProvider,
|
|
@@ -68,19 +70,25 @@ function createInjectedWalletClient(providerOverride) {
|
|
|
68
70
|
})
|
|
69
71
|
};
|
|
70
72
|
},
|
|
71
|
-
ensureApiKey: ({ aud, expIn, store = defaultStore, leewaySeconds = 60 }) => {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
ensureApiKey: async ({ aud, expIn, store = defaultStore, leewaySeconds = 60 }) => {
|
|
74
|
+
const provider = requireProvider();
|
|
75
|
+
const account = await provider.getAccount();
|
|
76
|
+
const cached = store.get(aud);
|
|
77
|
+
if (cached && isApiKeyValid(cached, aud, account, leewaySeconds)) return cached;
|
|
78
|
+
const pendingKey = JSON.stringify([account, aud]);
|
|
79
|
+
const inFlight = pendingApiKeys.get(pendingKey);
|
|
80
|
+
if (inFlight) return inFlight;
|
|
81
|
+
const request = provider.generateApiKey({
|
|
75
82
|
aud,
|
|
76
83
|
exp_in: expIn
|
|
77
84
|
}).then(({ apiKey }) => {
|
|
78
|
-
store.set(apiKey);
|
|
85
|
+
store.set(apiKey, aud);
|
|
79
86
|
return apiKey;
|
|
80
87
|
}).finally(() => {
|
|
81
|
-
|
|
88
|
+
pendingApiKeys.delete(pendingKey);
|
|
82
89
|
});
|
|
83
|
-
|
|
90
|
+
pendingApiKeys.set(pendingKey, request);
|
|
91
|
+
return request;
|
|
84
92
|
},
|
|
85
93
|
on: (event, cb) => requireProvider().on(event, cb),
|
|
86
94
|
off: (event, cb) => requireProvider().off(event, cb)
|
|
@@ -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\
|
|
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\t/** `aud` is passed so a store can keep one key per audience. */\n\tget(aud?: string): string | null\n\tset(apiKey: string, aud?: string): void\n}\n\nfunction memoryApiKeyStore(): ApiKeyStore {\n\tconst keysByAud = new Map<string, string>()\n\treturn {\n\t\tget: (aud = '') => keysByAud.get(aud) ?? null,\n\t\tset: (apiKey, aud = '') => {\n\t\t\tkeysByAud.set(aud, apiKey)\n\t\t}\n\t}\n}\n\nfunction isApiKeyValid(\n\tapiKey: string,\n\taud: string,\n\taccount: string | null,\n\tleewaySeconds: number\n): boolean {\n\ttry {\n\t\tconst { payload, address } = decodeApiKey(apiKey)\n\t\treturn (\n\t\t\taddress === account &&\n\t\t\tpayload.aud === aud &&\n\t\t\tpayload.exp > Math.floor(Date.now() / 1000) + leewaySeconds\n\t\t)\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 for `aud` signed by the active account, minting (and caching) a fresh one if needed. Coalesces concurrent calls per account + aud. */\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\tconst pendingApiKeys = new Map<string, Promise<string>>()\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: async ({ aud, expIn, store = defaultStore, leewaySeconds = 60 }) => {\n\t\t\tconst provider = requireProvider()\n\t\t\tconst account = await provider.getAccount()\n\t\t\tconst cached = store.get(aud)\n\t\t\tif (cached && isApiKeyValid(cached, aud, account, leewaySeconds)) return cached\n\t\t\tconst pendingKey = JSON.stringify([account, aud])\n\t\t\tconst inFlight = pendingApiKeys.get(pendingKey)\n\t\t\tif (inFlight) return inFlight\n\t\t\tconst request = provider\n\t\t\t\t.generateApiKey({ aud, exp_in: expIn })\n\t\t\t\t.then(({ apiKey }) => {\n\t\t\t\t\tstore.set(apiKey, aud)\n\t\t\t\t\treturn apiKey\n\t\t\t\t})\n\t\t\t\t.finally(() => {\n\t\t\t\t\tpendingApiKeys.delete(pendingKey)\n\t\t\t\t})\n\t\t\tpendingApiKeys.set(pendingKey, request)\n\t\t\treturn request\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":";;;;;;;;;;;;;;;;AA+BA,SAAS,oBAAiC;CACzC,MAAM,4BAAY,IAAI,IAAoB;CAC1C,OAAO;EACN,MAAM,MAAM,OAAO,UAAU,IAAI,GAAG,KAAK;EACzC,MAAM,QAAQ,MAAM,OAAO;GAC1B,UAAU,IAAI,KAAK,MAAM;EAC1B;CACD;AACD;AAEA,SAAS,cACR,QACA,KACA,SACA,eACU;CACV,IAAI;EACH,MAAM,EAAE,SAAS,YAAY,aAAa,MAAM;EAChD,OACC,YAAY,WACZ,QAAQ,QAAQ,OAChB,QAAQ,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,IAAI;CAEhD,QAAQ;EACP,OAAO;CACR;AACD;;;;;AAsCA,SAAgB,2BAA2B,kBAAkD;CAC5F,MAAM,oBAAoB,oBAAoB,mBAAmB;CACjE,MAAM,wBAAyC;EAC9C,MAAM,WAAW,YAAY;EAC7B,IAAI,CAAC,UACJ,MAAM,IAAI,eAAe,oBAAoB,iCAAiC;EAC/E,OAAO;CACR;CAEA,MAAM,eAAe,kBAAkB;CACvC,MAAM,iCAAiB,IAAI,IAA6B;CAExD,OAAO;EACN,mBAAmB,YAAY,MAAM;EACrC;EACA,SAAS,YAAY;GACpB,MAAM,WAAW,MAAM,gBAAgB,CAAC,CAAC,gBAAgB;GACzD,IAAI,CAAC,SAAS,QACb,MAAM,IAAI,eAAe,oBAAoB,qBAAqB;GACnE,OAAO,SAAS;EACjB;EACA,kBAAkB,gBAAgB,CAAC,CAAC,WAAW;EAC/C,kBAAkB,gBAAgB,CAAC,CAAC,WAAW;EAC/C,eAAe,OAAO,WAAW;GAChC,MAAM,WAAW,gBAAgB;GACjC,IAAI,OAAO,SAAS,yBAAyB,YAC5C,MAAM,IAAI,eAAe,eAAe,uCAAuC;GAChF,OAAO,SAAS,qBAAqB,MAAM;EAC5C;EACA,kBAAkB,YAAY,gBAAgB,CAAC,CAAC,gBAAgB,OAAO;EACvE,eAAe,OAAO,SAAS,YAAY;GAC1C,MAAM,EAAE,QAAQ,aAAa,MAAM,gBAAgB,CAAC,CAAC,gBAAgB,OAAO;GAK5E,OAAO;IAAE;IAAQ,WAAA,MAJO,kBAAkB,UAAU;KACnD,SAAS,QAAQ;KACjB,MAAM,QAAQ;IACf,CAAC;GAC0B;EAC5B;EACA,cAAc,OAAO,EAAE,KAAK,OAAO,QAAQ,cAAc,gBAAgB,SAAS;GACjF,MAAM,WAAW,gBAAgB;GACjC,MAAM,UAAU,MAAM,SAAS,WAAW;GAC1C,MAAM,SAAS,MAAM,IAAI,GAAG;GAC5B,IAAI,UAAU,cAAc,QAAQ,KAAK,SAAS,aAAa,GAAG,OAAO;GACzE,MAAM,aAAa,KAAK,UAAU,CAAC,SAAS,GAAG,CAAC;GAChD,MAAM,WAAW,eAAe,IAAI,UAAU;GAC9C,IAAI,UAAU,OAAO;GACrB,MAAM,UAAU,SACd,eAAe;IAAE;IAAK,QAAQ;GAAM,CAAC,CAAC,CACtC,MAAM,EAAE,aAAa;IACrB,MAAM,IAAI,QAAQ,GAAG;IACrB,OAAO;GACR,CAAC,CAAC,CACD,cAAc;IACd,eAAe,OAAO,UAAU;GACjC,CAAC;GACF,eAAe,IAAI,YAAY,OAAO;GACtC,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/constants.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ declare const WALLET_WINDOW_EVENTS: {
|
|
|
75
75
|
readonly networkChanged: "amadeus-wallet#networkChanged";
|
|
76
76
|
};
|
|
77
77
|
/** Provider `.on()` event names (EIP-1193-style). */
|
|
78
|
-
declare const PROVIDER_EVENTS: readonly ["accountsChanged", "connect", "disconnect", "lock", "unlock", "networkChanged"];
|
|
78
|
+
declare const PROVIDER_EVENTS: readonly ["accountsChanged", "connect", "disconnect", "lock", "unlock", "networkChanged", "shown"];
|
|
79
79
|
/** The valid networks the wallet exposes. */
|
|
80
80
|
declare const NETWORKS: readonly ["mainnet", "testnet", "custom"];
|
|
81
81
|
/**
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","names":[],"sources":["../src/constants.ts"],"mappings":";;;;;;;;;;;;cAaa;;;;;;;cAQA;;;;;;cAOA;;;;;;;;cASA;;cAGA;cACA;cACA;;;;;;;cAQA;;;;;;cAOA;;cAGA;cACA;cACA;;cAGA;;cAGA;;cAGA;;;;;;cAOA;;cAGA;;;;;;;;;cAUA;;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","names":[],"sources":["../src/constants.ts"],"mappings":";;;;;;;;;;;;cAaa;;;;;;;cAQA;;;;;;cAOA;;;;;;;;cASA;;cAGA;cACA;cACA;;;;;;;cAQA;;;;;;cAOA;;cAGA;cACA;cACA;;cAGA;;cAGA;;cAGA;;;;;;cAOA;;cAGA;;;;;;;;;cAUA;;cAWA;;;;;;cAOA"}
|
package/dist/constants.js
CHANGED
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["/**\n * Protocol constants for the Amadeus dApp <-> wallet connection layer.\n *\n * The Domain Separation Tags (DSTs) below are the single most safety-critical\n * values in this package. A signature made under one DST can NEVER verify under\n * another (BLS hash-to-curve mixes the DST into the point), which is exactly how\n * we guarantee an auth signature can never be replayed as a transaction, and\n * vice-versa. Two of these (`TX`, `APIKEY`) already exist in production — in\n * `@amadeus-protocol/sdk` and in the wallet extension respectively — and MUST\n * stay byte-for-byte identical here or existing tokens/txs stop verifying.\n */\n\n/** Transactions. Owned by `@amadeus-protocol/sdk` (`signing.ts`). Do not change. */\nexport const TX_DST = 'AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_TX_'\n\n/**\n * KBS bearer / API-key tokens. Currently hand-rolled identically in the wallet\n * extension (`background/handlers/api-key.ts`) and in hub/prime-hub\n * (`utils/blsWallet.ts`). This package is the one audited home for it. Do not\n * change — `kbs.ama.one` verifies against this exact tag.\n */\nexport const API_KEY_DST = 'AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_APIKEY_'\n\n/**\n * Connection-auth transcript signatures. NEW in this package — nothing verified\n * it before, so there is no backward-compat constraint. Deliberately distinct\n * from every other DST so a connect proof is unusable anywhere else.\n */\nexport const CONNECT_DST = 'AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_CONNECT_'\n\n/**\n * Arbitrary-message (\"personal sign\") signatures. NEW in this package — no prior\n * verifier, so no backward-compat constraint. Its distinct DST is the safety\n * guarantee: a message signed here can NEVER verify as a transaction (`TX_DST`),\n * an API key (`API_KEY_DST`), or a connect proof, so a dApp can't trick a user\n * into blind-signing a payload that is secretly valid under another protocol.\n */\nexport const MESSAGE_DST = 'AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_MSG_'\n\n/** Byte lengths of the Amadeus BLS12-381 \"long-signature\" variant (G1 pk / G2 sig). */\nexport const PUBLIC_KEY_BYTE_LENGTH = 48\nexport const SIGNATURE_BYTE_LENGTH = 96\nexport const SEED_BYTE_LENGTH = 64\n\n/**\n * Hard cap on the length of an api-key string accepted for decoding. A genuine\n * token is ~260 chars; this bounds untrusted input BEFORE the (quadratic) Base58\n * decode so a huge string can't stall the verifier's event loop. Generous enough\n * for a multi-hundred-char audience claim.\n */\nexport const MAX_API_KEY_STRING_LENGTH = 1024\n\n/**\n * Hard cap on a to-be-signed message (UTF-8 chars). Bounds untrusted input shown\n * in the approval UI and hashed for signing; generous enough for SIWE-style\n * multi-line login messages while refusing a megabyte blob.\n */\nexport const MAX_MESSAGE_LENGTH = 4096\n\n/** x25519 / xchacha20-poly1305 session-box parameters. */\nexport const SESSION_PUBLIC_KEY_BYTE_LENGTH = 32\nexport const SESSION_SECRET_KEY_BYTE_LENGTH = 32\nexport const SESSION_NONCE_BYTE_LENGTH = 24\n\n/** Wire protocol version. Absent in the extension today; new requests carry it. */\nexport const PROTOCOL_VERSION = 1\n\n/** Label mixed into the connect transcript so its bytes are unambiguous. */\nexport const CONNECT_TRANSCRIPT_LABEL = 'amadeus-connect/v1'\n\n/** The injected-provider global name and feature-detect flag. */\nexport const PROVIDER_GLOBAL = 'amadeus'\n\n/**\n * The canonical wallet-ready window event. NOTE: several dApps historically\n * listened for the WRONG name `amadeus#initialized`; the real one the extension\n * dispatches is `amadeus-wallet#initialized`. Consumers should use this constant.\n */\nexport const WALLET_INITIALIZED_EVENT = 'amadeus-wallet#initialized'\n\n/** All window CustomEvents the wallet dispatches on the page. */\nexport const WALLET_WINDOW_EVENTS = {\n\tinitialized: 'amadeus-wallet#initialized',\n\tconnected: 'amadeus-wallet#connected',\n\tdisconnected: 'amadeus-wallet#disconnected',\n\tlocked: 'amadeus-wallet#locked',\n\tunlocked: 'amadeus-wallet#unlocked',\n\tnetworkChanged: 'amadeus-wallet#networkChanged'\n} as const\n\n/** Provider `.on()` event names (EIP-1193-style). */\nexport const PROVIDER_EVENTS = [\n\t'accountsChanged',\n\t'connect',\n\t'disconnect',\n\t'lock',\n\t'unlock',\n\t'networkChanged'\n] as const\n\n/** The valid networks the wallet exposes. */\nexport const NETWORKS = ['mainnet', 'testnet', 'custom'] as const\n\n/**\n * Default cross-device relay (\"bridge\") URL. dApps that don't pass their own\n * `bridgeUrl` to `createConnectRequest` fall back to this. Must be https (the\n * wallet rejects non-https bridge URLs via `assertAllowedBridgeUrl`).\n */\nexport const DEFAULT_BRIDGE_URL = 'https://bridge.ama.one'\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,SAAS;;;;;;;AAQtB,MAAa,cAAc;;;;;;AAO3B,MAAa,cAAc;;;;;;;;AAS3B,MAAa,cAAc;;AAG3B,MAAa,yBAAyB;AACtC,MAAa,wBAAwB;AACrC,MAAa,mBAAmB;;;;;;;AAQhC,MAAa,4BAA4B;;;;;;AAOzC,MAAa,qBAAqB;;AAGlC,MAAa,iCAAiC;AAC9C,MAAa,iCAAiC;AAC9C,MAAa,4BAA4B;;AAGzC,MAAa,mBAAmB;;AAGhC,MAAa,2BAA2B;;AAGxC,MAAa,kBAAkB;;;;;;AAO/B,MAAa,2BAA2B;;AAGxC,MAAa,uBAAuB;CACnC,aAAa;CACb,WAAW;CACX,cAAc;CACd,QAAQ;CACR,UAAU;CACV,gBAAgB;AACjB;;AAGA,MAAa,kBAAkB;CAC9B;CACA;CACA;CACA;CACA;CACA;AACD;;AAGA,MAAa,WAAW;CAAC;CAAW;CAAW;AAAQ;;;;;;AAOvD,MAAa,qBAAqB"}
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["/**\n * Protocol constants for the Amadeus dApp <-> wallet connection layer.\n *\n * The Domain Separation Tags (DSTs) below are the single most safety-critical\n * values in this package. A signature made under one DST can NEVER verify under\n * another (BLS hash-to-curve mixes the DST into the point), which is exactly how\n * we guarantee an auth signature can never be replayed as a transaction, and\n * vice-versa. Two of these (`TX`, `APIKEY`) already exist in production — in\n * `@amadeus-protocol/sdk` and in the wallet extension respectively — and MUST\n * stay byte-for-byte identical here or existing tokens/txs stop verifying.\n */\n\n/** Transactions. Owned by `@amadeus-protocol/sdk` (`signing.ts`). Do not change. */\nexport const TX_DST = 'AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_TX_'\n\n/**\n * KBS bearer / API-key tokens. Currently hand-rolled identically in the wallet\n * extension (`background/handlers/api-key.ts`) and in hub/prime-hub\n * (`utils/blsWallet.ts`). This package is the one audited home for it. Do not\n * change — `kbs.ama.one` verifies against this exact tag.\n */\nexport const API_KEY_DST = 'AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_APIKEY_'\n\n/**\n * Connection-auth transcript signatures. NEW in this package — nothing verified\n * it before, so there is no backward-compat constraint. Deliberately distinct\n * from every other DST so a connect proof is unusable anywhere else.\n */\nexport const CONNECT_DST = 'AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_CONNECT_'\n\n/**\n * Arbitrary-message (\"personal sign\") signatures. NEW in this package — no prior\n * verifier, so no backward-compat constraint. Its distinct DST is the safety\n * guarantee: a message signed here can NEVER verify as a transaction (`TX_DST`),\n * an API key (`API_KEY_DST`), or a connect proof, so a dApp can't trick a user\n * into blind-signing a payload that is secretly valid under another protocol.\n */\nexport const MESSAGE_DST = 'AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_MSG_'\n\n/** Byte lengths of the Amadeus BLS12-381 \"long-signature\" variant (G1 pk / G2 sig). */\nexport const PUBLIC_KEY_BYTE_LENGTH = 48\nexport const SIGNATURE_BYTE_LENGTH = 96\nexport const SEED_BYTE_LENGTH = 64\n\n/**\n * Hard cap on the length of an api-key string accepted for decoding. A genuine\n * token is ~260 chars; this bounds untrusted input BEFORE the (quadratic) Base58\n * decode so a huge string can't stall the verifier's event loop. Generous enough\n * for a multi-hundred-char audience claim.\n */\nexport const MAX_API_KEY_STRING_LENGTH = 1024\n\n/**\n * Hard cap on a to-be-signed message (UTF-8 chars). Bounds untrusted input shown\n * in the approval UI and hashed for signing; generous enough for SIWE-style\n * multi-line login messages while refusing a megabyte blob.\n */\nexport const MAX_MESSAGE_LENGTH = 4096\n\n/** x25519 / xchacha20-poly1305 session-box parameters. */\nexport const SESSION_PUBLIC_KEY_BYTE_LENGTH = 32\nexport const SESSION_SECRET_KEY_BYTE_LENGTH = 32\nexport const SESSION_NONCE_BYTE_LENGTH = 24\n\n/** Wire protocol version. Absent in the extension today; new requests carry it. */\nexport const PROTOCOL_VERSION = 1\n\n/** Label mixed into the connect transcript so its bytes are unambiguous. */\nexport const CONNECT_TRANSCRIPT_LABEL = 'amadeus-connect/v1'\n\n/** The injected-provider global name and feature-detect flag. */\nexport const PROVIDER_GLOBAL = 'amadeus'\n\n/**\n * The canonical wallet-ready window event. NOTE: several dApps historically\n * listened for the WRONG name `amadeus#initialized`; the real one the extension\n * dispatches is `amadeus-wallet#initialized`. Consumers should use this constant.\n */\nexport const WALLET_INITIALIZED_EVENT = 'amadeus-wallet#initialized'\n\n/** All window CustomEvents the wallet dispatches on the page. */\nexport const WALLET_WINDOW_EVENTS = {\n\tinitialized: 'amadeus-wallet#initialized',\n\tconnected: 'amadeus-wallet#connected',\n\tdisconnected: 'amadeus-wallet#disconnected',\n\tlocked: 'amadeus-wallet#locked',\n\tunlocked: 'amadeus-wallet#unlocked',\n\tnetworkChanged: 'amadeus-wallet#networkChanged'\n} as const\n\n/** Provider `.on()` event names (EIP-1193-style). */\nexport const PROVIDER_EVENTS = [\n\t'accountsChanged',\n\t'connect',\n\t'disconnect',\n\t'lock',\n\t'unlock',\n\t'networkChanged',\n\t'shown'\n] as const\n\n/** The valid networks the wallet exposes. */\nexport const NETWORKS = ['mainnet', 'testnet', 'custom'] as const\n\n/**\n * Default cross-device relay (\"bridge\") URL. dApps that don't pass their own\n * `bridgeUrl` to `createConnectRequest` fall back to this. Must be https (the\n * wallet rejects non-https bridge URLs via `assertAllowedBridgeUrl`).\n */\nexport const DEFAULT_BRIDGE_URL = 'https://bridge.ama.one'\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,SAAS;;;;;;;AAQtB,MAAa,cAAc;;;;;;AAO3B,MAAa,cAAc;;;;;;;;AAS3B,MAAa,cAAc;;AAG3B,MAAa,yBAAyB;AACtC,MAAa,wBAAwB;AACrC,MAAa,mBAAmB;;;;;;;AAQhC,MAAa,4BAA4B;;;;;;AAOzC,MAAa,qBAAqB;;AAGlC,MAAa,iCAAiC;AAC9C,MAAa,iCAAiC;AAC9C,MAAa,4BAA4B;;AAGzC,MAAa,mBAAmB;;AAGhC,MAAa,2BAA2B;;AAGxC,MAAa,kBAAkB;;;;;;AAO/B,MAAa,2BAA2B;;AAGxC,MAAa,uBAAuB;CACnC,aAAa;CACb,WAAW;CACX,cAAc;CACd,QAAQ;CACR,UAAU;CACV,gBAAgB;AACjB;;AAGA,MAAa,kBAAkB;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;AACD;;AAGA,MAAa,WAAW;CAAC;CAAW;CAAW;AAAQ;;;;;;AAOvD,MAAa,qBAAqB"}
|
package/dist/crypto/box.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../constants.js";
|
|
2
|
-
import { WalletSdkError } from "../errors.js";
|
|
3
2
|
import { randomBytes } from "../bytes.js";
|
|
3
|
+
import { WalletSdkError } from "../errors.js";
|
|
4
4
|
import { fromBase58, toBase58 } from "@amadeus-protocol/sdk";
|
|
5
5
|
import { sha256 } from "@noble/hashes/sha2";
|
|
6
6
|
import { xchacha20poly1305 } from "@noble/ciphers/chacha.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { WalletSdkError, WalletSdkErrorCode } from "./errors.js";
|
|
|
3
3
|
import { bytesToUtf8, concatBytes, equalBytes, randomBytes, randomId, u32be, utf8ToBytes } from "./bytes.js";
|
|
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
|
-
import { AmadeusEventPayloadMap, AmadeusNetwork, AmadeusProvider, AmadeusProviderEvent, GenerateApiKeyRequest, GenerateApiKeyResponse, SignTransactionRequest, SignTransactionResponse, getAmadeusProvider, isProviderAvailable } from "./types.js";
|
|
6
|
+
import { AmadeusEventPayloadMap, AmadeusEventTimestamp, AmadeusNetwork, AmadeusProvider, AmadeusProviderEvent, AmadeusShownAs, GenerateApiKeyRequest, GenerateApiKeyResponse, PendingRequestSummary, SignTransactionRequest, SignTransactionResponse, getAmadeusProvider, isProviderAvailable } from "./types.js";
|
|
7
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";
|
|
@@ -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, 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 };
|
|
19
|
+
export { API_KEY_DST, AmadeusEventPayloadMap, AmadeusEventTimestamp, AmadeusNetwork, AmadeusProvider, AmadeusProviderEvent, AmadeusShownAs, 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, PendingRequestSummary, 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/react/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SignTransactionRequest, SignTransactionResponse } from "../types.js";
|
|
2
1
|
import { WalletClient } from "../client/injected.js";
|
|
2
|
+
import { SignTransactionRequest, SignTransactionResponse } from "../types.js";
|
|
3
3
|
type WalletStatus = 'unavailable' | 'disconnected' | 'connecting' | 'connected';
|
|
4
4
|
interface UseWalletResult {
|
|
5
5
|
client: WalletClient;
|
package/dist/react/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { WALLET_INITIALIZED_EVENT } from "../constants.js";
|
|
2
1
|
import { createInjectedWalletClient } from "../client/injected.js";
|
|
2
|
+
import { WALLET_INITIALIZED_EVENT } from "../constants.js";
|
|
3
3
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
4
4
|
// src/react/index.ts
|
|
5
5
|
/**
|
|
@@ -43,7 +43,7 @@ function useWallet() {
|
|
|
43
43
|
const onAccountsChanged = (d) => applyAccounts(d.accounts);
|
|
44
44
|
const onConnect = (d) => {
|
|
45
45
|
applyAccounts(d.accounts);
|
|
46
|
-
setNetwork(d.network);
|
|
46
|
+
if (d.network) setNetwork(d.network);
|
|
47
47
|
};
|
|
48
48
|
const onDisconnect = () => {
|
|
49
49
|
setAccount(null);
|
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\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\
|
|
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\t// Extension 1.9.2 always sends a network here; other providers may omit it, so keep the last value.\n\t\t\tif (d.network) setNetwork(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,iBAAiB,0BAA0B,MAAM;EACxD,IAAI,OAAO,YAAY,GAAG;GACzB,OACE,WAAW,CAAC,CACZ,MAAM,MAAM;IACZ,IAAI,GAAG;KACN,WAAW,CAAC;KACZ,UAAU,WAAW;IACtB;GACD,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;GAChB,OACE,WAAW,CAAC,CACZ,KAAK,UAAU,CAAC,CAChB,YAAY,CAAC,CAAC;EACjB;EACA,aAAa,OAAO,oBAAoB,0BAA0B,MAAM;CACzE,GAAG,CAAC,MAAM,CAAC;CAGX,gBAAgB;EACf,IAAI,CAAC,OAAO,YAAY,GAAG;EAC3B,MAAM,iBAAiB,aAAuB;GAC7C,MAAM,OAAO,SAAS,MAAM;GAC5B,WAAW,IAAI;GACf,UAAU,OAAO,cAAc,cAAc;EAC9C;EACA,MAAM,qBAAqB,MAC1B,cAAc,EAAE,QAAQ;EACzB,MAAM,aAAa,MAAyC;GAC3D,cAAc,EAAE,QAAQ;GAExB,IAAI,EAAE,SAAS,WAAW,EAAE,OAAO;EACpC;EACA,MAAM,qBAAqB;GAC1B,WAAW,IAAI;GACf,UAAU,cAAc;EACzB;EACA,MAAM,oBAAoB,MACzB,WAAW,EAAE,OAAO;EAErB,OAAO,GAAG,mBAAmB,iBAAiB;EAC9C,OAAO,GAAG,WAAW,SAAS;EAC9B,OAAO,GAAG,cAAc,YAAY;EACpC,OAAO,GAAG,kBAAkB,gBAAgB;EAC5C,aAAa;GACZ,OAAO,IAAI,mBAAmB,iBAAiB;GAC/C,OAAO,IAAI,WAAW,SAAS;GAC/B,OAAO,IAAI,cAAc,YAAY;GACrC,OAAO,IAAI,kBAAkB,gBAAgB;EAC9C;CACD,GAAG,CAAC,MAAM,CAAC;CAEX,MAAM,UAAU,YAAY,YAAY;EACvC,UAAU,YAAY;EACtB,IAAI;GACH,MAAM,IAAI,MAAM,OAAO,QAAQ;GAC/B,WAAW,CAAC;GACZ,UAAU,WAAW;EACtB,SAAS,OAAO;GACf,UAAU,OAAO,YAAY,IAAI,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/transport/bridge.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { WalletSdkError } from "../errors.js";
|
|
2
1
|
import { concatBytes, utf8ToBytes } from "../bytes.js";
|
|
2
|
+
import { WalletSdkError } from "../errors.js";
|
|
3
3
|
import { fromBase58, toBase58 } from "@amadeus-protocol/sdk";
|
|
4
4
|
import { sha256 } from "@noble/hashes/sha2";
|
|
5
5
|
// src/transport/bridge.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "../constants.js";
|
|
2
|
-
import { WalletSdkError } from "../errors.js";
|
|
3
2
|
import { bytesToUtf8, utf8ToBytes } from "../bytes.js";
|
|
4
3
|
import { open, seal } from "../crypto/box.js";
|
|
4
|
+
import { WalletSdkError } from "../errors.js";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
// src/transport/envelope.ts
|
|
7
7
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "../constants.js";
|
|
2
|
-
import { WalletSdkError } from "../errors.js";
|
|
3
2
|
import { randomBytes, randomId } from "../bytes.js";
|
|
4
3
|
import { signConnect, verifyConnect } from "../crypto/connect.js";
|
|
5
4
|
import { deriveSharedKey, generateSessionKeypair } from "../crypto/box.js";
|
|
5
|
+
import { WalletSdkError } from "../errors.js";
|
|
6
6
|
import { buildConnectUri } from "./uri.js";
|
|
7
7
|
import { toBase58 } from "@amadeus-protocol/sdk";
|
|
8
8
|
// src/transport/session.ts
|
package/dist/tx.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -20,36 +20,53 @@ interface GenerateApiKeyRequest {
|
|
|
20
20
|
interface GenerateApiKeyResponse {
|
|
21
21
|
apiKey: string;
|
|
22
22
|
}
|
|
23
|
+
/** ISO 8601 string (`new Date().toISOString()`), as the extension emits it. */
|
|
24
|
+
type AmadeusEventTimestamp = string;
|
|
25
|
+
/** How the wallet surfaced an approval prompt. */
|
|
26
|
+
type AmadeusShownAs = 'sidepanel' | 'popup' | 'window';
|
|
23
27
|
/** Event payloads emitted through the provider's `.on(name, cb)` channel. */
|
|
24
28
|
interface AmadeusEventPayloadMap {
|
|
25
29
|
accountsChanged: {
|
|
26
30
|
accounts: string[];
|
|
27
31
|
previousAccounts: string[];
|
|
28
|
-
timestamp:
|
|
32
|
+
timestamp: AmadeusEventTimestamp;
|
|
29
33
|
};
|
|
30
34
|
connect: {
|
|
31
35
|
accounts: string[];
|
|
32
36
|
network: string;
|
|
33
|
-
timestamp:
|
|
37
|
+
timestamp: AmadeusEventTimestamp;
|
|
34
38
|
};
|
|
35
39
|
disconnect: {
|
|
36
40
|
reason?: string;
|
|
37
|
-
timestamp:
|
|
41
|
+
timestamp: AmadeusEventTimestamp;
|
|
38
42
|
};
|
|
39
43
|
lock: {
|
|
40
44
|
reason?: string;
|
|
41
|
-
timestamp:
|
|
45
|
+
timestamp: AmadeusEventTimestamp;
|
|
42
46
|
};
|
|
43
47
|
unlock: {
|
|
44
48
|
accounts: string[];
|
|
45
49
|
network: string;
|
|
46
|
-
timestamp:
|
|
50
|
+
timestamp: AmadeusEventTimestamp;
|
|
47
51
|
};
|
|
48
52
|
networkChanged: {
|
|
49
53
|
network: string;
|
|
50
54
|
previousNetwork: string;
|
|
51
|
-
timestamp:
|
|
55
|
+
timestamp: AmadeusEventTimestamp;
|
|
52
56
|
};
|
|
57
|
+
/** A signTransaction approval prompt was surfaced; the sign promise still settles later. */
|
|
58
|
+
shown: {
|
|
59
|
+
requestId: string;
|
|
60
|
+
shownAs: AmadeusShownAs;
|
|
61
|
+
timestamp: AmadeusEventTimestamp;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** One of this origin's queued wallet requests, as returned by `getPendingRequests()`. */
|
|
65
|
+
interface PendingRequestSummary {
|
|
66
|
+
type: 'sign' | 'apiKey' | 'switchNetwork' | 'switchAccount' | 'connection';
|
|
67
|
+
id: string;
|
|
68
|
+
/** Milliseconds since epoch when the wallet queued the request. */
|
|
69
|
+
timestamp: number;
|
|
53
70
|
}
|
|
54
71
|
/**
|
|
55
72
|
* The injected provider interface. This is the object a dApp reads off
|
|
@@ -70,6 +87,10 @@ interface AmadeusProvider {
|
|
|
70
87
|
* predate it lack the method.
|
|
71
88
|
*/
|
|
72
89
|
requestSwitchAccount?(target?: string): Promise<string>;
|
|
90
|
+
/** This origin's queued requests, oldest first. Optional: extension >= 1.6.0. */
|
|
91
|
+
getPendingRequests?(): Promise<PendingRequestSummary[]>;
|
|
92
|
+
/** Cancel one of this origin's own pending requests. Optional: extension >= 1.6.0. */
|
|
93
|
+
cancelRequest?(requestId: string): void;
|
|
73
94
|
signTransaction(params: SignTransactionRequest): Promise<SignTransactionResponse>;
|
|
74
95
|
generateApiKey(params: GenerateApiKeyRequest): Promise<GenerateApiKeyResponse>;
|
|
75
96
|
on<E extends AmadeusProviderEvent>(event: E, callback: (data: AmadeusEventPayloadMap[E]) => void): void;
|
|
@@ -82,5 +103,5 @@ declare global {
|
|
|
82
103
|
declare function getAmadeusProvider(): AmadeusProvider | null;
|
|
83
104
|
/** Whether a genuine Amadeus provider is currently injected. */
|
|
84
105
|
declare function isProviderAvailable(): boolean;
|
|
85
|
-
export { AmadeusEventPayloadMap, AmadeusNetwork, AmadeusProvider, AmadeusProviderEvent, GenerateApiKeyRequest, GenerateApiKeyResponse, SignTransactionRequest, SignTransactionResponse, getAmadeusProvider, isProviderAvailable };
|
|
106
|
+
export { AmadeusEventPayloadMap, AmadeusEventTimestamp, AmadeusNetwork, AmadeusProvider, AmadeusProviderEvent, AmadeusShownAs, GenerateApiKeyRequest, GenerateApiKeyResponse, PendingRequestSummary, SignTransactionRequest, SignTransactionResponse, getAmadeusProvider, isProviderAvailable };
|
|
86
107
|
//# sourceMappingURL=types.d.ts.map
|
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;;;
|
|
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;;;KAIW;;KAGA;;UAGK;EAChB;IACC;IACA;IACA,WAAW;;EAEZ;IAAW;IAAoB;IAAiB,WAAW;;EAC3D;IAAc;IAAiB,WAAW;;EAC1C;IAAQ;IAAiB,WAAW;;EACpC;IAAU;IAAoB;IAAiB,WAAW;;EAC1D;IACC;IACA;IACA,WAAW;;;EAGZ;IAAS;IAAmB,SAAS;IAAgB,WAAW;;;;UAIhD;EAChB;EACA;;EAEA;;;;;;UAOgB;WACP;EACT,eAAe;EACf,cAAc;EACd,cAAc;EACd,mBAAmB;EACnB,qBAAqB,kBAAkB;;;;;;;;EAQvC,sBAAsB,kBAAkB;;EAExC,uBAAuB,QAAQ;;EAE/B,eAAe;EACf,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: {
|
|
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/** ISO 8601 string (`new Date().toISOString()`), as the extension emits it. */\nexport type AmadeusEventTimestamp = string\n\n/** How the wallet surfaced an approval prompt. */\nexport type AmadeusShownAs = 'sidepanel' | 'popup' | 'window'\n\n/** Event payloads emitted through the provider's `.on(name, cb)` channel. */\nexport interface AmadeusEventPayloadMap {\n\taccountsChanged: {\n\t\taccounts: string[]\n\t\tpreviousAccounts: string[]\n\t\ttimestamp: AmadeusEventTimestamp\n\t}\n\tconnect: { accounts: string[]; network: string; timestamp: AmadeusEventTimestamp }\n\tdisconnect: { reason?: string; timestamp: AmadeusEventTimestamp }\n\tlock: { reason?: string; timestamp: AmadeusEventTimestamp }\n\tunlock: { accounts: string[]; network: string; timestamp: AmadeusEventTimestamp }\n\tnetworkChanged: {\n\t\tnetwork: string\n\t\tpreviousNetwork: string\n\t\ttimestamp: AmadeusEventTimestamp\n\t}\n\t/** A signTransaction approval prompt was surfaced; the sign promise still settles later. */\n\tshown: { requestId: string; shownAs: AmadeusShownAs; timestamp: AmadeusEventTimestamp }\n}\n\n/** One of this origin's queued wallet requests, as returned by `getPendingRequests()`. */\nexport interface PendingRequestSummary {\n\ttype: 'sign' | 'apiKey' | 'switchNetwork' | 'switchAccount' | 'connection'\n\tid: string\n\t/** Milliseconds since epoch when the wallet queued the request. */\n\ttimestamp: 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\t/** This origin's queued requests, oldest first. Optional: extension >= 1.6.0. */\n\tgetPendingRequests?(): Promise<PendingRequestSummary[]>\n\t/** Cancel one of this origin's own pending requests. Optional: extension >= 1.6.0. */\n\tcancelRequest?(requestId: string): void\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":";;AA+GA,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.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "../constants.js";
|
|
2
|
-
import { WalletSdkError } from "../errors.js";
|
|
3
|
-
import { signTransaction } from "../tx.js";
|
|
4
|
-
import { generateApiKeyRequestSchema, signMessageRequestSchema, signTransactionRequestSchema } from "../schema.js";
|
|
5
2
|
import { generateApiKey } from "../crypto/apikey.js";
|
|
6
3
|
import { signMessage } from "../crypto/message.js";
|
|
4
|
+
import { WalletSdkError } from "../errors.js";
|
|
5
|
+
import { generateApiKeyRequestSchema, signMessageRequestSchema, signTransactionRequestSchema } from "../schema.js";
|
|
6
|
+
import { signTransaction } from "../tx.js";
|
|
7
7
|
// src/wallet/handler.ts
|
|
8
8
|
function ok(id, result) {
|
|
9
9
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amadeus-protocol/wallet-sdk",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
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,
|