@metamask-previews/kyc-controller 0.0.0-preview-e57e5c3dc → 0.0.0-preview-c449b8da8
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 +0 -8
- package/README.md +2 -10
- package/dist/index.cjs +10 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -18
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +7 -18
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +9 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -24
- package/dist/KycController-method-action-types.cjs +0 -7
- package/dist/KycController-method-action-types.cjs.map +0 -1
- package/dist/KycController-method-action-types.d.cts +0 -168
- package/dist/KycController-method-action-types.d.cts.map +0 -1
- package/dist/KycController-method-action-types.d.mts +0 -168
- package/dist/KycController-method-action-types.d.mts.map +0 -1
- package/dist/KycController-method-action-types.mjs +0 -6
- package/dist/KycController-method-action-types.mjs.map +0 -1
- package/dist/KycController.cjs +0 -1085
- package/dist/KycController.cjs.map +0 -1
- package/dist/KycController.d.cts +0 -255
- package/dist/KycController.d.cts.map +0 -1
- package/dist/KycController.d.mts +0 -255
- package/dist/KycController.d.mts.map +0 -1
- package/dist/KycController.mjs +0 -1080
- package/dist/KycController.mjs.map +0 -1
- package/dist/KycService-method-action-types.cjs +0 -7
- package/dist/KycService-method-action-types.cjs.map +0 -1
- package/dist/KycService-method-action-types.d.cts +0 -121
- package/dist/KycService-method-action-types.d.cts.map +0 -1
- package/dist/KycService-method-action-types.d.mts +0 -121
- package/dist/KycService-method-action-types.d.mts.map +0 -1
- package/dist/KycService-method-action-types.mjs +0 -6
- package/dist/KycService-method-action-types.mjs.map +0 -1
- package/dist/KycService.cjs +0 -417
- package/dist/KycService.cjs.map +0 -1
- package/dist/KycService.d.cts +0 -307
- package/dist/KycService.d.cts.map +0 -1
- package/dist/KycService.d.mts +0 -307
- package/dist/KycService.d.mts.map +0 -1
- package/dist/KycService.mjs +0 -413
- package/dist/KycService.mjs.map +0 -1
- package/dist/countryCodes.cjs +0 -274
- package/dist/countryCodes.cjs.map +0 -1
- package/dist/countryCodes.d.cts +0 -18
- package/dist/countryCodes.d.cts.map +0 -1
- package/dist/countryCodes.d.mts +0 -18
- package/dist/countryCodes.d.mts.map +0 -1
- package/dist/countryCodes.mjs +0 -270
- package/dist/countryCodes.mjs.map +0 -1
- package/dist/crypto.cjs +0 -154
- package/dist/crypto.cjs.map +0 -1
- package/dist/crypto.d.cts +0 -84
- package/dist/crypto.d.cts.map +0 -1
- package/dist/crypto.d.mts +0 -84
- package/dist/crypto.d.mts.map +0 -1
- package/dist/crypto.mjs +0 -149
- package/dist/crypto.mjs.map +0 -1
- package/dist/encoding.cjs +0 -40
- package/dist/encoding.cjs.map +0 -1
- package/dist/encoding.d.cts +0 -24
- package/dist/encoding.d.cts.map +0 -1
- package/dist/encoding.d.mts +0 -24
- package/dist/encoding.d.mts.map +0 -1
- package/dist/encoding.mjs +0 -35
- package/dist/encoding.mjs.map +0 -1
- package/dist/selectors.cjs +0 -30
- package/dist/selectors.cjs.map +0 -1
- package/dist/selectors.d.cts +0 -24
- package/dist/selectors.d.cts.map +0 -1
- package/dist/selectors.d.mts +0 -24
- package/dist/selectors.d.mts.map +0 -1
- package/dist/selectors.mjs +0 -24
- package/dist/selectors.mjs.map +0 -1
- package/dist/types.cjs +0 -10
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts +0 -124
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts +0 -124
- package/dist/types.d.mts.map +0 -1
- package/dist/types.mjs +0 -9
- package/dist/types.mjs.map +0 -1
- package/dist/ukyc/constants.cjs +0 -75
- package/dist/ukyc/constants.cjs.map +0 -1
- package/dist/ukyc/constants.d.cts +0 -69
- package/dist/ukyc/constants.d.cts.map +0 -1
- package/dist/ukyc/constants.d.mts +0 -69
- package/dist/ukyc/constants.d.mts.map +0 -1
- package/dist/ukyc/constants.mjs +0 -72
- package/dist/ukyc/constants.mjs.map +0 -1
- package/dist/ukyc/deriveClientMaterial.cjs +0 -65
- package/dist/ukyc/deriveClientMaterial.cjs.map +0 -1
- package/dist/ukyc/deriveClientMaterial.d.cts +0 -54
- package/dist/ukyc/deriveClientMaterial.d.cts.map +0 -1
- package/dist/ukyc/deriveClientMaterial.d.mts +0 -54
- package/dist/ukyc/deriveClientMaterial.d.mts.map +0 -1
- package/dist/ukyc/deriveClientMaterial.mjs +0 -60
- package/dist/ukyc/deriveClientMaterial.mjs.map +0 -1
- package/dist/ukyc/jwtChain.cjs +0 -54
- package/dist/ukyc/jwtChain.cjs.map +0 -1
- package/dist/ukyc/jwtChain.d.cts +0 -40
- package/dist/ukyc/jwtChain.d.cts.map +0 -1
- package/dist/ukyc/jwtChain.d.mts +0 -40
- package/dist/ukyc/jwtChain.d.mts.map +0 -1
- package/dist/ukyc/jwtChain.mjs +0 -50
- package/dist/ukyc/jwtChain.mjs.map +0 -1
- package/dist/ukyc/localUserSecret.cjs +0 -98
- package/dist/ukyc/localUserSecret.cjs.map +0 -1
- package/dist/ukyc/localUserSecret.d.cts +0 -65
- package/dist/ukyc/localUserSecret.d.cts.map +0 -1
- package/dist/ukyc/localUserSecret.d.mts +0 -65
- package/dist/ukyc/localUserSecret.d.mts.map +0 -1
- package/dist/ukyc/localUserSecret.mjs +0 -92
- package/dist/ukyc/localUserSecret.mjs.map +0 -1
- package/dist/ukyc/storageAccessToken.cjs +0 -139
- package/dist/ukyc/storageAccessToken.cjs.map +0 -1
- package/dist/ukyc/storageAccessToken.d.cts +0 -99
- package/dist/ukyc/storageAccessToken.d.cts.map +0 -1
- package/dist/ukyc/storageAccessToken.d.mts +0 -99
- package/dist/ukyc/storageAccessToken.d.mts.map +0 -1
- package/dist/ukyc/storageAccessToken.mjs +0 -133
- package/dist/ukyc/storageAccessToken.mjs.map +0 -1
- package/dist/ukyc/testToken.cjs +0 -61
- package/dist/ukyc/testToken.cjs.map +0 -1
- package/dist/ukyc/testToken.d.cts +0 -50
- package/dist/ukyc/testToken.d.cts.map +0 -1
- package/dist/ukyc/testToken.d.mts +0 -50
- package/dist/ukyc/testToken.d.mts.map +0 -1
- package/dist/ukyc/testToken.mjs +0 -57
- package/dist/ukyc/testToken.mjs.map +0 -1
- package/dist/ukyc/wrapEncryptionKey.cjs +0 -28
- package/dist/ukyc/wrapEncryptionKey.cjs.map +0 -1
- package/dist/ukyc/wrapEncryptionKey.d.cts +0 -34
- package/dist/ukyc/wrapEncryptionKey.d.cts.map +0 -1
- package/dist/ukyc/wrapEncryptionKey.d.mts +0 -34
- package/dist/ukyc/wrapEncryptionKey.d.mts.map +0 -1
- package/dist/ukyc/wrapEncryptionKey.mjs +0 -25
- package/dist/ukyc/wrapEncryptionKey.mjs.map +0 -1
- package/dist/ukyc/wrapUserKey.cjs +0 -80
- package/dist/ukyc/wrapUserKey.cjs.map +0 -1
- package/dist/ukyc/wrapUserKey.d.cts +0 -26
- package/dist/ukyc/wrapUserKey.d.cts.map +0 -1
- package/dist/ukyc/wrapUserKey.d.mts +0 -26
- package/dist/ukyc/wrapUserKey.d.mts.map +0 -1
- package/dist/ukyc/wrapUserKey.mjs +0 -76
- package/dist/ukyc/wrapUserKey.mjs.map +0 -1
- package/dist/ukyc/wrappedRelayPayload.cjs +0 -32
- package/dist/ukyc/wrappedRelayPayload.cjs.map +0 -1
- package/dist/ukyc/wrappedRelayPayload.d.cts +0 -35
- package/dist/ukyc/wrappedRelayPayload.d.cts.map +0 -1
- package/dist/ukyc/wrappedRelayPayload.d.mts +0 -35
- package/dist/ukyc/wrappedRelayPayload.d.mts.map +0 -1
- package/dist/ukyc/wrappedRelayPayload.mjs +0 -28
- package/dist/ukyc/wrappedRelayPayload.mjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storageAccessToken.d.cts","sourceRoot":"","sources":["../../src/ukyc/storageAccessToken.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,kBAAk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;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAqCzD;AAeD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,4BAA4B,GACnC,sBAAsB,CAwDxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,iCAAiC,CAC/C,KAAK,EAAE,sBAAsB,GAC5B,MAAM,CAER"}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import type { UkycClientMaterial } from "./deriveClientMaterial.mjs";
|
|
2
|
-
/**
|
|
3
|
-
* Mints `storage_access_token` capabilities — the client-signed, scoped,
|
|
4
|
-
* session-bound proofs that authorize UKYC storage operations. See the
|
|
5
|
-
* architecture doc, section "Storage Authentication".
|
|
6
|
-
*
|
|
7
|
-
* The token is Ed25519 over RFC 8785 (JCS) canonical JSON of the payload. Only
|
|
8
|
-
* the client holds the private `signing_key`, so only the client can mint a
|
|
9
|
-
* token; a `read`/`write`-scoped token may then be handed to the Relay to
|
|
10
|
-
* present, but `delete` is never delegated.
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* Storage operations a `storage_access_token` can authorize.
|
|
14
|
-
*/
|
|
15
|
-
export type UkycStorageOperation = 'read' | 'write' | 'delete';
|
|
16
|
-
/**
|
|
17
|
-
* Who presents the token to UKYC storage. The Relay may only present
|
|
18
|
-
* `read`/`write` tokens; `delete` is always client-presented.
|
|
19
|
-
*/
|
|
20
|
-
export type UkycTokenPresenter = 'client' | 'idos-relay';
|
|
21
|
-
/**
|
|
22
|
-
* The signed `storage_access_token` payload. Field names are snake_case because
|
|
23
|
-
* they are canonicalized and hashed exactly as they appear on the wire.
|
|
24
|
-
*/
|
|
25
|
-
export type UkycStorageAccessTokenPayload = {
|
|
26
|
-
version: number;
|
|
27
|
-
/** Every verifier that may accept the token, e.g. UKYC Storage and idOS Kwil. */
|
|
28
|
-
aud: string[];
|
|
29
|
-
storage_id: string;
|
|
30
|
-
signing_public_key: string;
|
|
31
|
-
operations: UkycStorageOperation[];
|
|
32
|
-
presenter: UkycTokenPresenter;
|
|
33
|
-
/** UKYC session id. Required (and only present) when presenter is `idos-relay`. */
|
|
34
|
-
session_id?: string;
|
|
35
|
-
issued_at: string;
|
|
36
|
-
expires_at: string;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* The on-the-wire envelope: the payload plus its detached Ed25519 signature
|
|
40
|
-
* (base64url) over the JCS canonicalization of the payload.
|
|
41
|
-
*/
|
|
42
|
-
export type UkycStorageAccessToken = {
|
|
43
|
-
payload: UkycStorageAccessTokenPayload;
|
|
44
|
-
signature: string;
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Inputs for minting a `storage_access_token`.
|
|
48
|
-
*/
|
|
49
|
-
export type SignStorageAccessTokenParams = {
|
|
50
|
-
/** Client material derived from `local_user_secret`. */
|
|
51
|
-
material: UkycClientMaterial;
|
|
52
|
-
/** Operations the token authorizes. `delete` must be the sole operation. */
|
|
53
|
-
operations: UkycStorageOperation[];
|
|
54
|
-
/** Who will present the token. Defaults to `client`. */
|
|
55
|
-
presenter?: UkycTokenPresenter;
|
|
56
|
-
/** UKYC session id. Required when presenter is `idos-relay`. */
|
|
57
|
-
sessionId?: string;
|
|
58
|
-
/** Token issue time. Defaults to now. */
|
|
59
|
-
issuedAt?: Date;
|
|
60
|
-
/** Token expiry. Must be strictly after `issuedAt`. */
|
|
61
|
-
expiresAt: Date;
|
|
62
|
-
};
|
|
63
|
-
type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
64
|
-
[key: string]: JsonValue | undefined;
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* Serializes a JSON value to RFC 8785 (JCS) canonical form.
|
|
68
|
-
*
|
|
69
|
-
* Scope note: this implementation covers the JSON shapes used by UKYC storage
|
|
70
|
-
* payloads — objects, arrays, strings, integers, booleans, and null. Object
|
|
71
|
-
* members are sorted by their UTF-16 code units (matching JS default string
|
|
72
|
-
* ordering, which is what JCS requires) and `undefined` members are dropped.
|
|
73
|
-
* Non-finite and non-integer numbers are rejected, since the payloads never
|
|
74
|
-
* contain them and correct JCS number formatting for the general case is
|
|
75
|
-
* intentionally out of scope here.
|
|
76
|
-
*
|
|
77
|
-
* @param value - The value to canonicalize.
|
|
78
|
-
* @returns The canonical JSON string.
|
|
79
|
-
*/
|
|
80
|
-
export declare function canonicalizeJson(value: JsonValue): string;
|
|
81
|
-
/**
|
|
82
|
-
* Builds and signs a `storage_access_token`.
|
|
83
|
-
*
|
|
84
|
-
* @param params - See {@link SignStorageAccessTokenParams}.
|
|
85
|
-
* @returns The signed token envelope.
|
|
86
|
-
*/
|
|
87
|
-
export declare function signStorageAccessToken(params: SignStorageAccessTokenParams): UkycStorageAccessToken;
|
|
88
|
-
/**
|
|
89
|
-
* Serializes a signed token to a compact string suitable for header transport
|
|
90
|
-
* (`Authorization: AccessToken <token>`, see `UKYC_CAPABILITY_AUTH_SCHEME`). The
|
|
91
|
-
* complete envelope is base64url-encoded; the private `signing_key` is never
|
|
92
|
-
* included.
|
|
93
|
-
*
|
|
94
|
-
* @param token - The signed token envelope.
|
|
95
|
-
* @returns The base64url-encoded envelope string.
|
|
96
|
-
*/
|
|
97
|
-
export declare function encodeStorageAccessTokenForHeader(token: UkycStorageAccessToken): string;
|
|
98
|
-
export {};
|
|
99
|
-
//# sourceMappingURL=storageAccessToken.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storageAccessToken.d.mts","sourceRoot":"","sources":["../../src/ukyc/storageAccessToken.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mCAAkC;AAGpE;;;;;;;;;GASG;AAEH;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE/D;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,YAAY,CAAC;AAEzD;;;GAGG;AACH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/C,KAAK,EAAE,sBAAsB,GAC5B,MAAM,CAER"}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { stringToBytes } from "@metamask/utils";
|
|
2
|
-
import { ed25519 } from "@noble/curves/ed25519";
|
|
3
|
-
import { UKYC_STORAGE_ACCESS_TOKEN_AUDIENCES, UKYC_STORAGE_ACCESS_TOKEN_VERSION } from "./constants.mjs";
|
|
4
|
-
import { toBase64Url } from "../encoding.mjs";
|
|
5
|
-
/**
|
|
6
|
-
* Serializes a JSON value to RFC 8785 (JCS) canonical form.
|
|
7
|
-
*
|
|
8
|
-
* Scope note: this implementation covers the JSON shapes used by UKYC storage
|
|
9
|
-
* payloads — objects, arrays, strings, integers, booleans, and null. Object
|
|
10
|
-
* members are sorted by their UTF-16 code units (matching JS default string
|
|
11
|
-
* ordering, which is what JCS requires) and `undefined` members are dropped.
|
|
12
|
-
* Non-finite and non-integer numbers are rejected, since the payloads never
|
|
13
|
-
* contain them and correct JCS number formatting for the general case is
|
|
14
|
-
* intentionally out of scope here.
|
|
15
|
-
*
|
|
16
|
-
* @param value - The value to canonicalize.
|
|
17
|
-
* @returns The canonical JSON string.
|
|
18
|
-
*/
|
|
19
|
-
export function canonicalizeJson(value) {
|
|
20
|
-
if (value === null) {
|
|
21
|
-
return 'null';
|
|
22
|
-
}
|
|
23
|
-
if (typeof value === 'boolean') {
|
|
24
|
-
return value ? 'true' : 'false';
|
|
25
|
-
}
|
|
26
|
-
if (typeof value === 'number') {
|
|
27
|
-
if (!Number.isInteger(value)) {
|
|
28
|
-
throw new Error('UKYC: cannot canonicalize a non-integer number for JCS.');
|
|
29
|
-
}
|
|
30
|
-
return JSON.stringify(value);
|
|
31
|
-
}
|
|
32
|
-
if (typeof value === 'string') {
|
|
33
|
-
return JSON.stringify(value);
|
|
34
|
-
}
|
|
35
|
-
if (Array.isArray(value)) {
|
|
36
|
-
return `[${value.map((item) => canonicalizeJson(item)).join(',')}]`;
|
|
37
|
-
}
|
|
38
|
-
const entries = Object.keys(value)
|
|
39
|
-
.sort()
|
|
40
|
-
.reduce((acc, key) => {
|
|
41
|
-
const child = value[key];
|
|
42
|
-
if (child !== undefined) {
|
|
43
|
-
acc.push(`${JSON.stringify(key)}:${canonicalizeJson(child)}`);
|
|
44
|
-
}
|
|
45
|
-
return acc;
|
|
46
|
-
}, []);
|
|
47
|
-
return `{${entries.join(',')}}`;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Formats a date as RFC 3339 UTC with whole-second precision (e.g.
|
|
51
|
-
* `2026-07-07T00:00:00Z`). `Date.prototype.toISOString` always emits
|
|
52
|
-
* milliseconds (`...:00.000Z`); the `storage_access_token` wire format omits
|
|
53
|
-
* fractional seconds, so the sub-second component is truncated (not rounded).
|
|
54
|
-
*
|
|
55
|
-
* @param date - The date to format.
|
|
56
|
-
* @returns The RFC 3339 timestamp without fractional seconds.
|
|
57
|
-
*/
|
|
58
|
-
function toRfc3339Seconds(date) {
|
|
59
|
-
return `${date.toISOString().slice(0, 19)}Z`;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Builds and signs a `storage_access_token`.
|
|
63
|
-
*
|
|
64
|
-
* @param params - See {@link SignStorageAccessTokenParams}.
|
|
65
|
-
* @returns The signed token envelope.
|
|
66
|
-
*/
|
|
67
|
-
export function signStorageAccessToken(params) {
|
|
68
|
-
const { material, operations, presenter = 'client', sessionId, issuedAt = new Date(), expiresAt, } = params;
|
|
69
|
-
assertValidOperations(operations);
|
|
70
|
-
if (expiresAt.getTime() <= issuedAt.getTime()) {
|
|
71
|
-
throw new Error('UKYC: storage_access_token expires_at must be after issued_at.');
|
|
72
|
-
}
|
|
73
|
-
const isDelete = operations.includes('delete');
|
|
74
|
-
if (presenter === 'idos-relay' && isDelete) {
|
|
75
|
-
throw new Error('UKYC: a delete-scoped storage_access_token cannot be delegated to the Relay.');
|
|
76
|
-
}
|
|
77
|
-
if (presenter === 'idos-relay' && !sessionId) {
|
|
78
|
-
throw new Error('UKYC: a Relay-presented storage_access_token requires a session_id.');
|
|
79
|
-
}
|
|
80
|
-
const payload = {
|
|
81
|
-
version: UKYC_STORAGE_ACCESS_TOKEN_VERSION,
|
|
82
|
-
aud: [...UKYC_STORAGE_ACCESS_TOKEN_AUDIENCES],
|
|
83
|
-
storage_id: toBase64Url(material.storageId),
|
|
84
|
-
signing_public_key: toBase64Url(material.signingPublicKey),
|
|
85
|
-
operations,
|
|
86
|
-
presenter,
|
|
87
|
-
issued_at: toRfc3339Seconds(issuedAt),
|
|
88
|
-
expires_at: toRfc3339Seconds(expiresAt),
|
|
89
|
-
};
|
|
90
|
-
// Only bind session_id for Relay-presented tokens; omit the key entirely for
|
|
91
|
-
// client-presented tokens so it does not appear in the canonicalized payload.
|
|
92
|
-
if (presenter === 'idos-relay') {
|
|
93
|
-
payload.session_id = sessionId;
|
|
94
|
-
}
|
|
95
|
-
const message = stringToBytes(canonicalizeJson(payload));
|
|
96
|
-
const signature = ed25519.sign(message, material.signingKey);
|
|
97
|
-
return {
|
|
98
|
-
payload,
|
|
99
|
-
signature: toBase64Url(signature),
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Serializes a signed token to a compact string suitable for header transport
|
|
104
|
-
* (`Authorization: AccessToken <token>`, see `UKYC_CAPABILITY_AUTH_SCHEME`). The
|
|
105
|
-
* complete envelope is base64url-encoded; the private `signing_key` is never
|
|
106
|
-
* included.
|
|
107
|
-
*
|
|
108
|
-
* @param token - The signed token envelope.
|
|
109
|
-
* @returns The base64url-encoded envelope string.
|
|
110
|
-
*/
|
|
111
|
-
export function encodeStorageAccessTokenForHeader(token) {
|
|
112
|
-
return toBase64Url(stringToBytes(JSON.stringify(token)));
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Validates that an operations list is one storage understands: a non-empty set
|
|
116
|
-
* of `read`/`write`, or exactly `['delete']`. `delete` is never combined with
|
|
117
|
-
* other operations.
|
|
118
|
-
*
|
|
119
|
-
* @param operations - The requested operations.
|
|
120
|
-
*/
|
|
121
|
-
function assertValidOperations(operations) {
|
|
122
|
-
if (operations.length === 0) {
|
|
123
|
-
throw new Error('UKYC: storage_access_token requires at least one operation.');
|
|
124
|
-
}
|
|
125
|
-
const unique = new Set(operations);
|
|
126
|
-
if (unique.size !== operations.length) {
|
|
127
|
-
throw new Error('UKYC: storage_access_token operations must be unique.');
|
|
128
|
-
}
|
|
129
|
-
if (unique.has('delete') && operations.length > 1) {
|
|
130
|
-
throw new Error('UKYC: a delete-scoped storage_access_token must contain only "delete".');
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
//# sourceMappingURL=storageAccessToken.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storageAccessToken.mjs","sourceRoot":"","sources":["../../src/ukyc/storageAccessToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,wBAAwB;AAChD,OAAO,EAAE,OAAO,EAAE,8BAA8B;AAEhD,OAAO,EACL,mCAAmC,EACnC,iCAAiC,EAClC,wBAAuB;AAExB,OAAO,EAAE,WAAW,EAAE,wBAAuB;AAiF7C;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAgB;IAC/C,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAClC,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CACb,yDAAyD,CAC1D,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC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;IAE7B,OAAO,WAAW,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;;GAMG;AACH,SAAS,qBAAqB,CAAC,UAAkC;IAC/D,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CACb,6DAA6D,CAC9D,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;IAEnC,IAAI,MAAM,CAAC,IAAI,KAAK,UAAU,CAAC,MAAM,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC3E,CAAC;IAED,IAAI,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CACb,wEAAwE,CACzE,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import { stringToBytes } from '@metamask/utils';\nimport { ed25519 } from '@noble/curves/ed25519';\n\nimport {\n UKYC_STORAGE_ACCESS_TOKEN_AUDIENCES,\n UKYC_STORAGE_ACCESS_TOKEN_VERSION,\n} from './constants.js';\nimport type { UkycClientMaterial } from './deriveClientMaterial.js';\nimport { toBase64Url } from '../encoding.js';\n\n/**\n * Mints `storage_access_token` capabilities — the client-signed, scoped,\n * session-bound proofs that authorize UKYC storage operations. See the\n * architecture doc, section \"Storage Authentication\".\n *\n * The token is Ed25519 over RFC 8785 (JCS) canonical JSON of the payload. Only\n * the client holds the private `signing_key`, so only the client can mint a\n * token; a `read`/`write`-scoped token may then be handed to the Relay to\n * present, but `delete` is never delegated.\n */\n\n/**\n * Storage operations a `storage_access_token` can authorize.\n */\nexport type UkycStorageOperation = 'read' | 'write' | 'delete';\n\n/**\n * Who presents the token to UKYC storage. The Relay may only present\n * `read`/`write` tokens; `delete` is always client-presented.\n */\nexport type UkycTokenPresenter = 'client' | 'idos-relay';\n\n/**\n * The signed `storage_access_token` payload. Field names are snake_case because\n * they are canonicalized and hashed exactly as they appear on the wire.\n */\nexport type UkycStorageAccessTokenPayload = {\n version: number;\n /** Every verifier that may accept the token, e.g. UKYC Storage and idOS Kwil. */\n aud: string[];\n // Wire-shape fields are snake_case; they are canonicalized and signed exactly\n // as they appear on the wire.\n /* eslint-disable @typescript-eslint/naming-convention */\n storage_id: string;\n signing_public_key: string;\n operations: UkycStorageOperation[];\n presenter: UkycTokenPresenter;\n /** UKYC session id. Required (and only present) when presenter is `idos-relay`. */\n session_id?: string;\n issued_at: string;\n expires_at: string;\n /* eslint-enable @typescript-eslint/naming-convention */\n};\n\n/**\n * The on-the-wire envelope: the payload plus its detached Ed25519 signature\n * (base64url) over the JCS canonicalization of the payload.\n */\nexport type UkycStorageAccessToken = {\n payload: UkycStorageAccessTokenPayload;\n signature: string;\n};\n\n/**\n * Inputs for minting a `storage_access_token`.\n */\nexport type SignStorageAccessTokenParams = {\n /** Client material derived from `local_user_secret`. */\n material: UkycClientMaterial;\n /** Operations the token authorizes. `delete` must be the sole operation. */\n operations: UkycStorageOperation[];\n /** Who will present the token. Defaults to `client`. */\n presenter?: UkycTokenPresenter;\n /** UKYC session id. Required when presenter is `idos-relay`. */\n sessionId?: string;\n /** Token issue time. Defaults to now. */\n issuedAt?: Date;\n /** Token expiry. Must be strictly after `issuedAt`. */\n expiresAt: Date;\n};\n\ntype JsonValue =\n | null\n | boolean\n | number\n | string\n | JsonValue[]\n | { [key: string]: JsonValue | undefined };\n\n/**\n * Serializes a JSON value to RFC 8785 (JCS) canonical form.\n *\n * Scope note: this implementation covers the JSON shapes used by UKYC storage\n * payloads — objects, arrays, strings, integers, booleans, and null. Object\n * members are sorted by their UTF-16 code units (matching JS default string\n * ordering, which is what JCS requires) and `undefined` members are dropped.\n * Non-finite and non-integer numbers are rejected, since the payloads never\n * contain them and correct JCS number formatting for the general case is\n * intentionally out of scope here.\n *\n * @param value - The value to canonicalize.\n * @returns The canonical JSON string.\n */\nexport function canonicalizeJson(value: JsonValue): string {\n if (value === null) {\n return 'null';\n }\n\n if (typeof value === 'boolean') {\n return value ? 'true' : 'false';\n }\n\n if (typeof value === 'number') {\n if (!Number.isInteger(value)) {\n throw new Error(\n 'UKYC: cannot canonicalize a non-integer number for JCS.',\n );\n }\n return JSON.stringify(value);\n }\n\n if (typeof value === 'string') {\n return JSON.stringify(value);\n }\n\n if (Array.isArray(value)) {\n return `[${value.map((item) => canonicalizeJson(item)).join(',')}]`;\n }\n\n const entries = Object.keys(value)\n .sort()\n .reduce<string[]>((acc, key) => {\n const child = value[key];\n if (child !== undefined) {\n acc.push(`${JSON.stringify(key)}:${canonicalizeJson(child)}`);\n }\n return acc;\n }, []);\n\n return `{${entries.join(',')}}`;\n}\n\n/**\n * Formats a date as RFC 3339 UTC with whole-second precision (e.g.\n * `2026-07-07T00:00:00Z`). `Date.prototype.toISOString` always emits\n * milliseconds (`...:00.000Z`); the `storage_access_token` wire format omits\n * fractional seconds, so the sub-second component is truncated (not rounded).\n *\n * @param date - The date to format.\n * @returns The RFC 3339 timestamp without fractional seconds.\n */\nfunction toRfc3339Seconds(date: Date): string {\n return `${date.toISOString().slice(0, 19)}Z`;\n}\n\n/**\n * Builds and signs a `storage_access_token`.\n *\n * @param params - See {@link SignStorageAccessTokenParams}.\n * @returns The signed token envelope.\n */\nexport function signStorageAccessToken(\n params: SignStorageAccessTokenParams,\n): UkycStorageAccessToken {\n const {\n material,\n operations,\n presenter = 'client',\n sessionId,\n issuedAt = new Date(),\n expiresAt,\n } = params;\n\n assertValidOperations(operations);\n\n if (expiresAt.getTime() <= issuedAt.getTime()) {\n throw new Error(\n 'UKYC: storage_access_token expires_at must be after issued_at.',\n );\n }\n\n const isDelete = operations.includes('delete');\n\n if (presenter === 'idos-relay' && isDelete) {\n throw new Error(\n 'UKYC: a delete-scoped storage_access_token cannot be delegated to the Relay.',\n );\n }\n\n if (presenter === 'idos-relay' && !sessionId) {\n throw new Error(\n 'UKYC: a Relay-presented storage_access_token requires a session_id.',\n );\n }\n\n const payload: UkycStorageAccessTokenPayload = {\n version: UKYC_STORAGE_ACCESS_TOKEN_VERSION,\n aud: [...UKYC_STORAGE_ACCESS_TOKEN_AUDIENCES],\n storage_id: toBase64Url(material.storageId),\n signing_public_key: toBase64Url(material.signingPublicKey),\n operations,\n presenter,\n issued_at: toRfc3339Seconds(issuedAt),\n expires_at: toRfc3339Seconds(expiresAt),\n };\n\n // Only bind session_id for Relay-presented tokens; omit the key entirely for\n // client-presented tokens so it does not appear in the canonicalized payload.\n if (presenter === 'idos-relay') {\n payload.session_id = sessionId;\n }\n\n const message = stringToBytes(canonicalizeJson(payload));\n const signature = ed25519.sign(message, material.signingKey);\n\n return {\n payload,\n signature: toBase64Url(signature),\n };\n}\n\n/**\n * Serializes a signed token to a compact string suitable for header transport\n * (`Authorization: AccessToken <token>`, see `UKYC_CAPABILITY_AUTH_SCHEME`). The\n * complete envelope is base64url-encoded; the private `signing_key` is never\n * included.\n *\n * @param token - The signed token envelope.\n * @returns The base64url-encoded envelope string.\n */\nexport function encodeStorageAccessTokenForHeader(\n token: UkycStorageAccessToken,\n): string {\n return toBase64Url(stringToBytes(JSON.stringify(token)));\n}\n\n/**\n * Validates that an operations list is one storage understands: a non-empty set\n * of `read`/`write`, or exactly `['delete']`. `delete` is never combined with\n * other operations.\n *\n * @param operations - The requested operations.\n */\nfunction assertValidOperations(operations: UkycStorageOperation[]): void {\n if (operations.length === 0) {\n throw new Error(\n 'UKYC: storage_access_token requires at least one operation.',\n );\n }\n\n const unique = new Set(operations);\n\n if (unique.size !== operations.length) {\n throw new Error('UKYC: storage_access_token operations must be unique.');\n }\n\n if (unique.has('delete') && operations.length > 1) {\n throw new Error(\n 'UKYC: a delete-scoped storage_access_token must contain only \"delete\".',\n );\n }\n}\n"]}
|
package/dist/ukyc/testToken.cjs
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mintUkycTestToken = void 0;
|
|
4
|
-
const utils_1 = require("@noble/hashes/utils");
|
|
5
|
-
const constants_js_1 = require("./constants.cjs");
|
|
6
|
-
const deriveClientMaterial_js_1 = require("./deriveClientMaterial.cjs");
|
|
7
|
-
const storageAccessToken_js_1 = require("./storageAccessToken.cjs");
|
|
8
|
-
/**
|
|
9
|
-
* Mints ready-to-use UKYC `storage_access_token`s for testing UKYC Storage.
|
|
10
|
-
*
|
|
11
|
-
* This composes the same pure functions the MetaMask client uses in production
|
|
12
|
-
* (`deriveClientMaterial` + `signStorageAccessToken`), so a third party such as
|
|
13
|
-
* idOS can produce a valid, signed token without deriving one on-device. No
|
|
14
|
-
* server "fills in" the `signing_public_key`: it is derived from a
|
|
15
|
-
* `local_user_secret` the caller controls and registered on first write, so
|
|
16
|
-
* reusing the same secret yields a stable `storage_id` and controlling key.
|
|
17
|
-
*/
|
|
18
|
-
/** Default token lifetime when `expiresAt` is not supplied (4 hours). */
|
|
19
|
-
const DEFAULT_TOKEN_LIFETIME_MS = 4 * 60 * 60 * 1000;
|
|
20
|
-
/**
|
|
21
|
-
* Resolves the caller-supplied secret into raw bytes, generating a random one
|
|
22
|
-
* when none is provided.
|
|
23
|
-
*
|
|
24
|
-
* @param secret - Raw 32 bytes, a hex string, or undefined for a random secret.
|
|
25
|
-
* @returns The `local_user_secret` bytes.
|
|
26
|
-
*/
|
|
27
|
-
function resolveLocalUserSecret(secret) {
|
|
28
|
-
if (secret === undefined) {
|
|
29
|
-
return (0, utils_1.randomBytes)(constants_js_1.UKYC_LOCAL_USER_SECRET_SIZE_BYTES);
|
|
30
|
-
}
|
|
31
|
-
return typeof secret === 'string' ? (0, utils_1.hexToBytes)(secret) : secret;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Mints a signed UKYC `storage_access_token` for testing.
|
|
35
|
-
*
|
|
36
|
-
* @param params - See {@link MintUkycTestTokenParams}.
|
|
37
|
-
* @returns The token, its `Authorization` header, and the derived identifiers.
|
|
38
|
-
*/
|
|
39
|
-
function mintUkycTestToken(params = {}) {
|
|
40
|
-
const { operations = ['read'], presenter, sessionId, issuedAt = new Date(), expiresAt = new Date(issuedAt.getTime() + DEFAULT_TOKEN_LIFETIME_MS), } = params;
|
|
41
|
-
const localUserSecret = resolveLocalUserSecret(params.localUserSecret);
|
|
42
|
-
const material = (0, deriveClientMaterial_js_1.deriveClientMaterial)(localUserSecret);
|
|
43
|
-
const token = (0, storageAccessToken_js_1.signStorageAccessToken)({
|
|
44
|
-
material,
|
|
45
|
-
operations,
|
|
46
|
-
presenter,
|
|
47
|
-
sessionId,
|
|
48
|
-
issuedAt,
|
|
49
|
-
expiresAt,
|
|
50
|
-
});
|
|
51
|
-
const { storageId, signingPublicKey } = (0, deriveClientMaterial_js_1.encodeClientMaterial)(material);
|
|
52
|
-
return {
|
|
53
|
-
localUserSecret: (0, utils_1.bytesToHex)(localUserSecret),
|
|
54
|
-
storageId,
|
|
55
|
-
signingPublicKey,
|
|
56
|
-
token,
|
|
57
|
-
authorizationHeader: `${constants_js_1.UKYC_CAPABILITY_AUTH_SCHEME} ${(0, storageAccessToken_js_1.encodeStorageAccessTokenForHeader)(token)}`,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
exports.mintUkycTestToken = mintUkycTestToken;
|
|
61
|
-
//# sourceMappingURL=testToken.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"testToken.cjs","sourceRoot":"","sources":["../../src/ukyc/testToken.ts"],"names":[],"mappings":";;;AAAA,+CAA0E;AAE1E,kDAGwB;AACxB,wEAGmC;AACnC,oEAGiC;AAOjC;;;;;;;;;GASG;AAEH,yEAAyE;AACzE,MAAM,yBAAyB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AA6CrD;;;;;;GAMG;AACH,SAAS,sBAAsB,CAAC,MAA4B;IAC1D,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,IAAA,mBAAW,EAAC,gDAAiC,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAA,kBAAU,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AAClE,CAAC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAC/B,SAAkC,EAAE;IAEpC,MAAM,EACJ,UAAU,GAAG,CAAC,MAAM,CAAC,EACrB,SAAS,EACT,SAAS,EACT,QAAQ,GAAG,IAAI,IAAI,EAAE,EACrB,SAAS,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,yBAAyB,CAAC,GACrE,GAAG,MAAM,CAAC;IAEX,MAAM,eAAe,GAAG,sBAAsB,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;IACvE,MAAM,QAAQ,GAAG,IAAA,8CAAoB,EAAC,eAAe,CAAC,CAAC;IAEvD,MAAM,KAAK,GAAG,IAAA,8CAAsB,EAAC;QACnC,QAAQ;QACR,UAAU;QACV,SAAS;QACT,SAAS;QACT,QAAQ;QACR,SAAS;KACV,CAAC,CAAC;IAEH,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,IAAA,8CAAoB,EAAC,QAAQ,CAAC,CAAC;IAEvE,OAAO;QACL,eAAe,EAAE,IAAA,kBAAU,EAAC,eAAe,CAAC;QAC5C,SAAS;QACT,gBAAgB;QAChB,KAAK;QACL,mBAAmB,EAAE,GAAG,0CAA2B,IAAI,IAAA,yDAAiC,EACtF,KAAK,CACN,EAAE;KACJ,CAAC;AACJ,CAAC;AAlCD,8CAkCC","sourcesContent":["import { bytesToHex, hexToBytes, randomBytes } from '@noble/hashes/utils';\n\nimport {\n UKYC_CAPABILITY_AUTH_SCHEME,\n UKYC_LOCAL_USER_SECRET_SIZE_BYTES,\n} from './constants.js';\nimport {\n deriveClientMaterial,\n encodeClientMaterial,\n} from './deriveClientMaterial.js';\nimport {\n encodeStorageAccessTokenForHeader,\n signStorageAccessToken,\n} from './storageAccessToken.js';\nimport type {\n UkycStorageAccessToken,\n UkycStorageOperation,\n UkycTokenPresenter,\n} from './storageAccessToken.js';\n\n/**\n * Mints ready-to-use UKYC `storage_access_token`s for testing UKYC Storage.\n *\n * This composes the same pure functions the MetaMask client uses in production\n * (`deriveClientMaterial` + `signStorageAccessToken`), so a third party such as\n * idOS can produce a valid, signed token without deriving one on-device. No\n * server \"fills in\" the `signing_public_key`: it is derived from a\n * `local_user_secret` the caller controls and registered on first write, so\n * reusing the same secret yields a stable `storage_id` and controlling key.\n */\n\n/** Default token lifetime when `expiresAt` is not supplied (4 hours). */\nconst DEFAULT_TOKEN_LIFETIME_MS = 4 * 60 * 60 * 1000;\n\n/**\n * Inputs for {@link mintUkycTestToken}. All fields are optional; the only value\n * a caller usually pins is `localUserSecret`, so `storage_id` and the signing\n * key stay stable across runs.\n */\nexport type MintUkycTestTokenParams = {\n /**\n * The root `local_user_secret`, as raw 32 bytes or a hex string. When omitted\n * a fresh random secret is generated (returned in the result so it can be\n * reused).\n */\n localUserSecret?: Uint8Array | string;\n /** Operations the token authorizes. Defaults to `['read']`. */\n operations?: UkycStorageOperation[];\n /** Who will present the token. Defaults to `client`. */\n presenter?: UkycTokenPresenter;\n /** UKYC session id. Required when `presenter` is `idos-relay`. */\n sessionId?: string;\n /** Token issue time. Defaults to now. */\n issuedAt?: Date;\n /** Token expiry. Defaults to `issuedAt` + 4 hours. */\n expiresAt?: Date;\n};\n\n/**\n * The minted token plus everything needed to exercise UKYC Storage with it.\n */\nexport type MintedUkycTestToken = {\n /** The `local_user_secret` used, hex-encoded, so the caller can reuse it. */\n localUserSecret: string;\n /** base64url `storage_id` — use it as the `{storage_id}` path segment. */\n storageId: string;\n /** base64url `signing_public_key` registered on first write. */\n signingPublicKey: string;\n /** The signed token envelope (payload + signature). */\n token: UkycStorageAccessToken;\n /**\n * The full `Authorization` header value, e.g.\n * `AccessToken <base64url(envelope)>`, ready to send to UKYC Storage.\n */\n authorizationHeader: string;\n};\n\n/**\n * Resolves the caller-supplied secret into raw bytes, generating a random one\n * when none is provided.\n *\n * @param secret - Raw 32 bytes, a hex string, or undefined for a random secret.\n * @returns The `local_user_secret` bytes.\n */\nfunction resolveLocalUserSecret(secret?: Uint8Array | string): Uint8Array {\n if (secret === undefined) {\n return randomBytes(UKYC_LOCAL_USER_SECRET_SIZE_BYTES);\n }\n return typeof secret === 'string' ? hexToBytes(secret) : secret;\n}\n\n/**\n * Mints a signed UKYC `storage_access_token` for testing.\n *\n * @param params - See {@link MintUkycTestTokenParams}.\n * @returns The token, its `Authorization` header, and the derived identifiers.\n */\nexport function mintUkycTestToken(\n params: MintUkycTestTokenParams = {},\n): MintedUkycTestToken {\n const {\n operations = ['read'],\n presenter,\n sessionId,\n issuedAt = new Date(),\n expiresAt = new Date(issuedAt.getTime() + DEFAULT_TOKEN_LIFETIME_MS),\n } = params;\n\n const localUserSecret = resolveLocalUserSecret(params.localUserSecret);\n const material = deriveClientMaterial(localUserSecret);\n\n const token = signStorageAccessToken({\n material,\n operations,\n presenter,\n sessionId,\n issuedAt,\n expiresAt,\n });\n\n const { storageId, signingPublicKey } = encodeClientMaterial(material);\n\n return {\n localUserSecret: bytesToHex(localUserSecret),\n storageId,\n signingPublicKey,\n token,\n authorizationHeader: `${UKYC_CAPABILITY_AUTH_SCHEME} ${encodeStorageAccessTokenForHeader(\n token,\n )}`,\n };\n}\n"]}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { UkycStorageAccessToken, UkycStorageOperation, UkycTokenPresenter } from "./storageAccessToken.cjs";
|
|
2
|
-
/**
|
|
3
|
-
* Inputs for {@link mintUkycTestToken}. All fields are optional; the only value
|
|
4
|
-
* a caller usually pins is `localUserSecret`, so `storage_id` and the signing
|
|
5
|
-
* key stay stable across runs.
|
|
6
|
-
*/
|
|
7
|
-
export type MintUkycTestTokenParams = {
|
|
8
|
-
/**
|
|
9
|
-
* The root `local_user_secret`, as raw 32 bytes or a hex string. When omitted
|
|
10
|
-
* a fresh random secret is generated (returned in the result so it can be
|
|
11
|
-
* reused).
|
|
12
|
-
*/
|
|
13
|
-
localUserSecret?: Uint8Array | string;
|
|
14
|
-
/** Operations the token authorizes. Defaults to `['read']`. */
|
|
15
|
-
operations?: UkycStorageOperation[];
|
|
16
|
-
/** Who will present the token. Defaults to `client`. */
|
|
17
|
-
presenter?: UkycTokenPresenter;
|
|
18
|
-
/** UKYC session id. Required when `presenter` is `idos-relay`. */
|
|
19
|
-
sessionId?: string;
|
|
20
|
-
/** Token issue time. Defaults to now. */
|
|
21
|
-
issuedAt?: Date;
|
|
22
|
-
/** Token expiry. Defaults to `issuedAt` + 4 hours. */
|
|
23
|
-
expiresAt?: Date;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* The minted token plus everything needed to exercise UKYC Storage with it.
|
|
27
|
-
*/
|
|
28
|
-
export type MintedUkycTestToken = {
|
|
29
|
-
/** The `local_user_secret` used, hex-encoded, so the caller can reuse it. */
|
|
30
|
-
localUserSecret: string;
|
|
31
|
-
/** base64url `storage_id` — use it as the `{storage_id}` path segment. */
|
|
32
|
-
storageId: string;
|
|
33
|
-
/** base64url `signing_public_key` registered on first write. */
|
|
34
|
-
signingPublicKey: string;
|
|
35
|
-
/** The signed token envelope (payload + signature). */
|
|
36
|
-
token: UkycStorageAccessToken;
|
|
37
|
-
/**
|
|
38
|
-
* The full `Authorization` header value, e.g.
|
|
39
|
-
* `AccessToken <base64url(envelope)>`, ready to send to UKYC Storage.
|
|
40
|
-
*/
|
|
41
|
-
authorizationHeader: string;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Mints a signed UKYC `storage_access_token` for testing.
|
|
45
|
-
*
|
|
46
|
-
* @param params - See {@link MintUkycTestTokenParams}.
|
|
47
|
-
* @returns The token, its `Authorization` header, and the derived identifiers.
|
|
48
|
-
*/
|
|
49
|
-
export declare function mintUkycTestToken(params?: MintUkycTestTokenParams): MintedUkycTestToken;
|
|
50
|
-
//# sourceMappingURL=testToken.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"testToken.d.cts","sourceRoot":"","sources":["../../src/ukyc/testToken.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,EACnB,iCAAgC;AAgBjC;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;OAIG;IACH,eAAe,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IACtC,+DAA+D;IAC/D,UAAU,CAAC,EAAE,oBAAoB,EAAE,CAAC;IACpC,wDAAwD;IACxD,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAC/B,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,sDAAsD;IACtD,SAAS,CAAC,EAAE,IAAI,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,6EAA6E;IAC7E,eAAe,EAAE,MAAM,CAAC;IACxB,0EAA0E;IAC1E,SAAS,EAAE,MAAM,CAAC;IAClB,gEAAgE;IAChE,gBAAgB,EAAE,MAAM,CAAC;IACzB,uDAAuD;IACvD,KAAK,EAAE,sBAAsB,CAAC;IAC9B;;;OAGG;IACH,mBAAmB,EAAE,MAAM,CAAC;CAC7B,CAAC;AAgBF;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,GAAE,uBAA4B,GACnC,mBAAmB,CAgCrB"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { UkycStorageAccessToken, UkycStorageOperation, UkycTokenPresenter } from "./storageAccessToken.mjs";
|
|
2
|
-
/**
|
|
3
|
-
* Inputs for {@link mintUkycTestToken}. All fields are optional; the only value
|
|
4
|
-
* a caller usually pins is `localUserSecret`, so `storage_id` and the signing
|
|
5
|
-
* key stay stable across runs.
|
|
6
|
-
*/
|
|
7
|
-
export type MintUkycTestTokenParams = {
|
|
8
|
-
/**
|
|
9
|
-
* The root `local_user_secret`, as raw 32 bytes or a hex string. When omitted
|
|
10
|
-
* a fresh random secret is generated (returned in the result so it can be
|
|
11
|
-
* reused).
|
|
12
|
-
*/
|
|
13
|
-
localUserSecret?: Uint8Array | string;
|
|
14
|
-
/** Operations the token authorizes. Defaults to `['read']`. */
|
|
15
|
-
operations?: UkycStorageOperation[];
|
|
16
|
-
/** Who will present the token. Defaults to `client`. */
|
|
17
|
-
presenter?: UkycTokenPresenter;
|
|
18
|
-
/** UKYC session id. Required when `presenter` is `idos-relay`. */
|
|
19
|
-
sessionId?: string;
|
|
20
|
-
/** Token issue time. Defaults to now. */
|
|
21
|
-
issuedAt?: Date;
|
|
22
|
-
/** Token expiry. Defaults to `issuedAt` + 4 hours. */
|
|
23
|
-
expiresAt?: Date;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* The minted token plus everything needed to exercise UKYC Storage with it.
|
|
27
|
-
*/
|
|
28
|
-
export type MintedUkycTestToken = {
|
|
29
|
-
/** The `local_user_secret` used, hex-encoded, so the caller can reuse it. */
|
|
30
|
-
localUserSecret: string;
|
|
31
|
-
/** base64url `storage_id` — use it as the `{storage_id}` path segment. */
|
|
32
|
-
storageId: string;
|
|
33
|
-
/** base64url `signing_public_key` registered on first write. */
|
|
34
|
-
signingPublicKey: string;
|
|
35
|
-
/** The signed token envelope (payload + signature). */
|
|
36
|
-
token: UkycStorageAccessToken;
|
|
37
|
-
/**
|
|
38
|
-
* The full `Authorization` header value, e.g.
|
|
39
|
-
* `AccessToken <base64url(envelope)>`, ready to send to UKYC Storage.
|
|
40
|
-
*/
|
|
41
|
-
authorizationHeader: string;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Mints a signed UKYC `storage_access_token` for testing.
|
|
45
|
-
*
|
|
46
|
-
* @param params - See {@link MintUkycTestTokenParams}.
|
|
47
|
-
* @returns The token, its `Authorization` header, and the derived identifiers.
|
|
48
|
-
*/
|
|
49
|
-
export declare function mintUkycTestToken(params?: MintUkycTestTokenParams): MintedUkycTestToken;
|
|
50
|
-
//# sourceMappingURL=testToken.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"testToken.d.mts","sourceRoot":"","sources":["../../src/ukyc/testToken.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,EACnB,iCAAgC;AAgBjC;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;OAIG;IACH,eAAe,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IACtC,+DAA+D;IAC/D,UAAU,CAAC,EAAE,oBAAoB,EAAE,CAAC;IACpC,wDAAwD;IACxD,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAC/B,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,sDAAsD;IACtD,SAAS,CAAC,EAAE,IAAI,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,6EAA6E;IAC7E,eAAe,EAAE,MAAM,CAAC;IACxB,0EAA0E;IAC1E,SAAS,EAAE,MAAM,CAAC;IAClB,gEAAgE;IAChE,gBAAgB,EAAE,MAAM,CAAC;IACzB,uDAAuD;IACvD,KAAK,EAAE,sBAAsB,CAAC;IAC9B;;;OAGG;IACH,mBAAmB,EAAE,MAAM,CAAC;CAC7B,CAAC;AAgBF;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,GAAE,uBAA4B,GACnC,mBAAmB,CAgCrB"}
|
package/dist/ukyc/testToken.mjs
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { bytesToHex, hexToBytes, randomBytes } from "@noble/hashes/utils";
|
|
2
|
-
import { UKYC_CAPABILITY_AUTH_SCHEME, UKYC_LOCAL_USER_SECRET_SIZE_BYTES } from "./constants.mjs";
|
|
3
|
-
import { deriveClientMaterial, encodeClientMaterial } from "./deriveClientMaterial.mjs";
|
|
4
|
-
import { encodeStorageAccessTokenForHeader, signStorageAccessToken } from "./storageAccessToken.mjs";
|
|
5
|
-
/**
|
|
6
|
-
* Mints ready-to-use UKYC `storage_access_token`s for testing UKYC Storage.
|
|
7
|
-
*
|
|
8
|
-
* This composes the same pure functions the MetaMask client uses in production
|
|
9
|
-
* (`deriveClientMaterial` + `signStorageAccessToken`), so a third party such as
|
|
10
|
-
* idOS can produce a valid, signed token without deriving one on-device. No
|
|
11
|
-
* server "fills in" the `signing_public_key`: it is derived from a
|
|
12
|
-
* `local_user_secret` the caller controls and registered on first write, so
|
|
13
|
-
* reusing the same secret yields a stable `storage_id` and controlling key.
|
|
14
|
-
*/
|
|
15
|
-
/** Default token lifetime when `expiresAt` is not supplied (4 hours). */
|
|
16
|
-
const DEFAULT_TOKEN_LIFETIME_MS = 4 * 60 * 60 * 1000;
|
|
17
|
-
/**
|
|
18
|
-
* Resolves the caller-supplied secret into raw bytes, generating a random one
|
|
19
|
-
* when none is provided.
|
|
20
|
-
*
|
|
21
|
-
* @param secret - Raw 32 bytes, a hex string, or undefined for a random secret.
|
|
22
|
-
* @returns The `local_user_secret` bytes.
|
|
23
|
-
*/
|
|
24
|
-
function resolveLocalUserSecret(secret) {
|
|
25
|
-
if (secret === undefined) {
|
|
26
|
-
return randomBytes(UKYC_LOCAL_USER_SECRET_SIZE_BYTES);
|
|
27
|
-
}
|
|
28
|
-
return typeof secret === 'string' ? hexToBytes(secret) : secret;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Mints a signed UKYC `storage_access_token` for testing.
|
|
32
|
-
*
|
|
33
|
-
* @param params - See {@link MintUkycTestTokenParams}.
|
|
34
|
-
* @returns The token, its `Authorization` header, and the derived identifiers.
|
|
35
|
-
*/
|
|
36
|
-
export function mintUkycTestToken(params = {}) {
|
|
37
|
-
const { operations = ['read'], presenter, sessionId, issuedAt = new Date(), expiresAt = new Date(issuedAt.getTime() + DEFAULT_TOKEN_LIFETIME_MS), } = params;
|
|
38
|
-
const localUserSecret = resolveLocalUserSecret(params.localUserSecret);
|
|
39
|
-
const material = deriveClientMaterial(localUserSecret);
|
|
40
|
-
const token = signStorageAccessToken({
|
|
41
|
-
material,
|
|
42
|
-
operations,
|
|
43
|
-
presenter,
|
|
44
|
-
sessionId,
|
|
45
|
-
issuedAt,
|
|
46
|
-
expiresAt,
|
|
47
|
-
});
|
|
48
|
-
const { storageId, signingPublicKey } = encodeClientMaterial(material);
|
|
49
|
-
return {
|
|
50
|
-
localUserSecret: bytesToHex(localUserSecret),
|
|
51
|
-
storageId,
|
|
52
|
-
signingPublicKey,
|
|
53
|
-
token,
|
|
54
|
-
authorizationHeader: `${UKYC_CAPABILITY_AUTH_SCHEME} ${encodeStorageAccessTokenForHeader(token)}`,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=testToken.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"testToken.mjs","sourceRoot":"","sources":["../../src/ukyc/testToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,4BAA4B;AAE1E,OAAO,EACL,2BAA2B,EAC3B,iCAAiC,EAClC,wBAAuB;AACxB,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACrB,mCAAkC;AACnC,OAAO,EACL,iCAAiC,EACjC,sBAAsB,EACvB,iCAAgC;AAOjC;;;;;;;;;GASG;AAEH,yEAAyE;AACzE,MAAM,yBAAyB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AA6CrD;;;;;;GAMG;AACH,SAAS,sBAAsB,CAAC,MAA4B;IAC1D,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,WAAW,CAAC,iCAAiC,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AAClE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC/B,SAAkC,EAAE;IAEpC,MAAM,EACJ,UAAU,GAAG,CAAC,MAAM,CAAC,EACrB,SAAS,EACT,SAAS,EACT,QAAQ,GAAG,IAAI,IAAI,EAAE,EACrB,SAAS,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,yBAAyB,CAAC,GACrE,GAAG,MAAM,CAAC;IAEX,MAAM,eAAe,GAAG,sBAAsB,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;IACvE,MAAM,QAAQ,GAAG,oBAAoB,CAAC,eAAe,CAAC,CAAC;IAEvD,MAAM,KAAK,GAAG,sBAAsB,CAAC;QACnC,QAAQ;QACR,UAAU;QACV,SAAS;QACT,SAAS;QACT,QAAQ;QACR,SAAS;KACV,CAAC,CAAC;IAEH,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IAEvE,OAAO;QACL,eAAe,EAAE,UAAU,CAAC,eAAe,CAAC;QAC5C,SAAS;QACT,gBAAgB;QAChB,KAAK;QACL,mBAAmB,EAAE,GAAG,2BAA2B,IAAI,iCAAiC,CACtF,KAAK,CACN,EAAE;KACJ,CAAC;AACJ,CAAC","sourcesContent":["import { bytesToHex, hexToBytes, randomBytes } from '@noble/hashes/utils';\n\nimport {\n UKYC_CAPABILITY_AUTH_SCHEME,\n UKYC_LOCAL_USER_SECRET_SIZE_BYTES,\n} from './constants.js';\nimport {\n deriveClientMaterial,\n encodeClientMaterial,\n} from './deriveClientMaterial.js';\nimport {\n encodeStorageAccessTokenForHeader,\n signStorageAccessToken,\n} from './storageAccessToken.js';\nimport type {\n UkycStorageAccessToken,\n UkycStorageOperation,\n UkycTokenPresenter,\n} from './storageAccessToken.js';\n\n/**\n * Mints ready-to-use UKYC `storage_access_token`s for testing UKYC Storage.\n *\n * This composes the same pure functions the MetaMask client uses in production\n * (`deriveClientMaterial` + `signStorageAccessToken`), so a third party such as\n * idOS can produce a valid, signed token without deriving one on-device. No\n * server \"fills in\" the `signing_public_key`: it is derived from a\n * `local_user_secret` the caller controls and registered on first write, so\n * reusing the same secret yields a stable `storage_id` and controlling key.\n */\n\n/** Default token lifetime when `expiresAt` is not supplied (4 hours). */\nconst DEFAULT_TOKEN_LIFETIME_MS = 4 * 60 * 60 * 1000;\n\n/**\n * Inputs for {@link mintUkycTestToken}. All fields are optional; the only value\n * a caller usually pins is `localUserSecret`, so `storage_id` and the signing\n * key stay stable across runs.\n */\nexport type MintUkycTestTokenParams = {\n /**\n * The root `local_user_secret`, as raw 32 bytes or a hex string. When omitted\n * a fresh random secret is generated (returned in the result so it can be\n * reused).\n */\n localUserSecret?: Uint8Array | string;\n /** Operations the token authorizes. Defaults to `['read']`. */\n operations?: UkycStorageOperation[];\n /** Who will present the token. Defaults to `client`. */\n presenter?: UkycTokenPresenter;\n /** UKYC session id. Required when `presenter` is `idos-relay`. */\n sessionId?: string;\n /** Token issue time. Defaults to now. */\n issuedAt?: Date;\n /** Token expiry. Defaults to `issuedAt` + 4 hours. */\n expiresAt?: Date;\n};\n\n/**\n * The minted token plus everything needed to exercise UKYC Storage with it.\n */\nexport type MintedUkycTestToken = {\n /** The `local_user_secret` used, hex-encoded, so the caller can reuse it. */\n localUserSecret: string;\n /** base64url `storage_id` — use it as the `{storage_id}` path segment. */\n storageId: string;\n /** base64url `signing_public_key` registered on first write. */\n signingPublicKey: string;\n /** The signed token envelope (payload + signature). */\n token: UkycStorageAccessToken;\n /**\n * The full `Authorization` header value, e.g.\n * `AccessToken <base64url(envelope)>`, ready to send to UKYC Storage.\n */\n authorizationHeader: string;\n};\n\n/**\n * Resolves the caller-supplied secret into raw bytes, generating a random one\n * when none is provided.\n *\n * @param secret - Raw 32 bytes, a hex string, or undefined for a random secret.\n * @returns The `local_user_secret` bytes.\n */\nfunction resolveLocalUserSecret(secret?: Uint8Array | string): Uint8Array {\n if (secret === undefined) {\n return randomBytes(UKYC_LOCAL_USER_SECRET_SIZE_BYTES);\n }\n return typeof secret === 'string' ? hexToBytes(secret) : secret;\n}\n\n/**\n * Mints a signed UKYC `storage_access_token` for testing.\n *\n * @param params - See {@link MintUkycTestTokenParams}.\n * @returns The token, its `Authorization` header, and the derived identifiers.\n */\nexport function mintUkycTestToken(\n params: MintUkycTestTokenParams = {},\n): MintedUkycTestToken {\n const {\n operations = ['read'],\n presenter,\n sessionId,\n issuedAt = new Date(),\n expiresAt = new Date(issuedAt.getTime() + DEFAULT_TOKEN_LIFETIME_MS),\n } = params;\n\n const localUserSecret = resolveLocalUserSecret(params.localUserSecret);\n const material = deriveClientMaterial(localUserSecret);\n\n const token = signStorageAccessToken({\n material,\n operations,\n presenter,\n sessionId,\n issuedAt,\n expiresAt,\n });\n\n const { storageId, signingPublicKey } = encodeClientMaterial(material);\n\n return {\n localUserSecret: bytesToHex(localUserSecret),\n storageId,\n signingPublicKey,\n token,\n authorizationHeader: `${UKYC_CAPABILITY_AUTH_SCHEME} ${encodeStorageAccessTokenForHeader(\n token,\n )}`,\n };\n}\n"]}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.wrapEncryptionKey = void 0;
|
|
4
|
-
const tweetnacl_1 = require("tweetnacl");
|
|
5
|
-
const encoding_js_1 = require("../encoding.cjs");
|
|
6
|
-
/**
|
|
7
|
-
* Wraps `keyToWrap` for the UKYC session server.
|
|
8
|
-
*
|
|
9
|
-
* The box is sealed with NaCl's `crypto_box`, keyed by the X25519 shared secret
|
|
10
|
-
* between our session client private key and the session server public key
|
|
11
|
-
* returned by `getWrappingKey`.
|
|
12
|
-
*
|
|
13
|
-
* @param sessionClientPrivateKey - Our session's X25519 private key.
|
|
14
|
-
* @param sessionServerPublicKey - The server's X25519 public key (base64url).
|
|
15
|
-
* @param keyToWrap - The raw symmetric key bytes to encrypt.
|
|
16
|
-
* @returns The base64url `encryptedKey` (ciphertext + tag) and `nonce`.
|
|
17
|
-
*/
|
|
18
|
-
function wrapEncryptionKey(sessionClientPrivateKey, sessionServerPublicKey, keyToWrap) {
|
|
19
|
-
const serverPublicKey = (0, encoding_js_1.base64UrlToBytes)(sessionServerPublicKey);
|
|
20
|
-
const nonce = (0, tweetnacl_1.randomBytes)(tweetnacl_1.box.nonceLength);
|
|
21
|
-
const encryptedKey = (0, tweetnacl_1.box)(keyToWrap, nonce, serverPublicKey, sessionClientPrivateKey);
|
|
22
|
-
return {
|
|
23
|
-
encryptedKey: (0, encoding_js_1.toBase64Url)(encryptedKey),
|
|
24
|
-
nonce: (0, encoding_js_1.toBase64Url)(nonce),
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
exports.wrapEncryptionKey = wrapEncryptionKey;
|
|
28
|
-
//# sourceMappingURL=wrapEncryptionKey.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wrapEncryptionKey.cjs","sourceRoot":"","sources":["../../src/ukyc/wrapEncryptionKey.ts"],"names":[],"mappings":";;;AAAA,yCAA6C;AAE7C,iDAA+D;AAwB/D;;;;;;;;;;;GAWG;AACH,SAAgB,iBAAiB,CAC/B,uBAAmC,EACnC,sBAA8B,EAC9B,SAAqB;IAErB,MAAM,eAAe,GAAG,IAAA,8BAAgB,EAAC,sBAAsB,CAAC,CAAC;IACjE,MAAM,KAAK,GAAG,IAAA,uBAAW,EAAC,eAAG,CAAC,WAAW,CAAC,CAAC;IAC3C,MAAM,YAAY,GAAG,IAAA,eAAG,EACtB,SAAS,EACT,KAAK,EACL,eAAe,EACf,uBAAuB,CACxB,CAAC;IACF,OAAO;QACL,YAAY,EAAE,IAAA,yBAAW,EAAC,YAAY,CAAC;QACvC,KAAK,EAAE,IAAA,yBAAW,EAAC,KAAK,CAAC;KAC1B,CAAC;AACJ,CAAC;AAjBD,8CAiBC","sourcesContent":["import { randomBytes, box } from 'tweetnacl';\n\nimport { base64UrlToBytes, toBase64Url } from '../encoding.js';\n\n/**\n * Wraps the `data_encryption_key` for the UKYC session server using NaCl's\n * `crypto_box` (X25519 + XSalsa20-Poly1305) established with the server's\n * per-session wrapping key.\n *\n * Unlike {@link wrapUserKey} (which generates a fresh ephemeral keypair per\n * call), this uses the session client keypair whose public half was already\n * handed to the server via `POST /wrapping-key`. The server therefore already\n * knows our public key and can derive the same shared secret from its session\n * private key, so only `{ encryptedKey, nonce }` need be transmitted.\n */\n\n/**\n * The transmitted portion of a wrapped encryption key: the `crypto_box`\n * ciphertext (which includes the 16-byte Poly1305 auth tag) and the nonce,\n * both unpadded base64url-encoded.\n */\nexport type WrappedEncryptionKeyParts = {\n encryptedKey: string;\n nonce: string;\n};\n\n/**\n * Wraps `keyToWrap` for the UKYC session server.\n *\n * The box is sealed with NaCl's `crypto_box`, keyed by the X25519 shared secret\n * between our session client private key and the session server public key\n * returned by `getWrappingKey`.\n *\n * @param sessionClientPrivateKey - Our session's X25519 private key.\n * @param sessionServerPublicKey - The server's X25519 public key (base64url).\n * @param keyToWrap - The raw symmetric key bytes to encrypt.\n * @returns The base64url `encryptedKey` (ciphertext + tag) and `nonce`.\n */\nexport function wrapEncryptionKey(\n sessionClientPrivateKey: Uint8Array,\n sessionServerPublicKey: string,\n keyToWrap: Uint8Array,\n): WrappedEncryptionKeyParts {\n const serverPublicKey = base64UrlToBytes(sessionServerPublicKey);\n const nonce = randomBytes(box.nonceLength);\n const encryptedKey = box(\n keyToWrap,\n nonce,\n serverPublicKey,\n sessionClientPrivateKey,\n );\n return {\n encryptedKey: toBase64Url(encryptedKey),\n nonce: toBase64Url(nonce),\n };\n}\n"]}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Wraps the `data_encryption_key` for the UKYC session server using NaCl's
|
|
3
|
-
* `crypto_box` (X25519 + XSalsa20-Poly1305) established with the server's
|
|
4
|
-
* per-session wrapping key.
|
|
5
|
-
*
|
|
6
|
-
* Unlike {@link wrapUserKey} (which generates a fresh ephemeral keypair per
|
|
7
|
-
* call), this uses the session client keypair whose public half was already
|
|
8
|
-
* handed to the server via `POST /wrapping-key`. The server therefore already
|
|
9
|
-
* knows our public key and can derive the same shared secret from its session
|
|
10
|
-
* private key, so only `{ encryptedKey, nonce }` need be transmitted.
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* The transmitted portion of a wrapped encryption key: the `crypto_box`
|
|
14
|
-
* ciphertext (which includes the 16-byte Poly1305 auth tag) and the nonce,
|
|
15
|
-
* both unpadded base64url-encoded.
|
|
16
|
-
*/
|
|
17
|
-
export type WrappedEncryptionKeyParts = {
|
|
18
|
-
encryptedKey: string;
|
|
19
|
-
nonce: string;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Wraps `keyToWrap` for the UKYC session server.
|
|
23
|
-
*
|
|
24
|
-
* The box is sealed with NaCl's `crypto_box`, keyed by the X25519 shared secret
|
|
25
|
-
* between our session client private key and the session server public key
|
|
26
|
-
* returned by `getWrappingKey`.
|
|
27
|
-
*
|
|
28
|
-
* @param sessionClientPrivateKey - Our session's X25519 private key.
|
|
29
|
-
* @param sessionServerPublicKey - The server's X25519 public key (base64url).
|
|
30
|
-
* @param keyToWrap - The raw symmetric key bytes to encrypt.
|
|
31
|
-
* @returns The base64url `encryptedKey` (ciphertext + tag) and `nonce`.
|
|
32
|
-
*/
|
|
33
|
-
export declare function wrapEncryptionKey(sessionClientPrivateKey: Uint8Array, sessionServerPublicKey: string, keyToWrap: Uint8Array): WrappedEncryptionKeyParts;
|
|
34
|
-
//# sourceMappingURL=wrapEncryptionKey.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wrapEncryptionKey.d.cts","sourceRoot":"","sources":["../../src/ukyc/wrapEncryptionKey.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AAEH;;;;GAIG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAC/B,uBAAuB,EAAE,UAAU,EACnC,sBAAsB,EAAE,MAAM,EAC9B,SAAS,EAAE,UAAU,GACpB,yBAAyB,CAa3B"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Wraps the `data_encryption_key` for the UKYC session server using NaCl's
|
|
3
|
-
* `crypto_box` (X25519 + XSalsa20-Poly1305) established with the server's
|
|
4
|
-
* per-session wrapping key.
|
|
5
|
-
*
|
|
6
|
-
* Unlike {@link wrapUserKey} (which generates a fresh ephemeral keypair per
|
|
7
|
-
* call), this uses the session client keypair whose public half was already
|
|
8
|
-
* handed to the server via `POST /wrapping-key`. The server therefore already
|
|
9
|
-
* knows our public key and can derive the same shared secret from its session
|
|
10
|
-
* private key, so only `{ encryptedKey, nonce }` need be transmitted.
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* The transmitted portion of a wrapped encryption key: the `crypto_box`
|
|
14
|
-
* ciphertext (which includes the 16-byte Poly1305 auth tag) and the nonce,
|
|
15
|
-
* both unpadded base64url-encoded.
|
|
16
|
-
*/
|
|
17
|
-
export type WrappedEncryptionKeyParts = {
|
|
18
|
-
encryptedKey: string;
|
|
19
|
-
nonce: string;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Wraps `keyToWrap` for the UKYC session server.
|
|
23
|
-
*
|
|
24
|
-
* The box is sealed with NaCl's `crypto_box`, keyed by the X25519 shared secret
|
|
25
|
-
* between our session client private key and the session server public key
|
|
26
|
-
* returned by `getWrappingKey`.
|
|
27
|
-
*
|
|
28
|
-
* @param sessionClientPrivateKey - Our session's X25519 private key.
|
|
29
|
-
* @param sessionServerPublicKey - The server's X25519 public key (base64url).
|
|
30
|
-
* @param keyToWrap - The raw symmetric key bytes to encrypt.
|
|
31
|
-
* @returns The base64url `encryptedKey` (ciphertext + tag) and `nonce`.
|
|
32
|
-
*/
|
|
33
|
-
export declare function wrapEncryptionKey(sessionClientPrivateKey: Uint8Array, sessionServerPublicKey: string, keyToWrap: Uint8Array): WrappedEncryptionKeyParts;
|
|
34
|
-
//# sourceMappingURL=wrapEncryptionKey.d.mts.map
|