@droplinked_inc/wallet-connection 0.1.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.
@@ -0,0 +1,340 @@
1
+ /**
2
+ * Phantom (Solana) connector.
3
+ *
4
+ * Hardening deltas vs. v1.0.1:
5
+ * 1. No `window.open('https://phantom.app/', '_blank')` redirect — the
6
+ * original silently popped a new tab when Phantom was missing, which
7
+ * is a phishing-friendly UX. We throw a typed error and let the host
8
+ * app decide what to render.
9
+ * 2. No `while(true) { sleep; getParsedTransaction }` busy-loop — the
10
+ * original could hang a tab forever if the network stalled. We
11
+ * surface the unsigned-transaction hash and let the caller poll.
12
+ * 3. No `console.log(error); throw error` — errors propagate without
13
+ * leaking through stdout.
14
+ * 4. Signature buffer is returned as base64 rather than the raw
15
+ * Uint8Array — same format as MetaMask EIP-712 output so server
16
+ * verification is uniform.
17
+ * 5. Login signs a SIWS-style (Sign-In With Solana, https://siws.xyz/)
18
+ * JSON payload with domain, nonce, chainId, issuedAt,
19
+ * expirationTime — NOT a static plaintext. The signature is
20
+ * bound to origin + chain + time and cannot be replayed across
21
+ * sites or sessions. Verification is provided alongside.
22
+ */
23
+ import { z } from 'zod';
24
+ import * as ed25519 from '@noble/ed25519';
25
+ import { Chain, ChainWallet, Network } from '../types.js';
26
+ import { InvalidSignatureError, OriginMismatchError, SignaturePayloadInvalidError, WalletNotFoundException, } from '../errors.js';
27
+ function requirePhantom() {
28
+ const g = globalThis;
29
+ if (g.solana === undefined || g.solana.isPhantom !== true) {
30
+ throw new WalletNotFoundException('Phantom wallet not found. Install Phantom from https://phantom.app/ and reload.');
31
+ }
32
+ // LOW-1: When `window.phantom.solana` is set, cross-check that the
33
+ // injected `window.solana` is the same surface. This stops a wallet
34
+ // that sets `isPhantom: true` on its own `window.solana` injection
35
+ // from impersonating Phantom in the presence of the canonical
36
+ // `window.phantom` namespace.
37
+ if (g.phantom?.solana !== undefined && g.phantom.solana !== g.solana) {
38
+ throw new WalletNotFoundException('window.solana and window.phantom.solana differ — possible Phantom impersonation');
39
+ }
40
+ return g.solana;
41
+ }
42
+ /* -------------------------------------------------------------------------- */
43
+ /* SIWS-style login payload (CRITICAL-2 mitigation) */
44
+ /* -------------------------------------------------------------------------- */
45
+ /**
46
+ * Default human-readable statement embedded in the signed payload so
47
+ * Phantom's prompt explains *why* the user is signing.
48
+ */
49
+ export const DEFAULT_SOLANA_LOGIN_STATEMENT = 'Sign in to droplinked. This signature does not authorize any token transfer.';
50
+ /** Allowed Solana chain identifiers; `chain` is bound into the payload. */
51
+ export const SOLANA_CHAIN_IDS = ['solana-mainnet', 'solana-devnet', 'solana-testnet'];
52
+ /** Hard upper bound on payload TTL — refused at build time. */
53
+ export const SOLANA_LOGIN_MAX_TTL_SECONDS = 15 * 60;
54
+ /** Default TTL when caller does not specify one. */
55
+ export const SOLANA_LOGIN_DEFAULT_TTL_SECONDS = 5 * 60;
56
+ export const SolanaLoginPayloadSchema = z.object({
57
+ domain: z
58
+ .string()
59
+ .min(1)
60
+ .max(253)
61
+ .regex(/^[a-z0-9.\-:]+$/iu, 'invalid domain'),
62
+ address: z.string().min(32).max(64).regex(/^[1-9A-HJ-NP-Za-km-z]+$/u, 'invalid base58 address'),
63
+ chain: z.enum(SOLANA_CHAIN_IDS),
64
+ nonce: z
65
+ .string()
66
+ .min(8)
67
+ .max(128)
68
+ .regex(/^[A-Za-z0-9_-]+$/u, 'nonce must be url-safe'),
69
+ issuedAt: z.string().datetime(),
70
+ expirationTime: z.string().datetime(),
71
+ statement: z.string().max(512),
72
+ });
73
+ /** 256-bit URL-safe nonce. */
74
+ function generateSolanaNonce() {
75
+ const c = globalThis.crypto;
76
+ if (c === undefined || typeof c.getRandomValues !== 'function') {
77
+ throw new Error('Web Crypto API unavailable; cannot generate nonce');
78
+ }
79
+ const bytes = new Uint8Array(32);
80
+ c.getRandomValues(bytes);
81
+ let bin = '';
82
+ for (let i = 0; i < bytes.length; i++) {
83
+ bin += String.fromCharCode(bytes[i]);
84
+ }
85
+ return btoa(bin).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/u, '');
86
+ }
87
+ function extractHost(origin) {
88
+ try {
89
+ return new URL(origin).host;
90
+ }
91
+ catch {
92
+ throw new SignaturePayloadInvalidError(`invalid origin: ${origin}`);
93
+ }
94
+ }
95
+ /**
96
+ * Build a SIWS-style login payload binding the signature to
97
+ * (domain, chain, nonce, issuedAt, expirationTime). Refuses any TTL
98
+ * over `SOLANA_LOGIN_MAX_TTL_SECONDS`.
99
+ */
100
+ export function buildSolanaLoginPayload(args) {
101
+ const ttl = args.expiresInSeconds ?? SOLANA_LOGIN_DEFAULT_TTL_SECONDS;
102
+ if (ttl <= 0 || ttl > SOLANA_LOGIN_MAX_TTL_SECONDS) {
103
+ throw new SignaturePayloadInvalidError(`expiresInSeconds must be in (0, ${SOLANA_LOGIN_MAX_TTL_SECONDS}]; got ${ttl}`);
104
+ }
105
+ const issuedAt = new Date().toISOString();
106
+ const expirationTime = new Date(Date.now() + ttl * 1000).toISOString();
107
+ const payload = {
108
+ domain: extractHost(args.origin),
109
+ address: args.address,
110
+ chain: args.chain,
111
+ nonce: generateSolanaNonce(),
112
+ issuedAt,
113
+ expirationTime,
114
+ statement: args.statement ?? DEFAULT_SOLANA_LOGIN_STATEMENT,
115
+ };
116
+ const parsed = SolanaLoginPayloadSchema.safeParse(payload);
117
+ if (!parsed.success) {
118
+ throw new SignaturePayloadInvalidError(parsed.error.message);
119
+ }
120
+ return parsed.data;
121
+ }
122
+ /**
123
+ * Canonicalize the payload to a deterministic JSON string with sorted
124
+ * keys. This is what gets signed — same string on both sides of the
125
+ * verification boundary.
126
+ */
127
+ export function canonicalizeSolanaLoginPayload(payload) {
128
+ const sortedKeys = Object.keys(payload).sort();
129
+ const sorted = {};
130
+ for (const k of sortedKeys) {
131
+ sorted[k] = payload[k];
132
+ }
133
+ return JSON.stringify(sorted);
134
+ }
135
+ /* -------------------------------------------------------------------------- */
136
+ /* base58 decoder (for Solana public keys) */
137
+ /* -------------------------------------------------------------------------- */
138
+ // eslint-disable-next-line no-secrets/no-secrets -- Base58 alphabet (public constant, not a secret)
139
+ const BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
140
+ const BASE58_MAP = (() => {
141
+ const m = {};
142
+ for (let i = 0; i < BASE58_ALPHABET.length; i++) {
143
+ m[BASE58_ALPHABET[i]] = i;
144
+ }
145
+ return m;
146
+ })();
147
+ /** Decode a base58-encoded string into bytes. Throws on invalid input. */
148
+ export function base58Decode(input) {
149
+ if (input.length === 0) {
150
+ return new Uint8Array();
151
+ }
152
+ const bytes = [0];
153
+ for (const c of input) {
154
+ const v = BASE58_MAP[c];
155
+ if (v === undefined) {
156
+ throw new SignaturePayloadInvalidError(`invalid base58 character: ${c}`);
157
+ }
158
+ let carry = v;
159
+ for (let j = 0; j < bytes.length; j++) {
160
+ const x = bytes[j] * 58 + carry;
161
+ bytes[j] = x & 0xff;
162
+ carry = x >>> 8;
163
+ }
164
+ while (carry > 0) {
165
+ bytes.push(carry & 0xff);
166
+ carry >>>= 8;
167
+ }
168
+ }
169
+ // leading zeros
170
+ for (let k = 0; k < input.length && input[k] === '1'; k++) {
171
+ bytes.push(0);
172
+ }
173
+ return new Uint8Array(bytes.reverse());
174
+ }
175
+ function base64DecodeToBytes(s) {
176
+ const bin = atob(s);
177
+ const out = new Uint8Array(bin.length);
178
+ for (let i = 0; i < bin.length; i++)
179
+ out[i] = bin.charCodeAt(i);
180
+ return out;
181
+ }
182
+ /**
183
+ * Verify a Phantom (Solana) SIWS-style login signature.
184
+ *
185
+ * Checks (in order):
186
+ * 1. Payload shape validates against `SolanaLoginPayloadSchema`.
187
+ * 2. `payload.chain === expectedChain` (cross-network replay refused).
188
+ * 3. `payload.domain === host(expectedOrigin)` (origin-spoofing refused).
189
+ * 4. `payload.address === expectedAddress`.
190
+ * 5. `now < expirationTime` AND `issuedAt <= now` (freshness).
191
+ * 6. The base64 signature is a valid ed25519 signature over
192
+ * `utf8(canonicalizeSolanaLoginPayload(payload))` for the public
193
+ * key derived from `expectedAddress` (base58-decoded).
194
+ *
195
+ * Note: nonce replay tracking is the responsibility of the server-side
196
+ * caller — this function does not maintain a seen-nonces store. The
197
+ * canonical pattern is to record `(payload.nonce, payload.address)`
198
+ * in a short-lived store keyed by `expirationTime` and reject any
199
+ * second presentation.
200
+ */
201
+ export async function verifySolanaLoginSignature(args) {
202
+ const parsed = SolanaLoginPayloadSchema.safeParse(args.payload);
203
+ if (!parsed.success) {
204
+ throw new SignaturePayloadInvalidError(parsed.error.message);
205
+ }
206
+ const payload = parsed.data;
207
+ if (payload.chain !== args.expectedChain) {
208
+ throw new InvalidSignatureError(`chain mismatch: payload=${payload.chain} expected=${args.expectedChain}`);
209
+ }
210
+ const expectedHost = extractHost(args.expectedOrigin).toLowerCase();
211
+ if (payload.domain.toLowerCase() !== expectedHost) {
212
+ throw new OriginMismatchError(`origin mismatch: payload=${payload.domain} expected=${expectedHost}`);
213
+ }
214
+ if (payload.address !== args.expectedAddress) {
215
+ throw new InvalidSignatureError(`address mismatch: payload=${payload.address} expected=${args.expectedAddress}`);
216
+ }
217
+ const now = args.nowMs ?? Date.now();
218
+ const expMs = Date.parse(payload.expirationTime);
219
+ if (Number.isNaN(expMs) || expMs <= now) {
220
+ throw new InvalidSignatureError('login payload expired');
221
+ }
222
+ const issMs = Date.parse(payload.issuedAt);
223
+ if (Number.isNaN(issMs) || issMs > now + 60_000) {
224
+ // tolerate up to 60s clock skew
225
+ throw new InvalidSignatureError('login payload issuedAt is in the future');
226
+ }
227
+ const canonical = canonicalizeSolanaLoginPayload(payload);
228
+ const messageBytes = new TextEncoder().encode(canonical);
229
+ let signatureBytes;
230
+ try {
231
+ signatureBytes = base64DecodeToBytes(args.signature);
232
+ }
233
+ catch {
234
+ throw new InvalidSignatureError('signature is not valid base64');
235
+ }
236
+ if (signatureBytes.length !== 64) {
237
+ throw new InvalidSignatureError(`signature wrong length: expected 64 bytes, got ${signatureBytes.length}`);
238
+ }
239
+ const pubkeyBytes = base58Decode(args.expectedAddress);
240
+ if (pubkeyBytes.length !== 32) {
241
+ throw new SignaturePayloadInvalidError(`expected address decodes to ${pubkeyBytes.length} bytes; want 32`);
242
+ }
243
+ const ok = await ed25519.verifyAsync(signatureBytes, messageBytes, pubkeyBytes);
244
+ if (!ok) {
245
+ throw new InvalidSignatureError('signature did not verify against expected pubkey');
246
+ }
247
+ }
248
+ function resolveOrigin() {
249
+ const g = globalThis;
250
+ return g.location?.origin ?? 'https://droplinked.com';
251
+ }
252
+ function defaultChainId(network) {
253
+ return network === Network.MAINNET ? 'solana-mainnet' : 'solana-devnet';
254
+ }
255
+ export class PhantomConnector {
256
+ chain = Chain.SOLANA;
257
+ network;
258
+ address = '';
259
+ wallet = ChainWallet.PhantomWallet;
260
+ origin;
261
+ chainId;
262
+ constructor(networkOrOptions) {
263
+ if (typeof networkOrOptions === 'string') {
264
+ this.network = networkOrOptions;
265
+ this.origin = resolveOrigin();
266
+ this.chainId = defaultChainId(networkOrOptions);
267
+ }
268
+ else {
269
+ this.network = networkOrOptions.network;
270
+ this.origin = networkOrOptions.origin ?? resolveOrigin();
271
+ this.chainId = networkOrOptions.chainId ?? defaultChainId(networkOrOptions.network);
272
+ }
273
+ }
274
+ setAddress(address) {
275
+ this.address = address;
276
+ return this;
277
+ }
278
+ setWallet(wallet) {
279
+ if (wallet !== ChainWallet.PhantomWallet) {
280
+ throw new WalletNotFoundException(`PhantomConnector only supports PhantomWallet; got ${wallet}`);
281
+ }
282
+ this.wallet = wallet;
283
+ return this;
284
+ }
285
+ /**
286
+ * Connect + SIWS-style typed login. Builds a fresh payload with a
287
+ * 256-bit nonce, binds it to origin + chain + time, asks Phantom to
288
+ * sign the canonicalized JSON, and returns the payload alongside the
289
+ * base64 signature. Server-side verification uses
290
+ * `verifySolanaLoginSignature`.
291
+ *
292
+ * Replaces the v1.0.1 / pre-audit static-plaintext signMessage path,
293
+ * which was replayable across origins, chains, and sessions.
294
+ */
295
+ async walletLogin() {
296
+ const provider = requirePhantom();
297
+ const resp = await provider.connect();
298
+ const address = resp.publicKey.toString();
299
+ const payload = buildSolanaLoginPayload({
300
+ address,
301
+ chain: this.chainId,
302
+ origin: this.origin,
303
+ });
304
+ const canonical = canonicalizeSolanaLoginPayload(payload);
305
+ const encoded = new TextEncoder().encode(canonical);
306
+ const signed = await provider.signMessage(encoded, 'utf8');
307
+ this.address = address;
308
+ return {
309
+ address,
310
+ signature: toBase64(signed.signature),
311
+ payload,
312
+ };
313
+ }
314
+ /**
315
+ * SPL token transfer is intentionally not implemented in this minimal
316
+ * recover+harden. The original v1.0.1 relied on the long-deprecated
317
+ * `@solana/spl-token` v0.1.x Token-class API (removed in v0.2). Re-
318
+ * implementing it correctly against the current `@solana/spl-token` v0.4
319
+ * APIs is out of scope for the first PR; it will land in a follow-up.
320
+ *
321
+ * The method throws a typed error so consumers fail loudly rather than
322
+ * silently mis-routing a transfer.
323
+ */
324
+ paymentWithToken(_receiver, _amount, _tokenAddress) {
325
+ return Promise.reject(new Error('PhantomConnector.paymentWithToken(): SPL transfer pending. ' +
326
+ 'Tracked in follow-up; do not call in production.'));
327
+ }
328
+ payment(_data) {
329
+ return Promise.reject(new Error('PhantomConnector.payment(): Solana checkout not implemented'));
330
+ }
331
+ }
332
+ /** base64-encode a Uint8Array. Browser-safe; no Buffer dependency. */
333
+ export function toBase64(bytes) {
334
+ let bin = '';
335
+ for (let i = 0; i < bytes.length; i++) {
336
+ bin += String.fromCharCode(bytes[i]);
337
+ }
338
+ return btoa(bin);
339
+ }
340
+ //# sourceMappingURL=phantom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phantom.js","sourceRoot":"","sources":["../../src/connectors/phantom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,OAAO,MAA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AAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAW,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AACnB,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Typed error classes. All errors extend native Error so callers can use
3
+ * `instanceof` and stack traces work correctly. The original v1.0.1
4
+ * package's classes did *not* extend Error — that was a footgun that
5
+ * silently broke try/catch in framework error boundaries.
6
+ */
7
+ export declare class WalletConnectionError extends Error {
8
+ readonly name: string;
9
+ constructor(message: string);
10
+ }
11
+ export declare class WalletNotFoundException extends WalletConnectionError {
12
+ readonly name = "WalletNotFoundException";
13
+ constructor(message: string);
14
+ }
15
+ export declare class AccountChangedException extends WalletConnectionError {
16
+ readonly name = "AccountChangedException";
17
+ constructor(message: string);
18
+ }
19
+ export declare class ChainNotImplementedException extends WalletConnectionError {
20
+ readonly name = "ChainNotImplementedException";
21
+ constructor(message: string);
22
+ }
23
+ export declare class InvalidSignatureError extends WalletConnectionError {
24
+ readonly name = "InvalidSignatureError";
25
+ constructor(message: string);
26
+ }
27
+ export declare class ChainMismatchError extends WalletConnectionError {
28
+ readonly name = "ChainMismatchError";
29
+ constructor(message: string);
30
+ }
31
+ export declare class OriginMismatchError extends WalletConnectionError {
32
+ readonly name = "OriginMismatchError";
33
+ constructor(message: string);
34
+ }
35
+ export declare class SignaturePayloadInvalidError extends WalletConnectionError {
36
+ readonly name = "SignaturePayloadInvalidError";
37
+ constructor(message: string);
38
+ }
39
+ /**
40
+ * Raised by `EvmConnector.submitRawTransaction` when the caller-supplied
41
+ * `to` does not match the configured checkout contract, or when the
42
+ * 4-byte function selector at the start of `data` is not on the explicit
43
+ * allowlist. The intent is to stop a compromised checkout API (or XSS in
44
+ * a consumer) from coercing the wallet into signing `approve(spender,
45
+ * MAX_UINT256)`, `setApprovalForAll`, NFT `safeTransferFrom`, etc.
46
+ */
47
+ export declare class InvalidTransactionError extends WalletConnectionError {
48
+ readonly name = "InvalidTransactionError";
49
+ constructor(message: string);
50
+ }
51
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,SAAkB,IAAI,EAAE,MAAM,CAA2B;gBAE7C,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,uBAAwB,SAAQ,qBAAqB;IAChE,SAAkB,IAAI,6BAA6B;gBACvC,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,uBAAwB,SAAQ,qBAAqB;IAChE,SAAkB,IAAI,6BAA6B;gBACvC,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,4BAA6B,SAAQ,qBAAqB;IACrE,SAAkB,IAAI,kCAAkC;gBAC5C,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,qBAAsB,SAAQ,qBAAqB;IAC9D,SAAkB,IAAI,2BAA2B;gBACrC,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,kBAAmB,SAAQ,qBAAqB;IAC3D,SAAkB,IAAI,wBAAwB;gBAClC,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,mBAAoB,SAAQ,qBAAqB;IAC5D,SAAkB,IAAI,yBAAyB;gBACnC,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,4BAA6B,SAAQ,qBAAqB;IACrE,SAAkB,IAAI,kCAAkC;gBAC5C,OAAO,EAAE,MAAM;CAG5B;AAED;;;;;;;GAOG;AACH,qBAAa,uBAAwB,SAAQ,qBAAqB;IAChE,SAAkB,IAAI,6BAA6B;gBACvC,OAAO,EAAE,MAAM;CAG5B"}
package/dist/errors.js ADDED
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Typed error classes. All errors extend native Error so callers can use
3
+ * `instanceof` and stack traces work correctly. The original v1.0.1
4
+ * package's classes did *not* extend Error — that was a footgun that
5
+ * silently broke try/catch in framework error boundaries.
6
+ */
7
+ export class WalletConnectionError extends Error {
8
+ name = 'WalletConnectionError';
9
+ constructor(message) {
10
+ super(message);
11
+ Object.setPrototypeOf(this, new.target.prototype);
12
+ }
13
+ }
14
+ export class WalletNotFoundException extends WalletConnectionError {
15
+ name = 'WalletNotFoundException';
16
+ constructor(message) {
17
+ super(message);
18
+ }
19
+ }
20
+ export class AccountChangedException extends WalletConnectionError {
21
+ name = 'AccountChangedException';
22
+ constructor(message) {
23
+ super(message);
24
+ }
25
+ }
26
+ export class ChainNotImplementedException extends WalletConnectionError {
27
+ name = 'ChainNotImplementedException';
28
+ constructor(message) {
29
+ super(message);
30
+ }
31
+ }
32
+ export class InvalidSignatureError extends WalletConnectionError {
33
+ name = 'InvalidSignatureError';
34
+ constructor(message) {
35
+ super(message);
36
+ }
37
+ }
38
+ export class ChainMismatchError extends WalletConnectionError {
39
+ name = 'ChainMismatchError';
40
+ constructor(message) {
41
+ super(message);
42
+ }
43
+ }
44
+ export class OriginMismatchError extends WalletConnectionError {
45
+ name = 'OriginMismatchError';
46
+ constructor(message) {
47
+ super(message);
48
+ }
49
+ }
50
+ export class SignaturePayloadInvalidError extends WalletConnectionError {
51
+ name = 'SignaturePayloadInvalidError';
52
+ constructor(message) {
53
+ super(message);
54
+ }
55
+ }
56
+ /**
57
+ * Raised by `EvmConnector.submitRawTransaction` when the caller-supplied
58
+ * `to` does not match the configured checkout contract, or when the
59
+ * 4-byte function selector at the start of `data` is not on the explicit
60
+ * allowlist. The intent is to stop a compromised checkout API (or XSS in
61
+ * a consumer) from coercing the wallet into signing `approve(spender,
62
+ * MAX_UINT256)`, `setApprovalForAll`, NFT `safeTransferFrom`, etc.
63
+ */
64
+ export class InvalidTransactionError extends WalletConnectionError {
65
+ name = 'InvalidTransactionError';
66
+ constructor(message) {
67
+ super(message);
68
+ }
69
+ }
70
+ //# sourceMappingUR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6B,SAAQ,qBAAqB;IACnD,IAAI,GAAG,8BAA8B,CAAC;IACxD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,uBAAwB,SAAQ,qBAAqB;IAC9C,IAAI,GAAG,yBAAyB,CAAC;IACnD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Public API surface for @droplinked_inc/wallet-connection.
3
+ *
4
+ * This package is a hardened rewrite of the original
5
+ * @droplinked/wallet-connection@1.0.1 (hostile-published by an external
6
+ * actor). The on-the-wire shape of types matches the original where
7
+ * feasible; behavior has been tightened — see THREAT_MODEL.md for the
8
+ * full delta.
9
+ */
10
+ import { Chain, ChainWallet, Network, type ChainProvider } from './types.js';
11
+ export { Chain, Network, ChainWallet, ProductType, type Proof, type Beneficiary, type CartItem, type IChainPayment, type ChainProvider, type EvmAddress, type LoginPayload, ProofSchema, BeneficiarySchema, CartItemSchema, ChainPaymentSchema, LoginPayloadSchema, EvmAddressSchema, ChainSchema, NetworkSchema, ChainWalletSchema, getEmptyProof, } from './types.js';
12
+ export { WalletConnectionError, WalletNotFoundException, AccountChangedException, ChainNotImplementedException, InvalidSignatureError, ChainMismatchError, OriginMismatchError, SignaturePayloadInvalidError, InvalidTransactionError, } from './errors.js';
13
+ export { EvmConnector, SUBMIT_RAW_TX_SELECTOR_ALLOWLIST, KNOWN_DRAINER_SELECTORS, } from './connectors/evm.js';
14
+ export { PhantomConnector, buildSolanaLoginPayload, canonicalizeSolanaLoginPayload, verifySolanaLoginSignature, SolanaLoginPayloadSchema, SOLANA_CHAIN_IDS, SOLANA_LOGIN_MAX_TTL_SECONDS, SOLANA_LOGIN_DEFAULT_TTL_SECONDS, DEFAULT_SOLANA_LOGIN_STATEMENT, base58Decode, type SolanaLoginPayload, type SolanaChainId, type PhantomConnectorOptions, } from './connectors/phantom.js';
15
+ export { isMetamaskInstalled, isCoinBaseInstalled, getAccounts, isWalletConnected, getBalance, selectMetaMaskProvider, selectCoinbaseProvider, discoverEip6963Providers, findProviderByRdns, WALLET_RDNS, type Eip1193Provider, type Eip6963ProviderInfo, type Eip6963ProviderDetail, type WalletRdns, } from './provider.js';
16
+ export { getChainMetadata, hasChainMetadata, type ChainMetadata } from './chains.js';
17
+ export { buildLoginPayload, signLoginPayload, verifyLoginSignature, generateNonce, constantTimeStringEquals, TYPED_DATA_DOMAIN_NAME, LOGIN_TYPES, } from './signing.js';
18
+ export { saveSession, loadSession, clearSession, buildSession, WalletSessionSchema, type WalletSession, type SessionStorage, } from './session.js';
19
+ export interface GetNetworkProviderArgs {
20
+ readonly chain: Chain;
21
+ readonly network: Network;
22
+ readonly address: string;
23
+ readonly wallet?: ChainWallet;
24
+ readonly checkoutContractAddress?: `0x${string}`;
25
+ readonly origin?: string;
26
+ }
27
+ /**
28
+ * Returns the correct ChainProvider for the (chain, network, wallet)
29
+ * triple. Mirrors the original `getNetworkProvider` factory but takes
30
+ * an options object rather than positional args.
31
+ */
32
+ export declare function getNetworkProvider(args: GetNetworkProviderArgs): ChainProvider;
33
+ /**
34
+ * @deprecated kept for v1.0.1 source compatibility. Use the standard
35
+ * Web APIs (`btoa` for strings) directly.
36
+ */
37
+ export declare function toBase64(str: string): string;
38
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,KAAK,EACL,WAAW,EACX,OAAO,EAEP,KAAK,aAAa,EACnB,MAAM,YAAY,CAAC;AAMpB,OAAO,EACL,KAAK,EACL,OAAO,EACP,WAAW,EACX,WAAW,EACX,KAAK,KAAK,EACV,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf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B,MAAM,cAAc,CAAC;AAItB,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,uBAAuB,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IACjD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,sBAAsB,GAAG,aAAa,CAmC9E;AAID;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE5C"}
package/dist/index.js ADDED
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Public API surface for @droplinked_inc/wallet-connection.
3
+ *
4
+ * This package is a hardened rewrite of the original
5
+ * @droplinked/wallet-connection@1.0.1 (hostile-published by an external
6
+ * actor). The on-the-wire shape of types matches the original where
7
+ * feasible; behavior has been tightened — see THREAT_MODEL.md for the
8
+ * full delta.
9
+ */
10
+ import { Chain, ChainWallet, Network, EvmAddressSchema, } from './types.js';
11
+ import { ChainNotImplementedException } from './errors.js';
12
+ import { EvmConnector } from './connectors/evm.js';
13
+ import { PhantomConnector } from './connectors/phantom.js';
14
+ /* ---------------------------- Types & enums ------------------------------- */
15
+ export { Chain, Network, ChainWallet, ProductType, ProofSchema, BeneficiarySchema, CartItemSchema, ChainPaymentSchema, LoginPayloadSchema, EvmAddressSchema, ChainSchema, NetworkSchema, ChainWalletSchema, getEmptyProof, } from './types.js';
16
+ /* ---------------------------- Errors -------------------------------------- */
17
+ export { WalletConnectionError, WalletNotFoundException, AccountChangedException, ChainNotImplementedException, InvalidSignatureError, ChainMismatchError, OriginMismatchError, SignaturePayloadInvalidError, InvalidTransactionError, } from './errors.js';
18
+ /* ---------------------------- Connectors ---------------------------------- */
19
+ export { EvmConnector, SUBMIT_RAW_TX_SELECTOR_ALLOWLIST, KNOWN_DRAINER_SELECTORS, } from './connectors/evm.js';
20
+ export { PhantomConnector, buildSolanaLoginPayload, canonicalizeSolanaLoginPayload, verifySolanaLoginSignature, SolanaLoginPayloadSchema, SOLANA_CHAIN_IDS, SOLANA_LOGIN_MAX_TTL_SECONDS, SOLANA_LOGIN_DEFAULT_TTL_SECONDS, DEFAULT_SOLANA_LOGIN_STATEMENT, base58Decode, } from './connectors/phantom.js';
21
+ /* ---------------------------- Provider helpers ---------------------------- */
22
+ export { isMetamaskInstalled, isCoinBaseInstalled, getAccounts, isWalletConnected, getBalance, selectMetaMaskProvider, selectCoinbaseProvider, discoverEip6963Providers, findProviderByRdns, WALLET_RDNS, } from './provider.js';
23
+ /* ---------------------------- Chains -------------------------------------- */
24
+ export { getChainMetadata, hasChainMetadata } from './chains.js';
25
+ /* ---------------------------- Signing ------------------------------------- */
26
+ export { buildLoginPayload, signLoginPayload, verifyLoginSignature, generateNonce, constantTimeStringEquals, TYPED_DATA_DOMAIN_NAME, LOGIN_TYPES, } from './signing.js';
27
+ /* ---------------------------- Session ------------------------------------- */
28
+ export { saveSession, loadSession, clearSession, buildSession, WalletSessionSchema, } from './session.js';
29
+ /**
30
+ * Returns the correct ChainProvider for the (chain, network, wallet)
31
+ * triple. Mirrors the original `getNetworkProvider` factory but takes
32
+ * an options object rather than positional args.
33
+ */
34
+ export function getNetworkProvider(args) {
35
+ if (args.chain === Chain.SOLANA) {
36
+ const connector = new PhantomConnector(args.network);
37
+ connector.setAddress(args.address);
38
+ return connector;
39
+ }
40
+ if (args.chain === Chain.STACKS ||
41
+ (args.chain === Chain.SKALE && args.network === Network.MAINNET)) {
42
+ throw new ChainNotImplementedException(`Chain ${args.chain} on ${args.network} is not implemented`);
43
+ }
44
+ const wallet = args.wallet ?? ChainWallet.Metamask;
45
+ if (wallet !== ChainWallet.Metamask && wallet !== ChainWallet.CoinBase) {
46
+ throw new ChainNotImplementedException(`Wallet ${wallet} not supported on EVM chain ${args.chain}`);
47
+ }
48
+ const baseOpts = {
49
+ chain: args.chain,
50
+ network: args.network,
51
+ wallet,
52
+ ...(args.checkoutContractAddress !== undefined
53
+ ? { checkoutContractAddress: args.checkoutContractAddress }
54
+ : {}),
55
+ ...(args.origin !== undefined ? { origin: args.origin } : {}),
56
+ };
57
+ const connector = new EvmConnector(baseOpts);
58
+ connector.setAddress(EvmAddressSchema.parse(args.address));
59
+ return connector;
60
+ }
61
+ /* ---------------------------- toBase64 (legacy) --------------------------- */
62
+ /**
63
+ * @deprecated kept for v1.0.1 source compatibility. Use the standard
64
+ * Web APIs (`btoa` for strings) directly.
65
+ */
66
+ export function toBase64(str) {
67
+ return btoa(str);
68
+ }
69
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,KAAK,EACL,WAAW,EACX,OAAO,EACP,gBAAgB,GAEjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,gFAAgF;AAChF,OAAO,EACL,KAAK,EACL,OAAO,EACP,WAAW,EACX,WAAW,EAQX,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,aAAa,GACd,MAAM,YAAY,CAAC;AAEpB,gFAAgF;AAChF,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,uBAAuB,EACvB,4BAA4B,EAC5B,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,4BAA4B,EAC5B,uBAA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