@wagmi/core 3.3.2 → 3.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/actions/connect.js.map +1 -1
- package/dist/esm/tempo/Connectors.js +63 -18
- package/dist/esm/tempo/Connectors.js.map +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/tempo/Connectors.d.ts +17 -3
- package/dist/types/tempo/Connectors.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/actions/connect.ts +1 -1
- package/src/tempo/Connectors.ts +97 -21
- package/src/version.ts +1 -1
package/dist/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '3.3.
|
|
1
|
+
export const version = '3.3.4';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as Address from 'ox/Address';
|
|
2
|
+
import type * as Hex from 'ox/Hex';
|
|
2
3
|
import { KeyAuthorization } from 'ox/tempo';
|
|
3
4
|
import { type LocalAccount } from 'viem/accounts';
|
|
4
5
|
import { WebAuthnP256 } from 'viem/tempo';
|
|
@@ -16,7 +17,7 @@ export declare function webAuthn(options: webAuthn.Parameters): import("../conne
|
|
|
16
17
|
}, "request">, {
|
|
17
18
|
connect<withCapabilities extends boolean = false>(parameters: {
|
|
18
19
|
chainId?: number | undefined;
|
|
19
|
-
capabilities?: OneOf<{
|
|
20
|
+
capabilities?: (OneOf<{
|
|
20
21
|
label?: string | undefined;
|
|
21
22
|
type: "sign-up";
|
|
22
23
|
} | {
|
|
@@ -24,11 +25,24 @@ export declare function webAuthn(options: webAuthn.Parameters): import("../conne
|
|
|
24
25
|
type: "sign-in";
|
|
25
26
|
} | {
|
|
26
27
|
type?: undefined;
|
|
27
|
-
}>
|
|
28
|
+
}> & {
|
|
29
|
+
credential?: {
|
|
30
|
+
id: string;
|
|
31
|
+
publicKey: Hex.Hex;
|
|
32
|
+
} | undefined;
|
|
33
|
+
sign?: {
|
|
34
|
+
hash: Hex.Hex;
|
|
35
|
+
} | undefined;
|
|
36
|
+
}) | undefined;
|
|
28
37
|
isReconnecting?: boolean | undefined;
|
|
29
38
|
withCapabilities?: withCapabilities | boolean | undefined;
|
|
30
39
|
}): Promise<{
|
|
31
|
-
accounts: readonly
|
|
40
|
+
accounts: withCapabilities extends true ? readonly {
|
|
41
|
+
address: Address.Address;
|
|
42
|
+
capabilities: {
|
|
43
|
+
signature?: Hex.Hex | undefined;
|
|
44
|
+
};
|
|
45
|
+
}[] : readonly Address.Address[];
|
|
32
46
|
chainId: number;
|
|
33
47
|
}>;
|
|
34
48
|
}, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Connectors.d.ts","sourceRoot":"","sources":["../../../src/tempo/Connectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"Connectors.d.ts","sourceRoot":"","sources":["../../../src/tempo/Connectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,YAAY,CAAA;AACrC,OAAO,KAAK,KAAK,GAAG,MAAM,QAAQ,CAAA;AAElC,OAAO,EAAE,gBAAgB,EAAqB,MAAM,UAAU,CAAA;AAQ9D,OAAO,EAEL,KAAK,YAAY,EAElB,MAAM,eAAe,CAAA;AACtB,OAAO,EAEL,YAAY,EAGb,MAAM,YAAY,CAAA;AAGnB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,KAAK,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAElD,oDAAoD;AACpD,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC,UAAU,CAAA;AAIpD;;GAEG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,UAAU;;;;;YAmBzC,gBAAgB,SAAS,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AC;IAC3C,KAAY,UAAU,GAAG;QACvB,OAAO,CAAC,EAAE,YAAY,GAAG,SAAS,CAAA;KACnC,CAAA;CACF"}
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "3.3.
|
|
1
|
+
export declare const version = "3.3.4";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
package/src/actions/connect.ts
CHANGED
package/src/tempo/Connectors.ts
CHANGED
|
@@ -55,7 +55,7 @@ export function webAuthn(options: webAuthn.Parameters) {
|
|
|
55
55
|
connect<withCapabilities extends boolean = false>(parameters: {
|
|
56
56
|
chainId?: number | undefined
|
|
57
57
|
capabilities?:
|
|
58
|
-
| OneOf<
|
|
58
|
+
| (OneOf<
|
|
59
59
|
| {
|
|
60
60
|
label?: string | undefined
|
|
61
61
|
type: 'sign-up'
|
|
@@ -67,11 +67,26 @@ export function webAuthn(options: webAuthn.Parameters) {
|
|
|
67
67
|
| {
|
|
68
68
|
type?: undefined
|
|
69
69
|
}
|
|
70
|
-
>
|
|
70
|
+
> & {
|
|
71
|
+
credential?: { id: string; publicKey: Hex.Hex } | undefined
|
|
72
|
+
sign?:
|
|
73
|
+
| {
|
|
74
|
+
hash: Hex.Hex
|
|
75
|
+
}
|
|
76
|
+
| undefined
|
|
77
|
+
})
|
|
71
78
|
| undefined
|
|
72
79
|
isReconnecting?: boolean | undefined
|
|
73
80
|
withCapabilities?: withCapabilities | boolean | undefined
|
|
74
|
-
}): Promise<{
|
|
81
|
+
}): Promise<{
|
|
82
|
+
accounts: withCapabilities extends true
|
|
83
|
+
? readonly {
|
|
84
|
+
address: Address.Address
|
|
85
|
+
capabilities: { signature?: Hex.Hex | undefined }
|
|
86
|
+
}[]
|
|
87
|
+
: readonly Address.Address[]
|
|
88
|
+
chainId: number
|
|
89
|
+
}>
|
|
75
90
|
}
|
|
76
91
|
type Provider = Pick<EIP1193Provider, 'request'>
|
|
77
92
|
type StorageItem = {
|
|
@@ -98,6 +113,34 @@ export function webAuthn(options: webAuthn.Parameters) {
|
|
|
98
113
|
async connect(parameters = {}) {
|
|
99
114
|
const capabilities =
|
|
100
115
|
'capabilities' in parameters ? (parameters.capabilities ?? {}) : {}
|
|
116
|
+
const signHash =
|
|
117
|
+
'sign' in capabilities ? capabilities.sign?.hash : undefined
|
|
118
|
+
|
|
119
|
+
// Fast path: if a credential is provided directly, use it.
|
|
120
|
+
if ('credential' in capabilities && capabilities.credential) {
|
|
121
|
+
const credential =
|
|
122
|
+
capabilities.credential as WebAuthnP256.P256Credential
|
|
123
|
+
config.storage?.setItem(
|
|
124
|
+
'webAuthn.activeCredential',
|
|
125
|
+
normalizeValue(credential),
|
|
126
|
+
)
|
|
127
|
+
config.storage?.setItem(
|
|
128
|
+
'webAuthn.lastActiveCredential',
|
|
129
|
+
normalizeValue(credential),
|
|
130
|
+
)
|
|
131
|
+
account = Account.fromWebAuthnP256(credential, {
|
|
132
|
+
rpId: options.getOptions?.rpId ?? options.rpId,
|
|
133
|
+
})
|
|
134
|
+
const address = getAddress(account.address)
|
|
135
|
+
const chainId = parameters.chainId ?? config.chains[0]?.id
|
|
136
|
+
if (!chainId) throw new ChainNotConfiguredError()
|
|
137
|
+
return {
|
|
138
|
+
accounts: (parameters.withCapabilities
|
|
139
|
+
? [{ address }]
|
|
140
|
+
: [address]) as never,
|
|
141
|
+
chainId,
|
|
142
|
+
}
|
|
143
|
+
}
|
|
101
144
|
|
|
102
145
|
if (
|
|
103
146
|
accessKeyOptions?.strict &&
|
|
@@ -112,7 +155,12 @@ export function webAuthn(options: webAuthn.Parameters) {
|
|
|
112
155
|
// - a WebAuthn `credential` to instantiate an account
|
|
113
156
|
// - optionally, a `keyPair` to use as the access key for the account
|
|
114
157
|
// - optionally, a signed `keyAuthorization` to provision the access key
|
|
115
|
-
const {
|
|
158
|
+
const {
|
|
159
|
+
credential,
|
|
160
|
+
keyAuthorization,
|
|
161
|
+
keyPair,
|
|
162
|
+
signature: signedHash,
|
|
163
|
+
} = await (async () => {
|
|
116
164
|
// If the connection type is of "sign-up", we are going to create a new credential
|
|
117
165
|
// and provision an access key (if needed).
|
|
118
166
|
if (capabilities.type === 'sign-up') {
|
|
@@ -138,12 +186,14 @@ export function webAuthn(options: webAuthn.Parameters) {
|
|
|
138
186
|
})
|
|
139
187
|
|
|
140
188
|
// Get key pair (access key) to use for the account.
|
|
189
|
+
// Skip if signing a hash — access key provisioning is deferred.
|
|
141
190
|
const keyPair = await (async () => {
|
|
191
|
+
if (signHash) return undefined
|
|
142
192
|
if (!accessKeyOptions) return undefined
|
|
143
193
|
return await WebCryptoP256.createKeyPair()
|
|
144
194
|
})()
|
|
145
195
|
|
|
146
|
-
return { credential, keyPair }
|
|
196
|
+
return { credential, keyPair, signature: undefined }
|
|
147
197
|
}
|
|
148
198
|
|
|
149
199
|
// If we are not selecting an account, we will check if an active credential is present in
|
|
@@ -154,6 +204,12 @@ export function webAuthn(options: webAuthn.Parameters) {
|
|
|
154
204
|
)) as WebAuthnP256.getCredential.ReturnValue | undefined
|
|
155
205
|
|
|
156
206
|
if (credential) {
|
|
207
|
+
// If signing a hash, skip local keypair checks and return
|
|
208
|
+
// the stored credential — the hash will be signed via
|
|
209
|
+
// `account.sign` since `createCredential` cannot sign.
|
|
210
|
+
if (signHash)
|
|
211
|
+
return { credential, keyPair: undefined, signature: undefined }
|
|
212
|
+
|
|
157
213
|
// Get key pair (access key) to use for the account.
|
|
158
214
|
const keyPair = await (async () => {
|
|
159
215
|
if (!accessKeyOptions) return undefined
|
|
@@ -164,10 +220,11 @@ export function webAuthn(options: webAuthn.Parameters) {
|
|
|
164
220
|
})()
|
|
165
221
|
|
|
166
222
|
// If the access key provisioning is not in strict mode, return the credential and key pair (if exists).
|
|
167
|
-
if (!accessKeyOptions?.strict)
|
|
223
|
+
if (!accessKeyOptions?.strict)
|
|
224
|
+
return { credential, keyPair, signature: undefined }
|
|
168
225
|
|
|
169
226
|
// If a key pair is found, return the credential and key pair.
|
|
170
|
-
if (keyPair) return { credential, keyPair }
|
|
227
|
+
if (keyPair) return { credential, keyPair, signature: undefined }
|
|
171
228
|
|
|
172
229
|
// If we are reconnecting, throw an error if not found.
|
|
173
230
|
if (parameters.isReconnecting)
|
|
@@ -180,7 +237,9 @@ export function webAuthn(options: webAuthn.Parameters) {
|
|
|
180
237
|
// Discover credential
|
|
181
238
|
{
|
|
182
239
|
// Get key pair (access key) to use for the account.
|
|
240
|
+
// Skip if signing a hash — access key provisioning is deferred.
|
|
183
241
|
const keyPair = await (async () => {
|
|
242
|
+
if (signHash) return undefined
|
|
184
243
|
if (!accessKeyOptions) return undefined
|
|
185
244
|
return await WebCryptoP256.createKeyPair()
|
|
186
245
|
})()
|
|
@@ -188,12 +247,17 @@ export function webAuthn(options: webAuthn.Parameters) {
|
|
|
188
247
|
// If we are provisioning an access key, we will need to sign a key authorization.
|
|
189
248
|
// We will need the hash (digest) to sign, and the address of the access key to construct the key authorization.
|
|
190
249
|
const { hash, keyAuthorization_unsigned } = await (async () => {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
250
|
+
const accessKeyAddress = keyPair
|
|
251
|
+
? Address.fromPublicKey(keyPair.publicKey)
|
|
252
|
+
: undefined
|
|
253
|
+
|
|
254
|
+
if (!accessKeyAddress)
|
|
255
|
+
return { keyAuthorization_unsigned: undefined, hash: undefined }
|
|
256
|
+
|
|
194
257
|
const keyAuthorization_unsigned = KeyAuthorization.from({
|
|
195
|
-
...accessKeyOptions,
|
|
196
258
|
address: accessKeyAddress,
|
|
259
|
+
expiry: accessKeyOptions?.expiry,
|
|
260
|
+
strict: accessKeyOptions?.strict ?? false,
|
|
197
261
|
type: 'p256',
|
|
198
262
|
})
|
|
199
263
|
const hash = KeyAuthorization.getSignPayload(
|
|
@@ -216,23 +280,30 @@ export function webAuthn(options: webAuthn.Parameters) {
|
|
|
216
280
|
if (!publicKey) throw new Error('publicKey not found.')
|
|
217
281
|
return publicKey
|
|
218
282
|
},
|
|
219
|
-
hash,
|
|
283
|
+
hash: signHash ?? hash,
|
|
220
284
|
rpId: options.getOptions?.rpId ?? options.rpId,
|
|
221
285
|
})
|
|
222
286
|
|
|
287
|
+
const envelope = SignatureEnvelope.from({
|
|
288
|
+
metadata: credential.metadata,
|
|
289
|
+
signature: credential.signature,
|
|
290
|
+
publicKey: PublicKey.fromHex(credential.publicKey),
|
|
291
|
+
type: 'webAuthn',
|
|
292
|
+
})
|
|
293
|
+
|
|
223
294
|
const keyAuthorization = keyAuthorization_unsigned
|
|
224
295
|
? KeyAuthorization.from({
|
|
225
296
|
...keyAuthorization_unsigned,
|
|
226
|
-
signature:
|
|
227
|
-
metadata: credential.metadata,
|
|
228
|
-
signature: credential.signature,
|
|
229
|
-
publicKey: PublicKey.fromHex(credential.publicKey),
|
|
230
|
-
type: 'webAuthn',
|
|
231
|
-
}),
|
|
297
|
+
signature: envelope,
|
|
232
298
|
})
|
|
233
299
|
: undefined
|
|
234
300
|
|
|
235
|
-
|
|
301
|
+
const signature =
|
|
302
|
+
signHash && !keyAuthorization_unsigned
|
|
303
|
+
? SignatureEnvelope.serialize(envelope)
|
|
304
|
+
: undefined
|
|
305
|
+
|
|
306
|
+
return { credential, keyAuthorization, keyPair, signature }
|
|
236
307
|
}
|
|
237
308
|
})()
|
|
238
309
|
|
|
@@ -249,7 +320,12 @@ export function webAuthn(options: webAuthn.Parameters) {
|
|
|
249
320
|
rpId: options.getOptions?.rpId ?? options.rpId,
|
|
250
321
|
})
|
|
251
322
|
|
|
252
|
-
|
|
323
|
+
let signature: Hex.Hex | undefined
|
|
324
|
+
if (signHash && !signedHash) {
|
|
325
|
+
signature = await account.sign({ hash: signHash })
|
|
326
|
+
} else if (signedHash) {
|
|
327
|
+
signature = signedHash
|
|
328
|
+
} else if (keyPair) {
|
|
253
329
|
accessKey = Account.fromWebCryptoP256(keyPair, {
|
|
254
330
|
access: account,
|
|
255
331
|
})
|
|
@@ -307,7 +383,7 @@ export function webAuthn(options: webAuthn.Parameters) {
|
|
|
307
383
|
|
|
308
384
|
return {
|
|
309
385
|
accounts: (parameters.withCapabilities
|
|
310
|
-
? [{ address }]
|
|
386
|
+
? [{ address, capabilities: { signature } }]
|
|
311
387
|
: [address]) as never,
|
|
312
388
|
chainId,
|
|
313
389
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '3.3.
|
|
1
|
+
export const version = '3.3.4'
|