@oatscenter/trellis 0.100.0-rc.57 → 0.100.0-rc.58
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/auth/connection.js +4 -1
- package/auth/device_activation.js +3 -3
- package/auth/message_digests.js +4 -1
- package/auth/protocol_wasm/client/trellis_protocol_wasm.d.ts +4 -3
- package/auth/protocol_wasm/client/trellis_protocol_wasm.js +16 -12
- package/auth/protocol_wasm/client/trellis_protocol_wasm_bg.wasm +0 -0
- package/auth/protocol_wasm/provider/trellis_protocol_wasm.d.ts +4 -3
- package/auth/protocol_wasm/provider/trellis_protocol_wasm.js +16 -12
- package/auth/protocol_wasm/provider/trellis_protocol_wasm_bg.wasm +0 -0
- package/auth/protocol_wasm.d.ts +8 -2
- package/auth/protocol_wasm.js +9 -3
- package/device/activation.js +2 -1
- package/device.js +3 -3
- package/generated_support.d.ts +9 -1
- package/generated_support.js +5 -1
- package/internal_sdk/generated/_internal/evidence.js +4 -4
- package/internal_sdk/generated/apis/auth/mod.d.ts +1 -1
- package/internal_sdk/generated/apis/auth/mod.js +1 -1
- package/internal_sdk/generated/package.json +2 -2
- package/internal_sdk/generated/participants/eventsRuntime/mod.d.ts +1 -1
- package/internal_sdk/generated/participants/eventsRuntime/mod.js +2 -2
- package/internal_sdk/generated/participants/jobsRuntime/mod.d.ts +1 -1
- package/internal_sdk/generated/participants/jobsRuntime/mod.js +2 -2
- package/internal_sdk/generated/participants/platform/mod.d.ts +1 -1
- package/internal_sdk/generated/participants/platform/mod.js +2 -2
- package/internal_sdk/generated/types/_internal/p0.d.ts +2 -4
- package/internal_sdk/generated/types/_internal/p0.js +1 -1
- package/live/client_open.js +3 -3
- package/live/provider.js +3 -3
- package/native/custody.js +7 -2
- package/operations.js +9 -7
- package/package.json +2 -2
- package/portable.d.ts +1 -1
- package/portable.js +1 -1
- package/service/runtime/core.js +5 -6
- package/service/runtime/enrollment.js +2 -2
- package/service/runtime/health.js +3 -3
- package/service/runtime/internal_jobs/job-manager.js +2 -3
- package/service/runtime/internal_jobs/key-coordinator.js +2 -2
- package/service/runtime/service.js +3 -4
- package/session/state.d.ts +1 -1
- package/session/state.js +2 -2
- package/session.js +3 -2
- package/transfer/session.js +2 -2
- package/values.d.ts +44 -11
- package/values.js +47 -12
package/auth/connection.js
CHANGED
|
@@ -10,6 +10,8 @@ import { initializeProtocolWasm, signProvisionedAdmissionWasm, verifyOAuthAdmiss
|
|
|
10
10
|
import { loadDefaultRuntimeTransport, } from "../runtime_transport.js";
|
|
11
11
|
import { TransportGenerationManager, } from "../transport/generations.js";
|
|
12
12
|
import { Backoff } from "../backoff.js";
|
|
13
|
+
import { isErr } from "@oatscenter/result";
|
|
14
|
+
import { parseId } from "../values.js";
|
|
13
15
|
/** Subjects on which Auth announces a new provider of an API the session calls. */
|
|
14
16
|
const PROVIDERS_NOTICE_SUBJECT_PREFIX = "trellis.auth.providers.";
|
|
15
17
|
const ISSUER_NOTICE_SUBJECT = "trellis.auth.issuers";
|
|
@@ -177,7 +179,8 @@ export async function connectAdmitted(options) {
|
|
|
177
179
|
});
|
|
178
180
|
const attachmentMarker = attachmentInfo.json().data?.user;
|
|
179
181
|
if (typeof attachmentMarker !== "string" ||
|
|
180
|
-
|
|
182
|
+
!attachmentMarker.startsWith("trellis.auth.v1:") ||
|
|
183
|
+
isErr(parseId(attachmentMarker.slice("trellis.auth.v1:".length), "attachment")))
|
|
181
184
|
throw new Error("AdmissionAttachmentMismatch");
|
|
182
185
|
const attachmentId = attachmentMarker.slice("trellis.auth.v1:".length);
|
|
183
186
|
const context = await requestOwnAdmission({
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import { Value } from "typebox/value";
|
|
3
|
-
import { ulid } from "ulid";
|
|
4
3
|
import { decodeTrellisHttpError } from "./http_error.js";
|
|
5
4
|
import { trellisCrypto } from "./crypto.js";
|
|
6
5
|
import { publicKeyBase64urlFromSeed } from "./keys.js";
|
|
7
6
|
import { createAuth } from "./session_auth.js";
|
|
8
7
|
import { base64urlDecode, base64urlEncode, sha256, utf8 } from "./utils.js";
|
|
8
|
+
import { newId } from "../values.js";
|
|
9
9
|
const DEVICE_IDENTITY_HKDF_INFO = "trellis/device-identity/v1";
|
|
10
10
|
const DEVICE_ACTIVATION_HKDF_INFO = "trellis/device-activate/v1";
|
|
11
11
|
const DEVICE_USER_COMPANION_DOMAIN = "trellis.device.user-companion.v1";
|
|
@@ -187,7 +187,7 @@ export async function requestDeviceEnrollment(args) {
|
|
|
187
187
|
identityPublicKey: args.publicIdentityKey,
|
|
188
188
|
sessionKey: args.sessionIdentity.sessionKey,
|
|
189
189
|
connectionId: args.connectionId,
|
|
190
|
-
requestId:
|
|
190
|
+
requestId: newId("request"),
|
|
191
191
|
iat: Date.now(),
|
|
192
192
|
participantId: args.participantId,
|
|
193
193
|
challengeDigest: args.challengeDigest,
|
|
@@ -255,7 +255,7 @@ export async function waitForDeviceActivation(args) {
|
|
|
255
255
|
publicIdentityKey: args.publicIdentityKey,
|
|
256
256
|
nonce,
|
|
257
257
|
});
|
|
258
|
-
const connectionId = args.connectionId ??
|
|
258
|
+
const connectionId = args.connectionId ?? newId("connection");
|
|
259
259
|
let reviewId;
|
|
260
260
|
let reviewDeadline;
|
|
261
261
|
while (true) {
|
package/auth/message_digests.js
CHANGED
|
@@ -88,7 +88,10 @@ function i64(value, field) {
|
|
|
88
88
|
return out;
|
|
89
89
|
}
|
|
90
90
|
function validateDataDescriptor(descriptor, payload) {
|
|
91
|
-
|
|
91
|
+
// `TR`, then 128 random bits as 26 uppercase Crockford base32 characters.
|
|
92
|
+
if (!/^TR[0-7][0-9A-HJKMNP-TV-Z]{25}$/.test(descriptor.transferId)) {
|
|
93
|
+
throw new Error("transferId must be TR followed by 128 random bits");
|
|
94
|
+
}
|
|
92
95
|
if (descriptor.kind !== "data" ||
|
|
93
96
|
descriptor.terminal !== undefined ||
|
|
94
97
|
(descriptor.direction !== "send" && descriptor.direction !== "receive") ||
|
|
@@ -115,9 +115,10 @@ export function live_constants(): string;
|
|
|
115
115
|
export function live_data_subject(provider_connection_id: string, consumer_connection_id: string, session_id: string): string;
|
|
116
116
|
|
|
117
117
|
/**
|
|
118
|
-
* Generate one
|
|
118
|
+
* Generate one Live nonce of `kind` (`session`, `open` or `challenge`) from
|
|
119
|
+
* the operating system RNG: its prefix, then 128 random bits.
|
|
119
120
|
*/
|
|
120
|
-
export function live_generate_nonce(): string;
|
|
121
|
+
export function live_generate_nonce(kind: string): string;
|
|
121
122
|
|
|
122
123
|
/**
|
|
123
124
|
* Compute the canonical logical-open hash from its JSON identity projection.
|
|
@@ -332,7 +333,7 @@ export interface InitOutput {
|
|
|
332
333
|
readonly issuer_metadata_subject: (a: number) => void;
|
|
333
334
|
readonly live_constants: (a: number) => void;
|
|
334
335
|
readonly live_data_subject: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
335
|
-
readonly live_generate_nonce: (a: number) => void;
|
|
336
|
+
readonly live_generate_nonce: (a: number, b: number, c: number) => void;
|
|
336
337
|
readonly live_logical_open_hash: (a: number, b: number, c: number) => void;
|
|
337
338
|
readonly live_negotiate_max_data_body_bytes: (a: number, b: number, c: number) => void;
|
|
338
339
|
readonly live_observe_subject: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
@@ -628,31 +628,35 @@ export function live_data_subject(provider_connection_id, consumer_connection_id
|
|
|
628
628
|
}
|
|
629
629
|
|
|
630
630
|
/**
|
|
631
|
-
* Generate one
|
|
631
|
+
* Generate one Live nonce of `kind` (`session`, `open` or `challenge`) from
|
|
632
|
+
* the operating system RNG: its prefix, then 128 random bits.
|
|
633
|
+
* @param {string} kind
|
|
632
634
|
* @returns {string}
|
|
633
635
|
*/
|
|
634
|
-
export function live_generate_nonce() {
|
|
635
|
-
let
|
|
636
|
-
let
|
|
636
|
+
export function live_generate_nonce(kind) {
|
|
637
|
+
let deferred3_0;
|
|
638
|
+
let deferred3_1;
|
|
637
639
|
try {
|
|
638
640
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
|
|
639
|
-
wasm.
|
|
641
|
+
const ptr0 = passStringToWasm0(kind, wasm.__wbindgen_export4, wasm.__wbindgen_export5);
|
|
642
|
+
const len0 = WASM_VECTOR_LEN;
|
|
643
|
+
wasm.live_generate_nonce(retptr, ptr0, len0);
|
|
640
644
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
641
645
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
642
646
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
643
647
|
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
644
|
-
var
|
|
645
|
-
var
|
|
648
|
+
var ptr2 = r0;
|
|
649
|
+
var len2 = r1;
|
|
646
650
|
if (r3) {
|
|
647
|
-
|
|
651
|
+
ptr2 = 0; len2 = 0;
|
|
648
652
|
throw takeFromExternrefTable0(r2);
|
|
649
653
|
}
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
return getStringFromWasm0(
|
|
654
|
+
deferred3_0 = ptr2;
|
|
655
|
+
deferred3_1 = len2;
|
|
656
|
+
return getStringFromWasm0(ptr2, len2);
|
|
653
657
|
} finally {
|
|
654
658
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
655
|
-
wasm.__wbindgen_export3(
|
|
659
|
+
wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);
|
|
656
660
|
}
|
|
657
661
|
}
|
|
658
662
|
|
|
Binary file
|
|
@@ -115,9 +115,10 @@ export function live_constants(): string;
|
|
|
115
115
|
export function live_data_subject(provider_connection_id: string, consumer_connection_id: string, session_id: string): string;
|
|
116
116
|
|
|
117
117
|
/**
|
|
118
|
-
* Generate one
|
|
118
|
+
* Generate one Live nonce of `kind` (`session`, `open` or `challenge`) from
|
|
119
|
+
* the operating system RNG: its prefix, then 128 random bits.
|
|
119
120
|
*/
|
|
120
|
-
export function live_generate_nonce(): string;
|
|
121
|
+
export function live_generate_nonce(kind: string): string;
|
|
121
122
|
|
|
122
123
|
/**
|
|
123
124
|
* Compute the canonical logical-control hash from its raw JSON body.
|
|
@@ -376,7 +377,7 @@ export interface InitOutput {
|
|
|
376
377
|
readonly issuer_metadata_subject: (a: number) => void;
|
|
377
378
|
readonly live_constants: (a: number) => void;
|
|
378
379
|
readonly live_data_subject: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
379
|
-
readonly live_generate_nonce: (a: number) => void;
|
|
380
|
+
readonly live_generate_nonce: (a: number, b: number, c: number) => void;
|
|
380
381
|
readonly live_logical_control_hash: (a: number, b: number, c: number) => void;
|
|
381
382
|
readonly live_logical_open_hash: (a: number, b: number, c: number) => void;
|
|
382
383
|
readonly live_negotiate_max_data_body_bytes: (a: number, b: number, c: number) => void;
|
|
@@ -628,31 +628,35 @@ export function live_data_subject(provider_connection_id, consumer_connection_id
|
|
|
628
628
|
}
|
|
629
629
|
|
|
630
630
|
/**
|
|
631
|
-
* Generate one
|
|
631
|
+
* Generate one Live nonce of `kind` (`session`, `open` or `challenge`) from
|
|
632
|
+
* the operating system RNG: its prefix, then 128 random bits.
|
|
633
|
+
* @param {string} kind
|
|
632
634
|
* @returns {string}
|
|
633
635
|
*/
|
|
634
|
-
export function live_generate_nonce() {
|
|
635
|
-
let
|
|
636
|
-
let
|
|
636
|
+
export function live_generate_nonce(kind) {
|
|
637
|
+
let deferred3_0;
|
|
638
|
+
let deferred3_1;
|
|
637
639
|
try {
|
|
638
640
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
|
|
639
|
-
wasm.
|
|
641
|
+
const ptr0 = passStringToWasm0(kind, wasm.__wbindgen_export4, wasm.__wbindgen_export5);
|
|
642
|
+
const len0 = WASM_VECTOR_LEN;
|
|
643
|
+
wasm.live_generate_nonce(retptr, ptr0, len0);
|
|
640
644
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
641
645
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
642
646
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
643
647
|
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
644
|
-
var
|
|
645
|
-
var
|
|
648
|
+
var ptr2 = r0;
|
|
649
|
+
var len2 = r1;
|
|
646
650
|
if (r3) {
|
|
647
|
-
|
|
651
|
+
ptr2 = 0; len2 = 0;
|
|
648
652
|
throw takeFromExternrefTable0(r2);
|
|
649
653
|
}
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
return getStringFromWasm0(
|
|
654
|
+
deferred3_0 = ptr2;
|
|
655
|
+
deferred3_1 = len2;
|
|
656
|
+
return getStringFromWasm0(ptr2, len2);
|
|
653
657
|
} finally {
|
|
654
658
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
655
|
-
wasm.__wbindgen_export3(
|
|
659
|
+
wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);
|
|
656
660
|
}
|
|
657
661
|
}
|
|
658
662
|
|
|
Binary file
|
package/auth/protocol_wasm.d.ts
CHANGED
|
@@ -709,8 +709,14 @@ export type LiveConstants = {
|
|
|
709
709
|
export declare function liveConstants(): LiveConstants;
|
|
710
710
|
/** Compute the negotiated DATA body limit through the shared protocol. */
|
|
711
711
|
export declare function liveNegotiateMaxDataBodyBytes(consumer: number, provider: number): number;
|
|
712
|
-
/**
|
|
713
|
-
|
|
712
|
+
/**
|
|
713
|
+
* Generate one Live nonce from the shared Rust RNG: the kind's prefix (`LS`,
|
|
714
|
+
* `LO` or `LC`), then 128 random bits.
|
|
715
|
+
*
|
|
716
|
+
* @param kind Whether it names a session, an open, or a challenge.
|
|
717
|
+
* @returns The nonce.
|
|
718
|
+
*/
|
|
719
|
+
export declare function liveGenerateNonce(kind: "session" | "open" | "challenge"): string;
|
|
714
720
|
/** Derive the exact live delivery subject through the shared protocol. */
|
|
715
721
|
export declare function liveDataSubject(providerConnectionId: string, consumerConnectionId: string, sessionId: string): string;
|
|
716
722
|
/** Derive the exact owner-directed control subject through the shared protocol. */
|
package/auth/protocol_wasm.js
CHANGED
|
@@ -321,10 +321,16 @@ export function liveNegotiateMaxDataBodyBytes(consumer, provider) {
|
|
|
321
321
|
initializeProtocolWasmSync();
|
|
322
322
|
return protocolWasm.live_negotiate_max_data_body_bytes(consumer, provider);
|
|
323
323
|
}
|
|
324
|
-
/**
|
|
325
|
-
|
|
324
|
+
/**
|
|
325
|
+
* Generate one Live nonce from the shared Rust RNG: the kind's prefix (`LS`,
|
|
326
|
+
* `LO` or `LC`), then 128 random bits.
|
|
327
|
+
*
|
|
328
|
+
* @param kind Whether it names a session, an open, or a challenge.
|
|
329
|
+
* @returns The nonce.
|
|
330
|
+
*/
|
|
331
|
+
export function liveGenerateNonce(kind) {
|
|
326
332
|
initializeProtocolWasmSync();
|
|
327
|
-
return protocolWasm.live_generate_nonce();
|
|
333
|
+
return protocolWasm.live_generate_nonce(kind);
|
|
328
334
|
}
|
|
329
335
|
/** Derive the exact live delivery subject through the shared protocol. */
|
|
330
336
|
export function liveDataSubject(providerConnectionId, consumerConnectionId, sessionId) {
|
package/device/activation.js
CHANGED
|
@@ -12,6 +12,7 @@ import { trellisCrypto } from "../auth/crypto.js";
|
|
|
12
12
|
import { base64urlDecode, base64urlEncode, sha256, utf8, } from "../auth/utils.js";
|
|
13
13
|
import { createAuth } from "../auth/session_auth.js";
|
|
14
14
|
import { participantEvidence } from "../participant_runtime/participant.js";
|
|
15
|
+
import { newId } from "../values.js";
|
|
15
16
|
const PendingActivationStateSchema = Type.Object({
|
|
16
17
|
status: Type.Literal("pending"),
|
|
17
18
|
participantId: Type.String({ minLength: 1 }),
|
|
@@ -308,7 +309,7 @@ export async function checkDeviceActivation(args) {
|
|
|
308
309
|
sessionIdentity: await createAuth({
|
|
309
310
|
sessionKeySeed: base64urlEncode(crypto.getRandomValues(new Uint8Array(32))),
|
|
310
311
|
}),
|
|
311
|
-
connectionId:
|
|
312
|
+
connectionId: newId("connection"),
|
|
312
313
|
participantId: args.participant.identity,
|
|
313
314
|
...participantEvidence(args.participant),
|
|
314
315
|
challengeDigest: base64urlEncode(await sha256(utf8(localState.nonce))),
|
package/device.js
CHANGED
|
@@ -3,7 +3,6 @@ import { acceptServerCertificateFor, installationFetch, trustAcceptedCertificate
|
|
|
3
3
|
import "./auth/protocol_wasm_provider.js";
|
|
4
4
|
export { checkDeviceActivation } from "./device/activation.js";
|
|
5
5
|
import { AsyncResult, Result, UnexpectedError } from "@oatscenter/result";
|
|
6
|
-
import { ulid } from "ulid";
|
|
7
6
|
import { connectProvisioned, } from "./auth/connection.js";
|
|
8
7
|
import { connectNativeClient, } from "./native/connection.js";
|
|
9
8
|
import { ContractResourceBindingsSchema } from "./participant.js";
|
|
@@ -23,6 +22,7 @@ import { createCallerRuntime } from "./caller.js";
|
|
|
23
22
|
import { getParticipantRuntime, participantEvidence, } from "./participant_runtime/participant.js";
|
|
24
23
|
import { ConfigHandle, loadConfig, ownReading, } from "./service/config.js";
|
|
25
24
|
import { API as AUTH_API } from "./internal_sdk/generated/apis/auth/mod.js";
|
|
25
|
+
import { newId } from "./values.js";
|
|
26
26
|
function deviceConnectResult(promise) {
|
|
27
27
|
return AsyncResult.from(promise.then((value) => Result.ok(value), (cause) => Result.err(cause instanceof TransportError
|
|
28
28
|
? cause
|
|
@@ -180,7 +180,7 @@ function createActivationSession(args) {
|
|
|
180
180
|
(await createAuth({
|
|
181
181
|
sessionKeySeed: base64urlEncode(crypto.getRandomValues(new Uint8Array(32))),
|
|
182
182
|
})),
|
|
183
|
-
connectionId: args.connectionId ??
|
|
183
|
+
connectionId: args.connectionId ?? newId("connection"),
|
|
184
184
|
participantId: args.participantId,
|
|
185
185
|
...participantEvidence(args.participant),
|
|
186
186
|
challengeDigest: base64urlEncode(await sha256(utf8(args.localState.nonce))),
|
|
@@ -209,7 +209,7 @@ export async function startDeviceActivationWithDeps(args, deps) {
|
|
|
209
209
|
const sessionIdentity = await createAuth({
|
|
210
210
|
sessionKeySeed: base64urlEncode(crypto.getRandomValues(new Uint8Array(32))),
|
|
211
211
|
});
|
|
212
|
-
const connectionId =
|
|
212
|
+
const connectionId = newId("connection");
|
|
213
213
|
const activation = await requestDeviceEnrollment({
|
|
214
214
|
fetch: installationFetch,
|
|
215
215
|
trellisUrl: args.trellisUrl,
|
package/generated_support.d.ts
CHANGED
|
@@ -29,10 +29,14 @@ type OpenEnum<T extends string> = T | (string & {
|
|
|
29
29
|
export type Timestamp = string & {
|
|
30
30
|
readonly __timestamp: unique symbol;
|
|
31
31
|
};
|
|
32
|
-
/** An IDL `ulid`:
|
|
32
|
+
/** An IDL `ulid`: an ID Trellis makes, the one- or two-letter prefix naming its kind, then a canonical ULID. */
|
|
33
33
|
export type Ulid = string & {
|
|
34
34
|
readonly __ulid: unique symbol;
|
|
35
35
|
};
|
|
36
|
+
/** An IDL `bare_ulid`: a canonical ULID with no prefix, for a service's own records. */
|
|
37
|
+
export type BareUlid = string & {
|
|
38
|
+
readonly __bareUlid: unique symbol;
|
|
39
|
+
};
|
|
36
40
|
type OptionalCodec<T> = Codec<T | undefined> & Readonly<{
|
|
37
41
|
optional: true;
|
|
38
42
|
}>;
|
|
@@ -95,6 +99,10 @@ export declare const codecs: Readonly<{
|
|
|
95
99
|
decode(value: unknown): Ulid;
|
|
96
100
|
encode(value: Ulid): unknown;
|
|
97
101
|
}>;
|
|
102
|
+
bareUlid: Readonly<{
|
|
103
|
+
decode(value: unknown): BareUlid;
|
|
104
|
+
encode(value: BareUlid): unknown;
|
|
105
|
+
}>;
|
|
98
106
|
json: Readonly<{
|
|
99
107
|
decode(value: unknown): JsonValue;
|
|
100
108
|
encode(value: JsonValue): unknown;
|
package/generated_support.js
CHANGED
|
@@ -82,7 +82,8 @@ function timestamp(value) {
|
|
|
82
82
|
const digits = fraction?.replace(/0+$/, "");
|
|
83
83
|
return `${canonical}${digits ? `.${digits}` : ""}Z`;
|
|
84
84
|
}
|
|
85
|
-
const ulidPattern = /^
|
|
85
|
+
const ulidPattern = /^[A-Z]{1,2}[0-7][0-9A-HJKMNP-TV-Z]{25}$/;
|
|
86
|
+
const bareUlidPattern = /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/;
|
|
86
87
|
/**
|
|
87
88
|
* Enforce declared bounds in both directions, so a provider never hands a
|
|
88
89
|
* handler an out-of-bounds input and a caller never sends one. String length
|
|
@@ -167,6 +168,9 @@ export const codecs = Object.freeze({
|
|
|
167
168
|
bytes: codec(decodeBase64, encodeBase64),
|
|
168
169
|
timestamp: codec(timestamp),
|
|
169
170
|
ulid: codec((value) => typeof value === "string" && ulidPattern.test(value)
|
|
171
|
+
? value
|
|
172
|
+
: fail("ID: its kind's prefix, then a canonical ULID")),
|
|
173
|
+
bareUlid: codec((value) => typeof value === "string" && bareUlidPattern.test(value)
|
|
170
174
|
? value
|
|
171
175
|
: fail("canonical ULID")),
|
|
172
176
|
json: codec(jsonValue),
|