@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.
- package/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +142 -0
- package/THREAT_MODEL.md +180 -0
- package/dist/chains.d.ts +25 -0
- package/dist/chains.d.ts.map +1 -0
- package/dist/chains.js +153 -0
- package/dist/chains.js.map +1 -0
- package/dist/connectors/evm.d.ts +144 -0
- package/dist/connectors/evm.d.ts.map +1 -0
- package/dist/connectors/evm.js +330 -0
- package/dist/connectors/evm.js.map +1 -0
- package/dist/connectors/phantom.d.ts +167 -0
- package/dist/connectors/phantom.d.ts.map +1 -0
- package/dist/connectors/phantom.js +340 -0
- package/dist/connectors/phantom.js.map +1 -0
- package/dist/errors.d.ts +51 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +70 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +74 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +210 -0
- package/dist/provider.js.map +1 -0
- package/dist/session.d.ts +68 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +99 -0
- package/dist/session.js.map +1 -0
- package/dist/signing.d.ts +94 -0
- package/dist/signing.d.ts.map +1 -0
- package/dist/signing.js +178 -0
- package/dist/signing.js.map +1 -0
- package/dist/types.d.ts +234 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +150 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -0
package/dist/signing.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EIP-712 typed-data signing + verification.
|
|
3
|
+
*
|
|
4
|
+
* Hardening deltas vs. v1.0.1:
|
|
5
|
+
* 1. v1.0.1 used `personal_sign` of a static plaintext — replayable
|
|
6
|
+
* across chains, origins, time. We use EIP-712 typed data with
|
|
7
|
+
* explicit domain (chainId + origin) and a per-attempt nonce.
|
|
8
|
+
* 2. Nonces are 256-bit cryptographically-random url-safe strings.
|
|
9
|
+
* 3. Signature verification is constant-time at the byte-array level.
|
|
10
|
+
* 4. Recovered address is compared as a normalized lowercase hex string.
|
|
11
|
+
*/
|
|
12
|
+
import { verifyTypedData } from 'viem';
|
|
13
|
+
import { LoginPayloadSchema, } from './types.js';
|
|
14
|
+
import { InvalidSignatureError, SignaturePayloadInvalidError, ChainMismatchError, OriginMismatchError, } from './errors.js';
|
|
15
|
+
/** EIP-712 domain name — kept short, embedded in every signed payload. */
|
|
16
|
+
export const TYPED_DATA_DOMAIN_NAME = 'droplinked';
|
|
17
|
+
/** EIP-712 type definitions. */
|
|
18
|
+
export const LOGIN_TYPES = {
|
|
19
|
+
Login: [
|
|
20
|
+
{ name: 'domain', type: 'string' },
|
|
21
|
+
{ name: 'address', type: 'address' },
|
|
22
|
+
{ name: 'statement', type: 'string' },
|
|
23
|
+
{ name: 'uri', type: 'string' },
|
|
24
|
+
{ name: 'version', type: 'string' },
|
|
25
|
+
{ name: 'chainId', type: 'uint256' },
|
|
26
|
+
{ name: 'nonce', type: 'string' },
|
|
27
|
+
{ name: 'issuedAt', type: 'string' },
|
|
28
|
+
{ name: 'expirationTime', type: 'string' },
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Generates a 256-bit random url-safe nonce. Uses Web Crypto when available;
|
|
33
|
+
* throws if no CSPRNG is reachable (we refuse to fall back to Math.random).
|
|
34
|
+
*/
|
|
35
|
+
export function generateNonce() {
|
|
36
|
+
const cryptoObj = globalThis
|
|
37
|
+
.crypto;
|
|
38
|
+
if (cryptoObj === undefined || typeof cryptoObj.getRandomValues !== 'function') {
|
|
39
|
+
throw new Error('Web Crypto API unavailable; cannot generate nonce');
|
|
40
|
+
}
|
|
41
|
+
const bytes = new Uint8Array(32);
|
|
42
|
+
cryptoObj.getRandomValues(bytes);
|
|
43
|
+
// base64url without padding
|
|
44
|
+
let bin = '';
|
|
45
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
46
|
+
bin += String.fromCharCode(bytes[i]);
|
|
47
|
+
}
|
|
48
|
+
return btoa(bin).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/u, '');
|
|
49
|
+
}
|
|
50
|
+
export function buildLoginPayload(args) {
|
|
51
|
+
const issuedAt = new Date().toISOString();
|
|
52
|
+
const expirationTime = args.expiresInSeconds !== undefined
|
|
53
|
+
? new Date(Date.now() + args.expiresInSeconds * 1000).toISOString()
|
|
54
|
+
: undefined;
|
|
55
|
+
const payload = {
|
|
56
|
+
domain: extractHost(args.origin),
|
|
57
|
+
address: args.address,
|
|
58
|
+
statement: args.statement ??
|
|
59
|
+
'Sign in to droplinked. This signature does not authorize any token transfer.',
|
|
60
|
+
uri: args.origin,
|
|
61
|
+
version: '1',
|
|
62
|
+
chainId: args.chainId,
|
|
63
|
+
nonce: generateNonce(),
|
|
64
|
+
issuedAt,
|
|
65
|
+
...(expirationTime !== undefined ? { expirationTime } : {}),
|
|
66
|
+
};
|
|
67
|
+
// Defensive: validate what we just built — guards against accidental
|
|
68
|
+
// construction bugs and ensures the schema is the single source of truth.
|
|
69
|
+
const parsed = LoginPayloadSchema.safeParse(payload);
|
|
70
|
+
if (!parsed.success) {
|
|
71
|
+
throw new SignaturePayloadInvalidError(parsed.error.message);
|
|
72
|
+
}
|
|
73
|
+
return parsed.data;
|
|
74
|
+
}
|
|
75
|
+
function extractHost(origin) {
|
|
76
|
+
try {
|
|
77
|
+
return new URL(origin).host;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
throw new SignaturePayloadInvalidError(`invalid origin: ${origin}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Request the wallet to sign the typed payload. Returns the 0x-prefixed
|
|
85
|
+
* signature.
|
|
86
|
+
*/
|
|
87
|
+
export async function signLoginPayload(provider, payload) {
|
|
88
|
+
const typedData = {
|
|
89
|
+
domain: {
|
|
90
|
+
name: TYPED_DATA_DOMAIN_NAME,
|
|
91
|
+
version: '1',
|
|
92
|
+
chainId: payload.chainId,
|
|
93
|
+
},
|
|
94
|
+
primaryType: 'Login',
|
|
95
|
+
types: LOGIN_TYPES,
|
|
96
|
+
message: payload,
|
|
97
|
+
};
|
|
98
|
+
const raw = await provider.request({
|
|
99
|
+
method: 'eth_signTypedData_v4',
|
|
100
|
+
params: [payload.address, JSON.stringify(typedData)],
|
|
101
|
+
});
|
|
102
|
+
if (typeof raw !== 'string' || !/^0x[a-fA-F0-9]+$/u.test(raw)) {
|
|
103
|
+
throw new InvalidSignatureError('wallet returned non-hex signature');
|
|
104
|
+
}
|
|
105
|
+
return raw;
|
|
106
|
+
}
|
|
107
|
+
export async function verifyLoginSignature(args) {
|
|
108
|
+
const parsed = LoginPayloadSchema.safeParse(args.payload);
|
|
109
|
+
if (!parsed.success) {
|
|
110
|
+
throw new SignaturePayloadInvalidError(parsed.error.message);
|
|
111
|
+
}
|
|
112
|
+
const payload = parsed.data;
|
|
113
|
+
// Chain binding
|
|
114
|
+
if (payload.chainId !== args.expectedChainId) {
|
|
115
|
+
throw new ChainMismatchError(`chainId mismatch: payload=${payload.chainId} expected=${args.expectedChainId}`);
|
|
116
|
+
}
|
|
117
|
+
// Origin binding (compare hosts case-insensitively in constant time)
|
|
118
|
+
const expectedHost = extractHost(args.expectedOrigin).toLowerCase();
|
|
119
|
+
const actualHost = payload.domain.toLowerCase();
|
|
120
|
+
if (!constantTimeStringEquals(expectedHost, actualHost)) {
|
|
121
|
+
throw new OriginMismatchError(`origin mismatch: payload=${actualHost} expected=${expectedHost}`);
|
|
122
|
+
}
|
|
123
|
+
// Address sanity
|
|
124
|
+
if (!constantTimeStringEquals(payload.address.toLowerCase(), args.expectedAddress.toLowerCase())) {
|
|
125
|
+
throw new InvalidSignatureError('address mismatch between payload and expected');
|
|
126
|
+
}
|
|
127
|
+
// Expiration
|
|
128
|
+
if (payload.expirationTime !== undefined) {
|
|
129
|
+
const now = args.nowMs ?? Date.now();
|
|
130
|
+
const expMs = Date.parse(payload.expirationTime);
|
|
131
|
+
if (Number.isNaN(expMs) || expMs <= now) {
|
|
132
|
+
throw new InvalidSignatureError('login payload expired');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// Cryptographic verification via viem. Viem requires uint256 fields
|
|
136
|
+
// to be passed as bigint; we widen `chainId` accordingly. The wallet's
|
|
137
|
+
// own EIP-712 hash agrees because uint256(N) hashes identically whether
|
|
138
|
+
// the JS source value was `number N` or `bigint N`.
|
|
139
|
+
const message = {
|
|
140
|
+
...payload,
|
|
141
|
+
chainId: BigInt(payload.chainId),
|
|
142
|
+
expirationTime: payload.expirationTime ?? '',
|
|
143
|
+
};
|
|
144
|
+
const ok = await verifyTypedData({
|
|
145
|
+
address: args.expectedAddress,
|
|
146
|
+
domain: {
|
|
147
|
+
name: TYPED_DATA_DOMAIN_NAME,
|
|
148
|
+
version: '1',
|
|
149
|
+
chainId: BigInt(payload.chainId),
|
|
150
|
+
},
|
|
151
|
+
types: LOGIN_TYPES,
|
|
152
|
+
primaryType: 'Login',
|
|
153
|
+
message,
|
|
154
|
+
signature: args.signature,
|
|
155
|
+
});
|
|
156
|
+
if (!ok) {
|
|
157
|
+
throw new InvalidSignatureError('signature did not recover expected address');
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Constant-time string equality. Compares the UTF-8 byte representation;
|
|
162
|
+
* always touches every byte of both inputs regardless of mismatch position.
|
|
163
|
+
* Returns false immediately on length mismatch — note that length is
|
|
164
|
+
* inherently leaky and not considered a secret here.
|
|
165
|
+
*/
|
|
166
|
+
export function constantTimeStringEquals(a, b) {
|
|
167
|
+
const aBytes = new TextEncoder().encode(a);
|
|
168
|
+
const bBytes = new TextEncoder().encode(b);
|
|
169
|
+
if (aBytes.length !== bBytes.length) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
let diff = 0;
|
|
173
|
+
for (let i = 0; i < aBytes.length; i++) {
|
|
174
|
+
diff |= aBytes[i] ^ bBytes[i];
|
|
175
|
+
}
|
|
176
|
+
return diff === 0;
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=signing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signing.js","sourceRoot":"","sources":["../src/signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,eAAe,EAA0B,MAAM,MAAM,CAAC;AAC/D,OAAO,EACL,kBAAkB,GAGnB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,qBAAqB,EACrB,4BAA4B,EAC5B,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAGrB,0EAA0E;AAC1E,MAAM,CAAC,MAAM,sBAAsB,GAAG,YAAqB,CAAC;AAE5D,gCAAgC;AAChC,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,KAAK,EAAE;QACL,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;QAClC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;QACpC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE;QACrC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC/B,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;QACnC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;QACpC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE;QACjC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE;QACpC,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC3C;CACO,CAAC;AAEX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G,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3C,IAAI,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,IAAI,IAAK,MAAM,CAAC,CAAC,CAAY,GAAI,MAAM,CAAC,CAAC,CAAY,CAAC;IACxD,CAAC;IACD,OAAO,IAAI,KAAK,CAAC,CAAC;AACpB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types and zod schemas for @droplinked_inc/wallet-connection.
|
|
3
|
+
*
|
|
4
|
+
* Every value that crosses an external boundary (window.ethereum response,
|
|
5
|
+
* RPC response, user-provided IChainPayment, etc.) is validated against the
|
|
6
|
+
* schemas in this module before being trusted.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
/**
|
|
10
|
+
* Supported chain identifiers.
|
|
11
|
+
*
|
|
12
|
+
* NOTE: Kept as a string-valued enum (vs. the implicit-numeric enum in the
|
|
13
|
+
* original v1.0.1) so values are stable across releases and survive
|
|
14
|
+
* JSON serialization. Numeric values from the original package are no
|
|
15
|
+
* longer accepted — callers must pass the string names.
|
|
16
|
+
*/
|
|
17
|
+
export declare enum Chain {
|
|
18
|
+
POLYGON = "POLYGON",
|
|
19
|
+
BINANCE = "BINANCE",
|
|
20
|
+
STACKS = "STACKS",
|
|
21
|
+
XRPLSIDECHAIN = "XRPLSIDECHAIN",
|
|
22
|
+
NEAR = "NEAR",
|
|
23
|
+
SKALE = "SKALE",
|
|
24
|
+
BASE = "BASE",
|
|
25
|
+
LINEA = "LINEA",
|
|
26
|
+
ETH = "ETH",
|
|
27
|
+
SOLANA = "SOLANA"
|
|
28
|
+
}
|
|
29
|
+
export declare enum Network {
|
|
30
|
+
MAINNET = "MAINNET",
|
|
31
|
+
TESTNET = "TESTNET"
|
|
32
|
+
}
|
|
33
|
+
export declare enum ChainWallet {
|
|
34
|
+
Metamask = "Metamask",
|
|
35
|
+
CoinBase = "CoinBase",
|
|
36
|
+
CasperWallet = "CasperWallet",
|
|
37
|
+
PhantomWallet = "PhantomWallet"
|
|
38
|
+
}
|
|
39
|
+
export declare enum ProductType {
|
|
40
|
+
DIGITAL = "DIGITAL",
|
|
41
|
+
POD = "POD",
|
|
42
|
+
PHYSICAL = "PHYSICAL"
|
|
43
|
+
}
|
|
44
|
+
export declare const ChainSchema: z.ZodNativeEnum<typeof Chain>;
|
|
45
|
+
export declare const NetworkSchema: z.ZodNativeEnum<typeof Network>;
|
|
46
|
+
export declare const ChainWalletSchema: z.ZodNativeEnum<typeof ChainWallet>;
|
|
47
|
+
/** 0x-prefixed lowercase 40-char hex address. */
|
|
48
|
+
export declare const EvmAddressSchema: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
49
|
+
export type EvmAddress = `0x${string}`;
|
|
50
|
+
export declare const HexStringSchema: z.ZodString;
|
|
51
|
+
export declare const ProofSchema: z.ZodObject<{
|
|
52
|
+
_pA: z.ZodTuple<[z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>], null>;
|
|
53
|
+
_pB: z.ZodTuple<[z.ZodTuple<[z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>], null>, z.ZodTuple<[z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>], null>], null>;
|
|
54
|
+
_pC: z.ZodTuple<[z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>], null>;
|
|
55
|
+
_pubSignals: z.ZodTuple<[z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>], null>;
|
|
56
|
+
provided: z.ZodBoolean;
|
|
57
|
+
}, "strip", z.ZodTypeAny, {
|
|
58
|
+
_pA: [string | number | bigint, string | number | bigint];
|
|
59
|
+
_pB: [[string | number | bigint, string | number | bigint], [string | number | bigint, string | number | bigint]];
|
|
60
|
+
_pC: [string | number | bigint, string | number | bigint];
|
|
61
|
+
_pubSignals: [string | number | bigint, string | number | bigint, string | number | bigint];
|
|
62
|
+
provided: boolean;
|
|
63
|
+
}, {
|
|
64
|
+
_pA: [string | number | bigint, string | number | bigint];
|
|
65
|
+
_pB: [[string | number | bigint, string | number | bigint], [string | number | bigint, string | number | bigint]];
|
|
66
|
+
_pC: [string | number | bigint, string | number | bigint];
|
|
67
|
+
_pubSignals: [string | number | bigint, string | number | bigint, string | number | bigint];
|
|
68
|
+
provided: boolean;
|
|
69
|
+
}>;
|
|
70
|
+
export type Proof = z.infer<typeof ProofSchema>;
|
|
71
|
+
/**
|
|
72
|
+
* Returns a Proof shape that marks itself as "not provided" — equivalent to
|
|
73
|
+
* the original `getEmptyProof()` helper from v1.0.1. The on-chain contract
|
|
74
|
+
* branches on `provided=false` to skip ZK verification.
|
|
75
|
+
*/
|
|
76
|
+
export declare function getEmptyProof(): Proof;
|
|
77
|
+
export declare const BeneficiarySchema: z.ZodObject<{
|
|
78
|
+
isPercentage: z.ZodBoolean;
|
|
79
|
+
value: z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>;
|
|
80
|
+
wallet: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
81
|
+
}, "strip", z.ZodTypeAny, {
|
|
82
|
+
value: string | number | bigint;
|
|
83
|
+
isPercentage: boolean;
|
|
84
|
+
wallet: `0x${string}`;
|
|
85
|
+
}, {
|
|
86
|
+
value: string | number | bigint;
|
|
87
|
+
isPercentage: boolean;
|
|
88
|
+
wallet: string;
|
|
89
|
+
}>;
|
|
90
|
+
export type Beneficiary = z.infer<typeof BeneficiarySchema>;
|
|
91
|
+
export declare const CartItemSchema: z.ZodObject<{
|
|
92
|
+
id: z.ZodNumber;
|
|
93
|
+
amount: z.ZodNumber;
|
|
94
|
+
isAffiliate: z.ZodBoolean;
|
|
95
|
+
}, "strip", z.ZodTypeAny, {
|
|
96
|
+
id: number;
|
|
97
|
+
amount: number;
|
|
98
|
+
isAffiliate: boolean;
|
|
99
|
+
}, {
|
|
100
|
+
id: number;
|
|
101
|
+
amount: number;
|
|
102
|
+
isAffiliate: boolean;
|
|
103
|
+
}>;
|
|
104
|
+
export type CartItem = z.infer<typeof CartItemSchema>;
|
|
105
|
+
export declare const ChainPaymentSchema: z.ZodObject<{
|
|
106
|
+
shopWallet: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
107
|
+
chainLinkRoundId: z.ZodString;
|
|
108
|
+
totalPrice: z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>;
|
|
109
|
+
tbdValues: z.ZodArray<z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, "many">;
|
|
110
|
+
tbdReceivers: z.ZodArray<z.ZodEffects<z.ZodString, `0x${string}`, string>, "many">;
|
|
111
|
+
cartItems: z.ZodArray<z.ZodObject<{
|
|
112
|
+
id: z.ZodNumber;
|
|
113
|
+
amount: z.ZodNumber;
|
|
114
|
+
isAffiliate: z.ZodBoolean;
|
|
115
|
+
}, "strip", z.ZodTypeAny, {
|
|
116
|
+
id: number;
|
|
117
|
+
amount: number;
|
|
118
|
+
isAffiliate: boolean;
|
|
119
|
+
}, {
|
|
120
|
+
id: number;
|
|
121
|
+
amount: number;
|
|
122
|
+
isAffiliate: boolean;
|
|
123
|
+
}>, "many">;
|
|
124
|
+
proof: z.ZodOptional<z.ZodObject<{
|
|
125
|
+
_pA: z.ZodTuple<[z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>], null>;
|
|
126
|
+
_pB: z.ZodTuple<[z.ZodTuple<[z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>], null>, z.ZodTuple<[z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>], null>], null>;
|
|
127
|
+
_pC: z.ZodTuple<[z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>], null>;
|
|
128
|
+
_pubSignals: z.ZodTuple<[z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>], null>;
|
|
129
|
+
provided: z.ZodBoolean;
|
|
130
|
+
}, "strip", z.ZodTypeAny, {
|
|
131
|
+
_pA: [string | number | bigint, string | number | bigint];
|
|
132
|
+
_pB: [[string | number | bigint, string | number | bigint], [string | number | bigint, string | number | bigint]];
|
|
133
|
+
_pC: [string | number | bigint, string | number | bigint];
|
|
134
|
+
_pubSignals: [string | number | bigint, string | number | bigint, string | number | bigint];
|
|
135
|
+
provided: boolean;
|
|
136
|
+
}, {
|
|
137
|
+
_pA: [string | number | bigint, string | number | bigint];
|
|
138
|
+
_pB: [[string | number | bigint, string | number | bigint], [string | number | bigint, string | number | bigint]];
|
|
139
|
+
_pC: [string | number | bigint, string | number | bigint];
|
|
140
|
+
_pubSignals: [string | number | bigint, string | number | bigint, string | number | bigint];
|
|
141
|
+
provided: boolean;
|
|
142
|
+
}>>;
|
|
143
|
+
memo: z.ZodString;
|
|
144
|
+
}, "strip", z.ZodTypeAny, {
|
|
145
|
+
shopWallet: `0x${string}`;
|
|
146
|
+
chainLinkRoundId: string;
|
|
147
|
+
totalPrice: string | number | bigint;
|
|
148
|
+
tbdValues: (string | number | bigint)[];
|
|
149
|
+
tbdReceivers: `0x${string}`[];
|
|
150
|
+
cartItems: {
|
|
151
|
+
id: number;
|
|
152
|
+
amount: number;
|
|
153
|
+
isAffiliate: boolean;
|
|
154
|
+
}[];
|
|
155
|
+
memo: string;
|
|
156
|
+
proof?: {
|
|
157
|
+
_pA: [string | number | bigint, string | number | bigint];
|
|
158
|
+
_pB: [[string | number | bigint, string | number | bigint], [string | number | bigint, string | number | bigint]];
|
|
159
|
+
_pC: [string | number | bigint, string | number | bigint];
|
|
160
|
+
_pubSignals: [string | number | bigint, string | number | bigint, string | number | bigint];
|
|
161
|
+
provided: boolean;
|
|
162
|
+
} | undefined;
|
|
163
|
+
}, {
|
|
164
|
+
shopWallet: string;
|
|
165
|
+
chainLinkRoundId: string;
|
|
166
|
+
totalPrice: string | number | bigint;
|
|
167
|
+
tbdValues: (string | number | bigint)[];
|
|
168
|
+
tbdReceivers: string[];
|
|
169
|
+
cartItems: {
|
|
170
|
+
id: number;
|
|
171
|
+
amount: number;
|
|
172
|
+
isAffiliate: boolean;
|
|
173
|
+
}[];
|
|
174
|
+
memo: string;
|
|
175
|
+
proof?: {
|
|
176
|
+
_pA: [string | number | bigint, string | number | bigint];
|
|
177
|
+
_pB: [[string | number | bigint, string | number | bigint], [string | number | bigint, string | number | bigint]];
|
|
178
|
+
_pC: [string | number | bigint, string | number | bigint];
|
|
179
|
+
_pubSignals: [string | number | bigint, string | number | bigint, string | number | bigint];
|
|
180
|
+
provided: boolean;
|
|
181
|
+
} | undefined;
|
|
182
|
+
}>;
|
|
183
|
+
export type IChainPayment = z.infer<typeof ChainPaymentSchema>;
|
|
184
|
+
export interface ChainProvider {
|
|
185
|
+
walletLogin(): Promise<{
|
|
186
|
+
address: string;
|
|
187
|
+
signature: string;
|
|
188
|
+
}>;
|
|
189
|
+
payment(data: IChainPayment): Promise<{
|
|
190
|
+
deploy_hash: string;
|
|
191
|
+
cryptoAmount: bigint;
|
|
192
|
+
}>;
|
|
193
|
+
paymentWithToken(receiver: string, amount: bigint, tokenAddress: string): Promise<string>;
|
|
194
|
+
setAddress(address: string): ChainProvider;
|
|
195
|
+
setWallet(wallet: ChainWallet): ChainProvider;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Canonical typed-data login payload. EIP-712 typed signing binds the
|
|
199
|
+
* signature to chainId + origin + nonce + issuedAt, so a signature obtained
|
|
200
|
+
* on chain X cannot be replayed on chain Y or against a different origin.
|
|
201
|
+
*/
|
|
202
|
+
export declare const LoginPayloadSchema: z.ZodObject<{
|
|
203
|
+
domain: z.ZodString;
|
|
204
|
+
address: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
205
|
+
statement: z.ZodString;
|
|
206
|
+
uri: z.ZodString;
|
|
207
|
+
version: z.ZodLiteral<"1">;
|
|
208
|
+
chainId: z.ZodNumber;
|
|
209
|
+
nonce: z.ZodString;
|
|
210
|
+
issuedAt: z.ZodString;
|
|
211
|
+
expirationTime: z.ZodOptional<z.ZodString>;
|
|
212
|
+
}, "strip", z.ZodTypeAny, {
|
|
213
|
+
domain: string;
|
|
214
|
+
address: `0x${string}`;
|
|
215
|
+
statement: string;
|
|
216
|
+
uri: string;
|
|
217
|
+
version: "1";
|
|
218
|
+
chainId: number;
|
|
219
|
+
nonce: string;
|
|
220
|
+
issuedAt: string;
|
|
221
|
+
expirationTime?: string | undefined;
|
|
222
|
+
}, {
|
|
223
|
+
domain: string;
|
|
224
|
+
address: string;
|
|
225
|
+
statement: string;
|
|
226
|
+
uri: string;
|
|
227
|
+
version: "1";
|
|
228
|
+
chainId: number;
|
|
229
|
+
nonce: string;
|
|
230
|
+
issuedAt: string;
|
|
231
|
+
expirationTime?: string | undefined;
|
|
232
|
+
}>;
|
|
233
|
+
export type LoginPayload = z.infer<typeof LoginPayloadSchema>;
|
|
234
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB;;;;;;;GAOG;AACH,oBAAY,KAAK;IACf,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,aAAa,kBAAkB;IAC/B,IAAI,SAAS;IACb,KAAK,UAAU;IACf,IAAI,SAAS;IACb,KAAK,UAAU;IACf,GAAG,QAAQ;IACX,MAAM,WAAW;CAClB;AAED,oBAAY,OAAO;IACjB,OAAO,YAAY;IACnB,OAAO,YAAY;CACpB;AAED,oBAAY,WAAW;IACrB,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,YAAY,iBAAiB;IAC7B,aAAa,kBAAkB;CAChC;AAED,oBAAY,WAAW;IACrB,OAAO,YAAY;IACnB,GAAG,QAAQ;IACX,QAAQ,aAAa;CACtB;AAED,eAAO,MAAM,WAAW,+BAAsB,CAAC;AAC/C,eAAO,MAAM,aAAa,iCAAwB,CAAC;AACnD,eAAO,MAAM,iBAAiB,qCAA4B,CAAC;AAM3D,iDAAiD;AACjD,eAAO,MAAM,gBAAgB,kDAGwB,CAAC;AAEtD,MAAM,MAAM,UAAU,GAAG,KAAK,MAAM,EAAE,CAAC;AAEvC,eAAO,MAAM,eAAe,aAEuB,CAAC;AAYpD,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;EAStB,CAAC;AAEH,MAAM,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEhD;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,KAAK,CAWrC;AAMD,eAAO,MAAM,iBAAiB;;;;;;;;;;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|
+
*
|
|
4
|
+
* Every value that crosses an external boundary (window.ethereum response,
|
|
5
|
+
* RPC response, user-provided IChainPayment, etc.) is validated against the
|
|
6
|
+
* schemas in this module before being trusted.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
/* -------------------------------------------------------------------------- */
|
|
10
|
+
/* Chains & networks */
|
|
11
|
+
/* -------------------------------------------------------------------------- */
|
|
12
|
+
/**
|
|
13
|
+
* Supported chain identifiers.
|
|
14
|
+
*
|
|
15
|
+
* NOTE: Kept as a string-valued enum (vs. the implicit-numeric enum in the
|
|
16
|
+
* original v1.0.1) so values are stable across releases and survive
|
|
17
|
+
* JSON serialization. Numeric values from the original package are no
|
|
18
|
+
* longer accepted — callers must pass the string names.
|
|
19
|
+
*/
|
|
20
|
+
export var Chain;
|
|
21
|
+
(function (Chain) {
|
|
22
|
+
Chain["POLYGON"] = "POLYGON";
|
|
23
|
+
Chain["BINANCE"] = "BINANCE";
|
|
24
|
+
Chain["STACKS"] = "STACKS";
|
|
25
|
+
Chain["XRPLSIDECHAIN"] = "XRPLSIDECHAIN";
|
|
26
|
+
Chain["NEAR"] = "NEAR";
|
|
27
|
+
Chain["SKALE"] = "SKALE";
|
|
28
|
+
Chain["BASE"] = "BASE";
|
|
29
|
+
Chain["LINEA"] = "LINEA";
|
|
30
|
+
Chain["ETH"] = "ETH";
|
|
31
|
+
Chain["SOLANA"] = "SOLANA";
|
|
32
|
+
})(Chain || (Chain = {}));
|
|
33
|
+
export var Network;
|
|
34
|
+
(function (Network) {
|
|
35
|
+
Network["MAINNET"] = "MAINNET";
|
|
36
|
+
Network["TESTNET"] = "TESTNET";
|
|
37
|
+
})(Network || (Network = {}));
|
|
38
|
+
export var ChainWallet;
|
|
39
|
+
(function (ChainWallet) {
|
|
40
|
+
ChainWallet["Metamask"] = "Metamask";
|
|
41
|
+
ChainWallet["CoinBase"] = "CoinBase";
|
|
42
|
+
ChainWallet["CasperWallet"] = "CasperWallet";
|
|
43
|
+
ChainWallet["PhantomWallet"] = "PhantomWallet";
|
|
44
|
+
})(ChainWallet || (ChainWallet = {}));
|
|
45
|
+
export var ProductType;
|
|
46
|
+
(function (ProductType) {
|
|
47
|
+
ProductType["DIGITAL"] = "DIGITAL";
|
|
48
|
+
ProductType["POD"] = "POD";
|
|
49
|
+
ProductType["PHYSICAL"] = "PHYSICAL";
|
|
50
|
+
})(ProductType || (ProductType = {}));
|
|
51
|
+
export const ChainSchema = z.nativeEnum(Chain);
|
|
52
|
+
export const NetworkSchema = z.nativeEnum(Network);
|
|
53
|
+
export const ChainWalletSchema = z.nativeEnum(ChainWallet);
|
|
54
|
+
/* -------------------------------------------------------------------------- */
|
|
55
|
+
/* EVM primitives */
|
|
56
|
+
/* -------------------------------------------------------------------------- */
|
|
57
|
+
/** 0x-prefixed lowercase 40-char hex address. */
|
|
58
|
+
export const EvmAddressSchema = z
|
|
59
|
+
.string()
|
|
60
|
+
.regex(/^0x[a-fA-F0-9]{40}$/u, 'invalid EVM address')
|
|
61
|
+
.transform((s) => s.toLowerCase());
|
|
62
|
+
export const HexStringSchema = z
|
|
63
|
+
.string()
|
|
64
|
+
.regex(/^0x[a-fA-F0-9]*$/u, 'invalid hex string');
|
|
65
|
+
/* -------------------------------------------------------------------------- */
|
|
66
|
+
/* Zero-knowledge coupon proof (carried over from v1.0.1 contract ABI) */
|
|
67
|
+
/* -------------------------------------------------------------------------- */
|
|
68
|
+
const BigintLikeSchema = z.union([
|
|
69
|
+
z.bigint(),
|
|
70
|
+
z.number().int().nonnegative(),
|
|
71
|
+
z.string().regex(/^[0-9]+$/u),
|
|
72
|
+
]);
|
|
73
|
+
export const ProofSchema = z.object({
|
|
74
|
+
_pA: z.tuple([BigintLikeSchema, BigintLikeSchema]),
|
|
75
|
+
_pB: z.tuple([
|
|
76
|
+
z.tuple([BigintLikeSchema, BigintLikeSchema]),
|
|
77
|
+
z.tuple([BigintLikeSchema, BigintLikeSchema]),
|
|
78
|
+
]),
|
|
79
|
+
_pC: z.tuple([BigintLikeSchema, BigintLikeSchema]),
|
|
80
|
+
_pubSignals: z.tuple([BigintLikeSchema, BigintLikeSchema, BigintLikeSchema]),
|
|
81
|
+
provided: z.boolean(),
|
|
82
|
+
});
|
|
83
|
+
/**
|
|
84
|
+
* Returns a Proof shape that marks itself as "not provided" — equivalent to
|
|
85
|
+
* the original `getEmptyProof()` helper from v1.0.1. The on-chain contract
|
|
86
|
+
* branches on `provided=false` to skip ZK verification.
|
|
87
|
+
*/
|
|
88
|
+
export function getEmptyProof() {
|
|
89
|
+
return {
|
|
90
|
+
_pA: [0, 0],
|
|
91
|
+
_pB: [
|
|
92
|
+
[0, 0],
|
|
93
|
+
[0, 0],
|
|
94
|
+
],
|
|
95
|
+
_pC: [0, 0],
|
|
96
|
+
_pubSignals: [0, 0, 0],
|
|
97
|
+
provided: false,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/* -------------------------------------------------------------------------- */
|
|
101
|
+
/* Beneficiary + payment payloads */
|
|
102
|
+
/* -------------------------------------------------------------------------- */
|
|
103
|
+
export const BeneficiarySchema = z.object({
|
|
104
|
+
isPercentage: z.boolean(),
|
|
105
|
+
value: BigintLikeSchema,
|
|
106
|
+
wallet: EvmAddressSchema,
|
|
107
|
+
});
|
|
108
|
+
export const CartItemSchema = z.object({
|
|
109
|
+
id: z.number().int().nonnegative(),
|
|
110
|
+
amount: z.number().int().positive(),
|
|
111
|
+
isAffiliate: z.boolean(),
|
|
112
|
+
});
|
|
113
|
+
export const ChainPaymentSchema = z.object({
|
|
114
|
+
shopWallet: EvmAddressSchema,
|
|
115
|
+
chainLinkRoundId: z.string().regex(/^[0-9]+$/u, 'chainLinkRoundId must be a uint string'),
|
|
116
|
+
totalPrice: BigintLikeSchema,
|
|
117
|
+
tbdValues: z.array(BigintLikeSchema),
|
|
118
|
+
tbdReceivers: z.array(EvmAddressSchema),
|
|
119
|
+
cartItems: z.array(CartItemSchema),
|
|
120
|
+
proof: ProofSchema.optional(),
|
|
121
|
+
memo: z.string().max(1024, 'memo too long'),
|
|
122
|
+
});
|
|
123
|
+
/* -------------------------------------------------------------------------- */
|
|
124
|
+
/* Session payload (for typed signing) */
|
|
125
|
+
/* -------------------------------------------------------------------------- */
|
|
126
|
+
/**
|
|
127
|
+
* Canonical typed-data login payload. EIP-712 typed signing binds the
|
|
128
|
+
* signature to chainId + origin + nonce + issuedAt, so a signature obtained
|
|
129
|
+
* on chain X cannot be replayed on chain Y or against a different origin.
|
|
130
|
+
*/
|
|
131
|
+
export const LoginPayloadSchema = z.object({
|
|
132
|
+
domain: z
|
|
133
|
+
.string()
|
|
134
|
+
.min(1)
|
|
135
|
+
.max(253)
|
|
136
|
+
.regex(/^[a-z0-9.\-:]+$/iu, 'invalid domain'),
|
|
137
|
+
address: EvmAddressSchema,
|
|
138
|
+
statement: z.string().max(512),
|
|
139
|
+
uri: z.string().url(),
|
|
140
|
+
version: z.literal('1'),
|
|
141
|
+
chainId: z.number().int().positive(),
|
|
142
|
+
nonce: z
|
|
143
|
+
.string()
|
|
144
|
+
.min(8)
|
|
145
|
+
.max(128)
|
|
146
|
+
.regex(/^[A-Za-z0-9_-]+$/u, 'nonce must be url-safe'),
|
|
147
|
+
issuedAt: z.string().datetime(),
|
|
148
|
+
expirationTime: z.string().datetime().optional(),
|
|
149
|
+
});
|
|
150
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,gFAAgF;AAChF,iFAAiF;AACjF,gFAAgF;AAEhF;;;;;;;GAOG;AACH,MAAM,CAAN,IAAY,KAWX;AAXD,WAAY,KAAK;IACf,4BAAmB,CAAA;IACnB,4BAAmB,CAAA;IACnB,0BAAiB,CAAA;IACjB,wCAA+B,CAAA;IAC/B,sBAAa,CAAA;IACb,wBA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IACzB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC;IAC9B,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE;IACrB,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC;IACvB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IACpC,KAAK,EAAE,CAAC;SACL,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,GAAG,CAAC,GAAG,CAAC;SACR,KAAK,CAAC,mBAAmB,EAAE,wBAAwB,CAAC;IACvD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;CACjD,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@droplinked_inc/wallet-connection",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Wallet connection adapters for droplinked (MetaMask, Coinbase, WalletConnect, Phantom). Hardened recover+rewrite of the original @droplinked/wallet-connection.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"CHANGELOG.md",
|
|
19
|
+
"LICENSE",
|
|
20
|
+
"THREAT_MODEL.md"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public",
|
|
24
|
+
"provenance": false
|
|
25
|
+
},
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@noble/ed25519": "^2.1.0",
|
|
29
|
+
"viem": "^2.21.0",
|
|
30
|
+
"zod": "^3.23.8"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/jest": "^29.5.12",
|
|
34
|
+
"@types/node": "^22.5.0",
|
|
35
|
+
"fast-check": "^3.22.0",
|
|
36
|
+
"typescript": "^5.6.0"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/droplinked/droplink-packages.git",
|
|
41
|
+
"directory": "packages/wallet-connection"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/droplinked/droplink-packages/tree/main/packages/wallet-connection#readme",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/droplinked/droplink-packages/issues"
|
|
46
|
+
},
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=22.0.0"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsc -p tsconfig.json",
|
|
52
|
+
"test": "jest",
|
|
53
|
+
"test:coverage": "jest --coverage",
|
|
54
|
+
"lint": "eslint src --max-warnings=0",
|
|
55
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
56
|
+
}
|
|
57
|
+
}
|