@wagmi/core 3.4.1 → 3.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/actions/sendTransaction.js.map +1 -1
- package/dist/esm/actions/sendTransactionSync.js.map +1 -1
- package/dist/esm/exports/tempo.js +1 -2
- package/dist/esm/exports/tempo.js.map +1 -1
- package/dist/esm/tempo/Connectors.js +278 -570
- 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/actions/deployContract.d.ts +2 -2
- package/dist/types/actions/deployContract.d.ts.map +1 -1
- package/dist/types/actions/sendTransaction.d.ts +5 -3
- package/dist/types/actions/sendTransaction.d.ts.map +1 -1
- package/dist/types/actions/sendTransactionSync.d.ts +5 -3
- package/dist/types/actions/sendTransactionSync.d.ts.map +1 -1
- package/dist/types/exports/tempo.d.ts +1 -2
- package/dist/types/exports/tempo.d.ts.map +1 -1
- package/dist/types/tempo/Connectors.d.ts +58 -86
- package/dist/types/tempo/Connectors.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +5 -1
- package/src/actions/deployContract.ts +3 -3
- package/src/actions/sendTransaction.ts +7 -5
- package/src/actions/sendTransactionSync.ts +7 -5
- package/src/exports/tempo.ts +2 -1
- package/src/tempo/Connectors.ts +406 -798
- package/src/version.ts +1 -1
- package/dist/esm/tempo/KeyManager.js +0 -154
- package/dist/esm/tempo/KeyManager.js.map +0 -1
- package/dist/types/tempo/KeyManager.d.ts +0 -71
- package/dist/types/tempo/KeyManager.d.ts.map +0 -1
- package/src/tempo/KeyManager.ts +0 -241
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '3.4.
|
|
1
|
+
export const version = '3.4.3'
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import * as Base64 from 'ox/Base64';
|
|
2
|
-
import * as Json from 'ox/Json';
|
|
3
|
-
import { createStorage, } from '../createStorage.js';
|
|
4
|
-
/** Instantiates a key manager. */
|
|
5
|
-
export function from(manager) {
|
|
6
|
-
return manager;
|
|
7
|
-
}
|
|
8
|
-
/** Instantiates a key manager from a Storage instance. */
|
|
9
|
-
export function fromStorage(storage) {
|
|
10
|
-
return from({
|
|
11
|
-
async getPublicKey(parameters) {
|
|
12
|
-
const publicKey = await storage.getItem(parameters.credential.id);
|
|
13
|
-
if (!publicKey)
|
|
14
|
-
throw new Error('publicKey not found.');
|
|
15
|
-
return publicKey;
|
|
16
|
-
},
|
|
17
|
-
async setPublicKey(parameters) {
|
|
18
|
-
await storage.setItem(parameters.credential.id, parameters.publicKey);
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Instantiates a key manager from a localStorage instance.
|
|
24
|
-
*
|
|
25
|
-
* WARNING: Do not use this in production.
|
|
26
|
-
* This is because we are unable to extract a user's public key after the registration
|
|
27
|
-
* process. If a user clears their storage, or visits the website on a different device,
|
|
28
|
-
* they will not be able to access their account.
|
|
29
|
-
*
|
|
30
|
-
* Instead, we recommend to set up a remote store such as [`KeyManager.http`](#http) to register
|
|
31
|
-
* public keys against their WebAuthn credential.
|
|
32
|
-
*
|
|
33
|
-
* @see {@link http}
|
|
34
|
-
*
|
|
35
|
-
* @deprecated
|
|
36
|
-
*/
|
|
37
|
-
export function localStorage(options = {}) {
|
|
38
|
-
const { key = 'wagmi.keyManager' } = options;
|
|
39
|
-
const storage = createStorage({
|
|
40
|
-
...options,
|
|
41
|
-
key,
|
|
42
|
-
storage: typeof window !== 'undefined' ? window.localStorage : undefined,
|
|
43
|
-
});
|
|
44
|
-
return fromStorage(storage);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Instantiates a key manager that uses HTTP endpoints for credential management.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```tsx
|
|
51
|
-
* import { KeyManager } from '@wagmi/core/tempo'
|
|
52
|
-
*
|
|
53
|
-
* const keyManager = KeyManager.http('https://api.example.com')
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
* @param url - The URL to use for the HTTP endpoints.
|
|
57
|
-
* @param options - Configuration options for HTTP endpoints.
|
|
58
|
-
* @returns A KeyManager instance that uses HTTP for credential operations.
|
|
59
|
-
*/
|
|
60
|
-
export function http(url, options = {}) {
|
|
61
|
-
const { fetch: fetchFn = globalThis.fetch } = options;
|
|
62
|
-
const { getChallenge, getPublicKey, setPublicKey } = (() => {
|
|
63
|
-
const base = typeof url === 'string' ? url : '';
|
|
64
|
-
const urls = typeof url === 'object' ? url : {};
|
|
65
|
-
return {
|
|
66
|
-
getChallenge: urls.getChallenge ?? `${base}/challenge`,
|
|
67
|
-
getPublicKey: urls.getPublicKey ?? `${base}/:credentialId`,
|
|
68
|
-
setPublicKey: urls.setPublicKey ?? `${base}/:credentialId`,
|
|
69
|
-
};
|
|
70
|
-
})();
|
|
71
|
-
return from({
|
|
72
|
-
async getChallenge() {
|
|
73
|
-
const request = getChallenge instanceof Request
|
|
74
|
-
? getChallenge
|
|
75
|
-
: new Request(getChallenge);
|
|
76
|
-
const response = await fetchFn(request);
|
|
77
|
-
if (!response.ok)
|
|
78
|
-
throw new Error(`Failed to get create options: ${response.statusText}`);
|
|
79
|
-
return await response.json();
|
|
80
|
-
},
|
|
81
|
-
async getPublicKey(parameters) {
|
|
82
|
-
const request = getPublicKey instanceof Request
|
|
83
|
-
? getPublicKey
|
|
84
|
-
: new Request(getPublicKey);
|
|
85
|
-
const response = await fetchFn(new Request(request.url.replace(':credentialId', parameters.credential.id), request));
|
|
86
|
-
if (!response.ok)
|
|
87
|
-
throw new Error(`Failed to get public key: ${response.statusText}`);
|
|
88
|
-
const data = await response.json();
|
|
89
|
-
return data.publicKey;
|
|
90
|
-
},
|
|
91
|
-
async setPublicKey(parameters) {
|
|
92
|
-
const request = setPublicKey instanceof Request
|
|
93
|
-
? setPublicKey
|
|
94
|
-
: new Request(setPublicKey);
|
|
95
|
-
const response = await fetchFn(new Request(request.url.replace(':credentialId', parameters.credential.id), request), {
|
|
96
|
-
method: 'POST',
|
|
97
|
-
headers: {
|
|
98
|
-
'Content-Type': 'application/json',
|
|
99
|
-
},
|
|
100
|
-
body: Json.stringify({
|
|
101
|
-
...parameters,
|
|
102
|
-
credential: serializeCredential(parameters.credential),
|
|
103
|
-
}),
|
|
104
|
-
});
|
|
105
|
-
if (!response.ok)
|
|
106
|
-
throw new Error(`Failed to set public key: ${response.statusText}`);
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Serializes a WebAuthn credential for JSON transmission.
|
|
112
|
-
* @internal
|
|
113
|
-
*/
|
|
114
|
-
function serializeCredential(credential) {
|
|
115
|
-
const response = credential.response;
|
|
116
|
-
return {
|
|
117
|
-
...credential,
|
|
118
|
-
rawId: Base64.fromBytes(new Uint8Array(credential.rawId)),
|
|
119
|
-
response: {
|
|
120
|
-
clientDataJSON: Base64.fromBytes(new Uint8Array(response.clientDataJSON)),
|
|
121
|
-
...('attestationObject' in response && {
|
|
122
|
-
attestationObject: Base64.fromBytes(new Uint8Array(response.attestationObject)),
|
|
123
|
-
}),
|
|
124
|
-
...('getAuthenticatorData' in response &&
|
|
125
|
-
typeof response.getAuthenticatorData === 'function' && {
|
|
126
|
-
authenticatorData: Base64.fromBytes(new Uint8Array(response.getAuthenticatorData.call(response))),
|
|
127
|
-
}),
|
|
128
|
-
...('getPublicKey' in response &&
|
|
129
|
-
typeof response.getPublicKey === 'function' && {
|
|
130
|
-
publicKey: Base64.fromBytes(new Uint8Array(response.getPublicKey.call(response))),
|
|
131
|
-
}),
|
|
132
|
-
...('getPublicKeyAlgorithm' in response &&
|
|
133
|
-
typeof response.getPublicKeyAlgorithm === 'function' && {
|
|
134
|
-
publicKeyAlgorithm: response.getPublicKeyAlgorithm.call(response),
|
|
135
|
-
}),
|
|
136
|
-
...('getTransports' in response &&
|
|
137
|
-
typeof response.getTransports === 'function' && {
|
|
138
|
-
transports: response.getTransports.call(response),
|
|
139
|
-
}),
|
|
140
|
-
...('authenticatorData' in response && {
|
|
141
|
-
authenticatorData: Base64.fromBytes(new Uint8Array(response.authenticatorData)),
|
|
142
|
-
}),
|
|
143
|
-
...('signature' in response && {
|
|
144
|
-
signature: Base64.fromBytes(new Uint8Array(response.signature)),
|
|
145
|
-
}),
|
|
146
|
-
...('userHandle' in response && response.userHandle
|
|
147
|
-
? {
|
|
148
|
-
userHandle: Base64.fromBytes(new Uint8Array(response.userHandle)),
|
|
149
|
-
}
|
|
150
|
-
: {}),
|
|
151
|
-
},
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
//# sourceMappingURL=KeyManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KeyManager.js","sourceRoot":"","sources":["../../../src/tempo/KeyManager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,WAAW,CAAA;AAEnC,OAAO,KAAK,IAAI,MAAM,SAAS,CAAA;AAC/B,OAAO,EAEL,aAAa,GAEd,MAAM,qBAAqB,CAAA;AAqB5B,kCAAkC;AAClC,MAAM,UAAU,IAAI,CAA6B,OAAgB;IAC/D,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,WAAW,CAAC,OAAgB;IAC1C,OAAO,IAAI,CAAC;QACV,KAAK,CAAC,YAAY,CAAC,UAAU;YAC3B,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;YACjE,IAAI,CAAC,SAAS;gBAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;YACvD,OAAO,SAAoB,CAAA;QAC7B,CAAC;QACD,KAAK,CAAC,YAAY,CAAC,UAAU;YAC3B,MAAM,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,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AC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAgB,CAAC,CACpE;aACF,CAAC;YACJ,GAAG,CAAC,uBAAuB,IAAI,QAAQ;gBACrC,OAAO,QAAQ,CAAC,qBAAqB,KAAK,UAAU,IAAI;gBACtD,kBAAkB,EAAE,QAAQ,CAAC,qBAAqB,CAAC,IAAI,CAAC,QAAQ,CAAC;aAClE,CAAC;YACJ,GAAG,CAAC,eAAe,IAAI,QAAQ;gBAC7B,OAAO,QAAQ,CAAC,aAAa,KAAK,UAAU,IAAI;gBAC9C,UAAU,EAAE,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC;aAClD,CAAC;YACJ,GAAG,CAAC,mBAAmB,IAAI,QAAQ,IAAI;gBACrC,iBAAiB,EAAE,MAAM,CAAC,SAAS,CACjC,IAAI,UAAU,CAAC,QAAQ,CAAC,iBAAgC,CAAC,CAC1D;aACF,CAAC;YACF,GAAG,CAAC,WAAW,IAAI,QAAQ,IAAI;gBAC7B,SAAS,EAAE,MAAM,CAAC,SAAS,CACzB,IAAI,UAAU,CAAC,QAAQ,CAAC,SAAwB,CAAC,CAClD;aACF,CAAC;YACF,GAAG,CAAC,YAAY,IAAI,QAAQ,IAAI,QAAQ,CAAC,UAAU;gBACjD,CAAC,CAAC;oBACE,UAAU,EAAE,MAAM,CAAC,SAAS,CAC1B,IAAI,UAAU,CAAC,QAAQ,CAAC,UAAyB,CAAC,CACnD;iBACF;gBACH,CAAC,CAAC,EAAE,CAAC;SACR;KACF,CAAA;AACH,CAAC"}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { WebAuthnP256 } from 'ox';
|
|
2
|
-
import type * as Hex from 'ox/Hex';
|
|
3
|
-
import { type CreateStorageParameters, type Storage } from '../createStorage.js';
|
|
4
|
-
export type KeyManager = {
|
|
5
|
-
/** Function to fetch create options for WebAuthn. */
|
|
6
|
-
getChallenge?: (() => Promise<{
|
|
7
|
-
challenge: Hex.Hex;
|
|
8
|
-
rp?: {
|
|
9
|
-
id: string;
|
|
10
|
-
name: string;
|
|
11
|
-
} | undefined;
|
|
12
|
-
}>) | undefined;
|
|
13
|
-
/** Function to fetch the public key for a credential. */
|
|
14
|
-
getPublicKey: (parameters: {
|
|
15
|
-
credential: WebAuthnP256.P256Credential['raw'];
|
|
16
|
-
}) => Promise<Hex.Hex>;
|
|
17
|
-
/** Function to set the public key for a credential. */
|
|
18
|
-
setPublicKey: (parameters: {
|
|
19
|
-
credential: WebAuthnP256.P256Credential['raw'];
|
|
20
|
-
publicKey: Hex.Hex;
|
|
21
|
-
}) => Promise<void>;
|
|
22
|
-
};
|
|
23
|
-
/** Instantiates a key manager. */
|
|
24
|
-
export declare function from<manager extends KeyManager>(manager: manager): manager;
|
|
25
|
-
/** Instantiates a key manager from a Storage instance. */
|
|
26
|
-
export declare function fromStorage(storage: Storage): KeyManager;
|
|
27
|
-
/**
|
|
28
|
-
* Instantiates a key manager from a localStorage instance.
|
|
29
|
-
*
|
|
30
|
-
* WARNING: Do not use this in production.
|
|
31
|
-
* This is because we are unable to extract a user's public key after the registration
|
|
32
|
-
* process. If a user clears their storage, or visits the website on a different device,
|
|
33
|
-
* they will not be able to access their account.
|
|
34
|
-
*
|
|
35
|
-
* Instead, we recommend to set up a remote store such as [`KeyManager.http`](#http) to register
|
|
36
|
-
* public keys against their WebAuthn credential.
|
|
37
|
-
*
|
|
38
|
-
* @see {@link http}
|
|
39
|
-
*
|
|
40
|
-
* @deprecated
|
|
41
|
-
*/
|
|
42
|
-
export declare function localStorage(options?: localStorage.Options): KeyManager;
|
|
43
|
-
export declare namespace localStorage {
|
|
44
|
-
type Options = Omit<CreateStorageParameters, 'storage'>;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Instantiates a key manager that uses HTTP endpoints for credential management.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```tsx
|
|
51
|
-
* import { KeyManager } from '@wagmi/core/tempo'
|
|
52
|
-
*
|
|
53
|
-
* const keyManager = KeyManager.http('https://api.example.com')
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
* @param url - The URL to use for the HTTP endpoints.
|
|
57
|
-
* @param options - Configuration options for HTTP endpoints.
|
|
58
|
-
* @returns A KeyManager instance that uses HTTP for credential operations.
|
|
59
|
-
*/
|
|
60
|
-
export declare function http(url: string | {
|
|
61
|
-
getChallenge?: string | Request | undefined;
|
|
62
|
-
getPublicKey?: string | Request | undefined;
|
|
63
|
-
setPublicKey?: string | Request | undefined;
|
|
64
|
-
}, options?: http.Options): KeyManager;
|
|
65
|
-
export declare namespace http {
|
|
66
|
-
type Options = {
|
|
67
|
-
/** Custom fetch function. @default `globalThis.fetch`. */
|
|
68
|
-
fetch?: typeof fetch | undefined;
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=KeyManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KeyManager.d.ts","sourceRoot":"","sources":["../../../src/tempo/KeyManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,IAAI,CAAA;AAEtC,OAAO,KAAK,KAAK,GAAG,MAAM,QAAQ,CAAA;AAElC,OAAO,EACL,KAAK,uBAAuB,EAE5B,KAAK,OAAO,EACb,MAAM,qBAAqB,CAAA;AAE5B,MAAM,MAAM,UAAU,GAAG;IACvB,qDAAqD;IACrD,YAAY,CAAC,EACT,CAAC,MAAM,OAAO,CAAC;QACb,SAAS,EAAE,GAAG,CAAC,GAAG,CAAA;QAClB,EAAE,CAAC,EAAE;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,GAAG,SAAS,CAAA;KAC9C,CAAC,CAAC,GACH,SAAS,CAAA;IACb,yDAAyD;IACzD,YAAY,EAAE,CAAC,UAAU,EAAE;QACzB,UAAU,EAAE,YAAY,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;KAC/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ox/Hex'
|
|
4
|
-
import * as Json from 'ox/Json'
|
|
5
|
-
import {
|
|
6
|
-
type CreateStorageParameters,
|
|
7
|
-
createStorage,
|
|
8
|
-
type Storage,
|
|
9
|
-
} from '../createStorage.js'
|
|
10
|
-
|
|
11
|
-
export type KeyManager = {
|
|
12
|
-
/** Function to fetch create options for WebAuthn. */
|
|
13
|
-
getChallenge?:
|
|
14
|
-
| (() => Promise<{
|
|
15
|
-
challenge: Hex.Hex
|
|
16
|
-
rp?: { id: string; name: string } | undefined
|
|
17
|
-
}>)
|
|
18
|
-
| undefined
|
|
19
|
-
/** Function to fetch the public key for a credential. */
|
|
20
|
-
getPublicKey: (parameters: {
|
|
21
|
-
credential: WebAuthnP256.P256Credential['raw']
|
|
22
|
-
}) => Promise<Hex.Hex>
|
|
23
|
-
/** Function to set the public key for a credential. */
|
|
24
|
-
setPublicKey: (parameters: {
|
|
25
|
-
credential: WebAuthnP256.P256Credential['raw']
|
|
26
|
-
publicKey: Hex.Hex
|
|
27
|
-
}) => Promise<void>
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Instantiates a key manager. */
|
|
31
|
-
export function from<manager extends KeyManager>(manager: manager): manager {
|
|
32
|
-
return manager
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** Instantiates a key manager from a Storage instance. */
|
|
36
|
-
export function fromStorage(storage: Storage): KeyManager {
|
|
37
|
-
return from({
|
|
38
|
-
async getPublicKey(parameters) {
|
|
39
|
-
const publicKey = await storage.getItem(parameters.credential.id)
|
|
40
|
-
if (!publicKey) throw new Error('publicKey not found.')
|
|
41
|
-
return publicKey as Hex.Hex
|
|
42
|
-
},
|
|
43
|
-
async setPublicKey(parameters) {
|
|
44
|
-
await storage.setItem(parameters.credential.id, parameters.publicKey)
|
|
45
|
-
},
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Instantiates a key manager from a localStorage instance.
|
|
51
|
-
*
|
|
52
|
-
* WARNING: Do not use this in production.
|
|
53
|
-
* This is because we are unable to extract a user's public key after the registration
|
|
54
|
-
* process. If a user clears their storage, or visits the website on a different device,
|
|
55
|
-
* they will not be able to access their account.
|
|
56
|
-
*
|
|
57
|
-
* Instead, we recommend to set up a remote store such as [`KeyManager.http`](#http) to register
|
|
58
|
-
* public keys against their WebAuthn credential.
|
|
59
|
-
*
|
|
60
|
-
* @see {@link http}
|
|
61
|
-
*
|
|
62
|
-
* @deprecated
|
|
63
|
-
*/
|
|
64
|
-
export function localStorage(options: localStorage.Options = {}) {
|
|
65
|
-
const { key = 'wagmi.keyManager' } = options
|
|
66
|
-
const storage = createStorage({
|
|
67
|
-
...options,
|
|
68
|
-
key,
|
|
69
|
-
storage: typeof window !== 'undefined' ? window.localStorage : undefined,
|
|
70
|
-
})
|
|
71
|
-
return fromStorage(storage)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export namespace localStorage {
|
|
75
|
-
export type Options = Omit<CreateStorageParameters, 'storage'>
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Instantiates a key manager that uses HTTP endpoints for credential management.
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```tsx
|
|
83
|
-
* import { KeyManager } from '@wagmi/core/tempo'
|
|
84
|
-
*
|
|
85
|
-
* const keyManager = KeyManager.http('https://api.example.com')
|
|
86
|
-
* ```
|
|
87
|
-
*
|
|
88
|
-
* @param url - The URL to use for the HTTP endpoints.
|
|
89
|
-
* @param options - Configuration options for HTTP endpoints.
|
|
90
|
-
* @returns A KeyManager instance that uses HTTP for credential operations.
|
|
91
|
-
*/
|
|
92
|
-
export function http(
|
|
93
|
-
url:
|
|
94
|
-
| string
|
|
95
|
-
| {
|
|
96
|
-
getChallenge?: string | Request | undefined
|
|
97
|
-
getPublicKey?: string | Request | undefined
|
|
98
|
-
setPublicKey?: string | Request | undefined
|
|
99
|
-
},
|
|
100
|
-
options: http.Options = {},
|
|
101
|
-
): KeyManager {
|
|
102
|
-
const { fetch: fetchFn = globalThis.fetch } = options
|
|
103
|
-
const { getChallenge, getPublicKey, setPublicKey } = (() => {
|
|
104
|
-
const base = typeof url === 'string' ? url : ''
|
|
105
|
-
const urls = typeof url === 'object' ? url : {}
|
|
106
|
-
return {
|
|
107
|
-
getChallenge: urls.getChallenge ?? `${base}/challenge`,
|
|
108
|
-
getPublicKey: urls.getPublicKey ?? `${base}/:credentialId`,
|
|
109
|
-
setPublicKey: urls.setPublicKey ?? `${base}/:credentialId`,
|
|
110
|
-
}
|
|
111
|
-
})()
|
|
112
|
-
|
|
113
|
-
return from({
|
|
114
|
-
async getChallenge() {
|
|
115
|
-
const request =
|
|
116
|
-
getChallenge instanceof Request
|
|
117
|
-
? getChallenge
|
|
118
|
-
: new Request(getChallenge)
|
|
119
|
-
|
|
120
|
-
const response = await fetchFn(request)
|
|
121
|
-
|
|
122
|
-
if (!response.ok)
|
|
123
|
-
throw new Error(`Failed to get create options: ${response.statusText}`)
|
|
124
|
-
return await response.json()
|
|
125
|
-
},
|
|
126
|
-
|
|
127
|
-
async getPublicKey(parameters) {
|
|
128
|
-
const request =
|
|
129
|
-
getPublicKey instanceof Request
|
|
130
|
-
? getPublicKey
|
|
131
|
-
: new Request(getPublicKey)
|
|
132
|
-
|
|
133
|
-
const response = await fetchFn(
|
|
134
|
-
new Request(
|
|
135
|
-
request.url.replace(':credentialId', parameters.credential.id),
|
|
136
|
-
request,
|
|
137
|
-
),
|
|
138
|
-
)
|
|
139
|
-
|
|
140
|
-
if (!response.ok)
|
|
141
|
-
throw new Error(`Failed to get public key: ${response.statusText}`)
|
|
142
|
-
const data = await response.json()
|
|
143
|
-
return data.publicKey as Hex.Hex
|
|
144
|
-
},
|
|
145
|
-
|
|
146
|
-
async setPublicKey(parameters) {
|
|
147
|
-
const request =
|
|
148
|
-
setPublicKey instanceof Request
|
|
149
|
-
? setPublicKey
|
|
150
|
-
: new Request(setPublicKey)
|
|
151
|
-
|
|
152
|
-
const response = await fetchFn(
|
|
153
|
-
new Request(
|
|
154
|
-
request.url.replace(':credentialId', parameters.credential.id),
|
|
155
|
-
request,
|
|
156
|
-
),
|
|
157
|
-
{
|
|
158
|
-
method: 'POST',
|
|
159
|
-
headers: {
|
|
160
|
-
'Content-Type': 'application/json',
|
|
161
|
-
},
|
|
162
|
-
body: Json.stringify({
|
|
163
|
-
...parameters,
|
|
164
|
-
credential: serializeCredential(parameters.credential),
|
|
165
|
-
}),
|
|
166
|
-
},
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
if (!response.ok)
|
|
170
|
-
throw new Error(`Failed to set public key: ${response.statusText}`)
|
|
171
|
-
},
|
|
172
|
-
})
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export namespace http {
|
|
176
|
-
export type Options = {
|
|
177
|
-
/** Custom fetch function. @default `globalThis.fetch`. */
|
|
178
|
-
fetch?: typeof fetch | undefined
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Serializes a WebAuthn credential for JSON transmission.
|
|
184
|
-
* @internal
|
|
185
|
-
*/
|
|
186
|
-
function serializeCredential(
|
|
187
|
-
credential: WebAuthnP256.P256Credential['raw'],
|
|
188
|
-
): Record<string, unknown> {
|
|
189
|
-
const response = credential.response
|
|
190
|
-
return {
|
|
191
|
-
...credential,
|
|
192
|
-
rawId: Base64.fromBytes(new Uint8Array(credential.rawId)),
|
|
193
|
-
response: {
|
|
194
|
-
clientDataJSON: Base64.fromBytes(new Uint8Array(response.clientDataJSON)),
|
|
195
|
-
...('attestationObject' in response && {
|
|
196
|
-
attestationObject: Base64.fromBytes(
|
|
197
|
-
new Uint8Array(response.attestationObject as ArrayBuffer),
|
|
198
|
-
),
|
|
199
|
-
}),
|
|
200
|
-
...('getAuthenticatorData' in response &&
|
|
201
|
-
typeof response.getAuthenticatorData === 'function' && {
|
|
202
|
-
authenticatorData: Base64.fromBytes(
|
|
203
|
-
new Uint8Array(
|
|
204
|
-
response.getAuthenticatorData.call(response) as ArrayBuffer,
|
|
205
|
-
),
|
|
206
|
-
),
|
|
207
|
-
}),
|
|
208
|
-
...('getPublicKey' in response &&
|
|
209
|
-
typeof response.getPublicKey === 'function' && {
|
|
210
|
-
publicKey: Base64.fromBytes(
|
|
211
|
-
new Uint8Array(response.getPublicKey.call(response) as ArrayBuffer),
|
|
212
|
-
),
|
|
213
|
-
}),
|
|
214
|
-
...('getPublicKeyAlgorithm' in response &&
|
|
215
|
-
typeof response.getPublicKeyAlgorithm === 'function' && {
|
|
216
|
-
publicKeyAlgorithm: response.getPublicKeyAlgorithm.call(response),
|
|
217
|
-
}),
|
|
218
|
-
...('getTransports' in response &&
|
|
219
|
-
typeof response.getTransports === 'function' && {
|
|
220
|
-
transports: response.getTransports.call(response),
|
|
221
|
-
}),
|
|
222
|
-
...('authenticatorData' in response && {
|
|
223
|
-
authenticatorData: Base64.fromBytes(
|
|
224
|
-
new Uint8Array(response.authenticatorData as ArrayBuffer),
|
|
225
|
-
),
|
|
226
|
-
}),
|
|
227
|
-
...('signature' in response && {
|
|
228
|
-
signature: Base64.fromBytes(
|
|
229
|
-
new Uint8Array(response.signature as ArrayBuffer),
|
|
230
|
-
),
|
|
231
|
-
}),
|
|
232
|
-
...('userHandle' in response && response.userHandle
|
|
233
|
-
? {
|
|
234
|
-
userHandle: Base64.fromBytes(
|
|
235
|
-
new Uint8Array(response.userHandle as ArrayBuffer),
|
|
236
|
-
),
|
|
237
|
-
}
|
|
238
|
-
: {}),
|
|
239
|
-
},
|
|
240
|
-
}
|
|
241
|
-
}
|