@naylence/runtime 0.3.5-test.921 → 0.3.5-test.923
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/browser/index.cjs +255 -249
- package/dist/browser/index.mjs +250 -250
- package/dist/cjs/naylence/fame/security/index.js +10 -1
- package/dist/cjs/version.js +2 -2
- package/dist/esm/naylence/fame/security/index.js +3 -0
- package/dist/esm/version.js +2 -2
- package/dist/node/index.cjs +255 -249
- package/dist/node/index.mjs +250 -250
- package/dist/node/node.cjs +254 -248
- package/dist/node/node.mjs +249 -249
- package/dist/types/naylence/fame/security/index.d.ts +3 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/browser/index.cjs
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
var core = require('@naylence/core');
|
|
4
4
|
var zod = require('zod');
|
|
5
5
|
var factory = require('@naylence/factory');
|
|
6
|
+
var ed25519 = require('@noble/ed25519');
|
|
7
|
+
var sha2_js = require('@noble/hashes/sha2.js');
|
|
6
8
|
var chacha_js = require('@noble/ciphers/chacha.js');
|
|
7
9
|
var ed25519_js = require('@noble/curves/ed25519.js');
|
|
8
10
|
var hkdf_js = require('@noble/hashes/hkdf.js');
|
|
9
|
-
var sha2_js = require('@noble/hashes/sha2.js');
|
|
10
11
|
var utils_js = require('@noble/hashes/utils.js');
|
|
11
12
|
var yaml = require('yaml');
|
|
12
13
|
var fastify = require('fastify');
|
|
13
14
|
var websocketPlugin = require('@fastify/websocket');
|
|
14
|
-
var ed25519 = require('@noble/ed25519');
|
|
15
15
|
|
|
16
16
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
17
17
|
// --- ENV SHIM (runs once in browser) ---
|
|
@@ -98,12 +98,12 @@ installProcessEnvShim();
|
|
|
98
98
|
// --- END ENV SHIM ---
|
|
99
99
|
|
|
100
100
|
// This file is auto-generated during build - do not edit manually
|
|
101
|
-
// Generated from package.json version: 0.3.5-test.
|
|
101
|
+
// Generated from package.json version: 0.3.5-test.923
|
|
102
102
|
/**
|
|
103
103
|
* The package version, injected at build time.
|
|
104
104
|
* @internal
|
|
105
105
|
*/
|
|
106
|
-
const VERSION = '0.3.5-test.
|
|
106
|
+
const VERSION = '0.3.5-test.923';
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
109
|
* Fame protocol specific error classes with WebSocket close codes and proper inheritance.
|
|
@@ -25245,6 +25245,251 @@ class SigningConfig {
|
|
|
25245
25245
|
}
|
|
25246
25246
|
}
|
|
25247
25247
|
|
|
25248
|
+
function hasBuffer() {
|
|
25249
|
+
return typeof Buffer !== 'undefined';
|
|
25250
|
+
}
|
|
25251
|
+
function readStringProperty(source, ...names) {
|
|
25252
|
+
if (!source || typeof source !== 'object') {
|
|
25253
|
+
return undefined;
|
|
25254
|
+
}
|
|
25255
|
+
for (const name of names) {
|
|
25256
|
+
const value = source[name];
|
|
25257
|
+
if (typeof value === 'string' && value.length > 0) {
|
|
25258
|
+
return value;
|
|
25259
|
+
}
|
|
25260
|
+
}
|
|
25261
|
+
return undefined;
|
|
25262
|
+
}
|
|
25263
|
+
function decodePem(pem) {
|
|
25264
|
+
const base64 = pem
|
|
25265
|
+
.replace(/-----BEGIN[^-]+-----/g, '')
|
|
25266
|
+
.replace(/-----END[^-]+-----/g, '')
|
|
25267
|
+
.replace(/\s+/g, '');
|
|
25268
|
+
if (typeof atob === 'function') {
|
|
25269
|
+
const binary = atob(base64);
|
|
25270
|
+
const bytes = new Uint8Array(binary.length);
|
|
25271
|
+
for (let i = 0; i < binary.length; i += 1) {
|
|
25272
|
+
bytes[i] = binary.charCodeAt(i);
|
|
25273
|
+
}
|
|
25274
|
+
return bytes;
|
|
25275
|
+
}
|
|
25276
|
+
if (hasBuffer()) {
|
|
25277
|
+
return Uint8Array.from(Buffer.from(base64, 'base64'));
|
|
25278
|
+
}
|
|
25279
|
+
throw new Error('Base64 decoding is not available in this environment');
|
|
25280
|
+
}
|
|
25281
|
+
function readLength(data, offset) {
|
|
25282
|
+
const initial = data[offset];
|
|
25283
|
+
if (initial === undefined) {
|
|
25284
|
+
throw new Error('Unexpected end of ASN.1 data');
|
|
25285
|
+
}
|
|
25286
|
+
if ((initial & 0x80) === 0) {
|
|
25287
|
+
return { length: initial, nextOffset: offset + 1 };
|
|
25288
|
+
}
|
|
25289
|
+
const lengthOfLength = initial & 0x7f;
|
|
25290
|
+
if (lengthOfLength === 0 || lengthOfLength > 4) {
|
|
25291
|
+
throw new Error('Unsupported ASN.1 length encoding');
|
|
25292
|
+
}
|
|
25293
|
+
let length = 0;
|
|
25294
|
+
let position = offset + 1;
|
|
25295
|
+
for (let i = 0; i < lengthOfLength; i += 1) {
|
|
25296
|
+
const byte = data[position];
|
|
25297
|
+
if (byte === undefined) {
|
|
25298
|
+
throw new Error('Unexpected end of ASN.1 data');
|
|
25299
|
+
}
|
|
25300
|
+
length = (length << 8) | byte;
|
|
25301
|
+
position += 1;
|
|
25302
|
+
}
|
|
25303
|
+
return { length, nextOffset: position };
|
|
25304
|
+
}
|
|
25305
|
+
function readElement(data, offset, tag) {
|
|
25306
|
+
if (data[offset] !== tag) {
|
|
25307
|
+
throw new Error(`Unexpected ASN.1 tag: expected 0x${tag.toString(16)}, got 0x${(data[offset] ?? 0).toString(16)}`);
|
|
25308
|
+
}
|
|
25309
|
+
const { length, nextOffset } = readLength(data, offset + 1);
|
|
25310
|
+
const contentOffset = nextOffset;
|
|
25311
|
+
return {
|
|
25312
|
+
length,
|
|
25313
|
+
contentOffset,
|
|
25314
|
+
nextOffset: contentOffset + length,
|
|
25315
|
+
};
|
|
25316
|
+
}
|
|
25317
|
+
function parseEd25519PrivateKey(pem) {
|
|
25318
|
+
const raw = decodePem(pem);
|
|
25319
|
+
if (raw.length === 32) {
|
|
25320
|
+
return raw.slice();
|
|
25321
|
+
}
|
|
25322
|
+
// Handle PKCS#8 structure defined in RFC 8410
|
|
25323
|
+
const sequence = readElement(raw, 0, 0x30);
|
|
25324
|
+
const version = readElement(raw, sequence.contentOffset, 0x02);
|
|
25325
|
+
let offset = version.nextOffset;
|
|
25326
|
+
const algorithm = readElement(raw, offset, 0x30);
|
|
25327
|
+
offset = algorithm.nextOffset;
|
|
25328
|
+
const privateKey = readElement(raw, offset, 0x04);
|
|
25329
|
+
const privateContent = raw.subarray(privateKey.contentOffset, privateKey.contentOffset + privateKey.length);
|
|
25330
|
+
if (privateContent.length === 32) {
|
|
25331
|
+
return privateContent.slice();
|
|
25332
|
+
}
|
|
25333
|
+
if (privateContent.length >= 34 && privateContent[0] === 0x04) {
|
|
25334
|
+
const innerLength = privateContent[1];
|
|
25335
|
+
if (innerLength !== 32 || privateContent.length < innerLength + 2) {
|
|
25336
|
+
throw new Error('Unexpected Ed25519 private key length');
|
|
25337
|
+
}
|
|
25338
|
+
return privateContent.subarray(2, 34);
|
|
25339
|
+
}
|
|
25340
|
+
throw new Error('Unsupported Ed25519 private key structure');
|
|
25341
|
+
}
|
|
25342
|
+
const textEncoder = typeof TextEncoder !== 'undefined' ? new TextEncoder() : undefined;
|
|
25343
|
+
function encodeUtf8(value) {
|
|
25344
|
+
if (textEncoder) {
|
|
25345
|
+
return textEncoder.encode(value);
|
|
25346
|
+
}
|
|
25347
|
+
if (hasBuffer()) {
|
|
25348
|
+
return Uint8Array.from(Buffer.from(value, 'utf8'));
|
|
25349
|
+
}
|
|
25350
|
+
throw new Error('No UTF-8 encoder available in this environment');
|
|
25351
|
+
}
|
|
25352
|
+
|
|
25353
|
+
if (!ed25519.hashes.sha512) {
|
|
25354
|
+
ed25519.hashes.sha512 = (message) => sha2_js.sha512(message);
|
|
25355
|
+
}
|
|
25356
|
+
function normalizeSignerOptions(options) {
|
|
25357
|
+
if (!options || typeof options !== 'object') {
|
|
25358
|
+
return {};
|
|
25359
|
+
}
|
|
25360
|
+
const candidate = options;
|
|
25361
|
+
const result = {
|
|
25362
|
+
...options,
|
|
25363
|
+
};
|
|
25364
|
+
const cryptoProvider = resolveAlias(candidate, ['cryptoProvider', 'crypto_provider']);
|
|
25365
|
+
if (cryptoProvider !== undefined) {
|
|
25366
|
+
result.cryptoProvider = cryptoProvider ?? null;
|
|
25367
|
+
}
|
|
25368
|
+
const signingConfig = resolveAlias(candidate, ['signingConfig', 'signing_config']);
|
|
25369
|
+
if (signingConfig !== undefined) {
|
|
25370
|
+
result.signingConfig = signingConfig;
|
|
25371
|
+
}
|
|
25372
|
+
const privateKeyPem = resolveAlias(candidate, [
|
|
25373
|
+
'privateKeyPem',
|
|
25374
|
+
'private_key_pem',
|
|
25375
|
+
]);
|
|
25376
|
+
if (privateKeyPem !== undefined) {
|
|
25377
|
+
result.privateKeyPem = privateKeyPem;
|
|
25378
|
+
}
|
|
25379
|
+
const keyId = resolveAlias(candidate, [
|
|
25380
|
+
'keyId',
|
|
25381
|
+
'key_id',
|
|
25382
|
+
]);
|
|
25383
|
+
if (keyId !== undefined) {
|
|
25384
|
+
result.keyId = keyId;
|
|
25385
|
+
}
|
|
25386
|
+
return result;
|
|
25387
|
+
}
|
|
25388
|
+
class EdDSAEnvelopeSigner {
|
|
25389
|
+
constructor(options = {}) {
|
|
25390
|
+
const normalized = normalizeSignerOptions(options);
|
|
25391
|
+
const provider = normalized.cryptoProvider ?? null;
|
|
25392
|
+
if (!provider) {
|
|
25393
|
+
throw new Error('No crypto provider is configured for signing');
|
|
25394
|
+
}
|
|
25395
|
+
this.crypto = provider;
|
|
25396
|
+
const signingConfigOption = normalized.signingConfig;
|
|
25397
|
+
if (signingConfigOption instanceof SigningConfig) {
|
|
25398
|
+
this.signingConfig = signingConfigOption;
|
|
25399
|
+
}
|
|
25400
|
+
else if (signingConfigOption) {
|
|
25401
|
+
this.signingConfig = new SigningConfig(signingConfigOption);
|
|
25402
|
+
}
|
|
25403
|
+
else {
|
|
25404
|
+
this.signingConfig = new SigningConfig();
|
|
25405
|
+
}
|
|
25406
|
+
this.explicitPrivateKey = normalized.privateKeyPem;
|
|
25407
|
+
this.explicitKeyId = normalized.keyId;
|
|
25408
|
+
}
|
|
25409
|
+
signEnvelope(envelope, { physicalPath }) {
|
|
25410
|
+
if (!envelope.sid) {
|
|
25411
|
+
throw new Error('Envelope missing sid');
|
|
25412
|
+
}
|
|
25413
|
+
const frame = envelope.frame;
|
|
25414
|
+
if (frame.type === 'Data') {
|
|
25415
|
+
const dataFrame = frame;
|
|
25416
|
+
if (!dataFrame.pd) {
|
|
25417
|
+
const payload = dataFrame.payload ?? '';
|
|
25418
|
+
const payloadString = payload === '' ? '' : canonicalJson(payload);
|
|
25419
|
+
dataFrame.pd = secureDigest(payloadString);
|
|
25420
|
+
}
|
|
25421
|
+
}
|
|
25422
|
+
const digest = frameDigest(frame);
|
|
25423
|
+
const immutable = canonicalJson(immutableHeaders(envelope));
|
|
25424
|
+
const sidDigest = secureDigest(physicalPath);
|
|
25425
|
+
const tbs = new Uint8Array(encodeUtf8(sidDigest).length +
|
|
25426
|
+
1 +
|
|
25427
|
+
encodeUtf8(immutable).length +
|
|
25428
|
+
1 +
|
|
25429
|
+
encodeUtf8(digest).length);
|
|
25430
|
+
const sidBytes = encodeUtf8(sidDigest);
|
|
25431
|
+
const immBytes = encodeUtf8(immutable);
|
|
25432
|
+
const digBytes = encodeUtf8(digest);
|
|
25433
|
+
let offset = 0;
|
|
25434
|
+
tbs.set(sidBytes, offset);
|
|
25435
|
+
offset += sidBytes.length;
|
|
25436
|
+
tbs[offset] = 0x1f;
|
|
25437
|
+
offset += 1;
|
|
25438
|
+
tbs.set(immBytes, offset);
|
|
25439
|
+
offset += immBytes.length;
|
|
25440
|
+
tbs[offset] = 0x1f;
|
|
25441
|
+
offset += 1;
|
|
25442
|
+
tbs.set(digBytes, offset);
|
|
25443
|
+
const privateKey = this.loadPrivateKey();
|
|
25444
|
+
const signatureBytes = ed25519.sign(tbs, privateKey);
|
|
25445
|
+
const signature = urlsafeBase64Encode(signatureBytes);
|
|
25446
|
+
const kid = this.determineKeyId();
|
|
25447
|
+
const signatureHeader = {
|
|
25448
|
+
kid,
|
|
25449
|
+
val: signature,
|
|
25450
|
+
alg: 'EdDSA',
|
|
25451
|
+
};
|
|
25452
|
+
const secHeader = envelope.sec ?? {};
|
|
25453
|
+
secHeader.sig = signatureHeader;
|
|
25454
|
+
envelope.sec = secHeader;
|
|
25455
|
+
return envelope;
|
|
25456
|
+
}
|
|
25457
|
+
loadPrivateKey() {
|
|
25458
|
+
const pem = this.explicitPrivateKey ??
|
|
25459
|
+
readStringProperty(this.crypto, 'signingPrivatePem', 'signing_private_pem');
|
|
25460
|
+
if (!pem) {
|
|
25461
|
+
throw new Error('Crypto provider does not expose a signing private key');
|
|
25462
|
+
}
|
|
25463
|
+
return parseEd25519PrivateKey(pem);
|
|
25464
|
+
}
|
|
25465
|
+
determineKeyId() {
|
|
25466
|
+
if (this.explicitKeyId) {
|
|
25467
|
+
return this.explicitKeyId;
|
|
25468
|
+
}
|
|
25469
|
+
if (this.signingConfig.signingMaterial === core.SigningMaterial.X509_CHAIN) {
|
|
25470
|
+
const certificateProvider = this
|
|
25471
|
+
.crypto;
|
|
25472
|
+
const jwk = certificateProvider.nodeJwk?.();
|
|
25473
|
+
if (jwk && typeof jwk === 'object' && 'kid' in jwk && 'x5c' in jwk) {
|
|
25474
|
+
const kid = jwk.kid;
|
|
25475
|
+
if (typeof kid === 'string' && kid.length > 0) {
|
|
25476
|
+
return kid;
|
|
25477
|
+
}
|
|
25478
|
+
}
|
|
25479
|
+
}
|
|
25480
|
+
const fallback = readStringProperty(this.crypto, 'signatureKeyId', 'signature_key_id');
|
|
25481
|
+
if (!fallback) {
|
|
25482
|
+
throw new Error('Crypto provider does not expose a signature key id');
|
|
25483
|
+
}
|
|
25484
|
+
return fallback;
|
|
25485
|
+
}
|
|
25486
|
+
}
|
|
25487
|
+
|
|
25488
|
+
var eddsaEnvelopeSigner = /*#__PURE__*/Object.freeze({
|
|
25489
|
+
__proto__: null,
|
|
25490
|
+
EdDSAEnvelopeSigner: EdDSAEnvelopeSigner
|
|
25491
|
+
});
|
|
25492
|
+
|
|
25248
25493
|
const logger$x = getLogger('naylence.fame.security.auth.jwt_token_issuer');
|
|
25249
25494
|
let joseModulePromise = null;
|
|
25250
25495
|
async function requireJose() {
|
|
@@ -39352,251 +39597,6 @@ var sharedSecretTokenVerifier = /*#__PURE__*/Object.freeze({
|
|
|
39352
39597
|
SharedSecretTokenVerifier: SharedSecretTokenVerifier
|
|
39353
39598
|
});
|
|
39354
39599
|
|
|
39355
|
-
function hasBuffer() {
|
|
39356
|
-
return typeof Buffer !== 'undefined';
|
|
39357
|
-
}
|
|
39358
|
-
function readStringProperty(source, ...names) {
|
|
39359
|
-
if (!source || typeof source !== 'object') {
|
|
39360
|
-
return undefined;
|
|
39361
|
-
}
|
|
39362
|
-
for (const name of names) {
|
|
39363
|
-
const value = source[name];
|
|
39364
|
-
if (typeof value === 'string' && value.length > 0) {
|
|
39365
|
-
return value;
|
|
39366
|
-
}
|
|
39367
|
-
}
|
|
39368
|
-
return undefined;
|
|
39369
|
-
}
|
|
39370
|
-
function decodePem(pem) {
|
|
39371
|
-
const base64 = pem
|
|
39372
|
-
.replace(/-----BEGIN[^-]+-----/g, '')
|
|
39373
|
-
.replace(/-----END[^-]+-----/g, '')
|
|
39374
|
-
.replace(/\s+/g, '');
|
|
39375
|
-
if (typeof atob === 'function') {
|
|
39376
|
-
const binary = atob(base64);
|
|
39377
|
-
const bytes = new Uint8Array(binary.length);
|
|
39378
|
-
for (let i = 0; i < binary.length; i += 1) {
|
|
39379
|
-
bytes[i] = binary.charCodeAt(i);
|
|
39380
|
-
}
|
|
39381
|
-
return bytes;
|
|
39382
|
-
}
|
|
39383
|
-
if (hasBuffer()) {
|
|
39384
|
-
return Uint8Array.from(Buffer.from(base64, 'base64'));
|
|
39385
|
-
}
|
|
39386
|
-
throw new Error('Base64 decoding is not available in this environment');
|
|
39387
|
-
}
|
|
39388
|
-
function readLength(data, offset) {
|
|
39389
|
-
const initial = data[offset];
|
|
39390
|
-
if (initial === undefined) {
|
|
39391
|
-
throw new Error('Unexpected end of ASN.1 data');
|
|
39392
|
-
}
|
|
39393
|
-
if ((initial & 0x80) === 0) {
|
|
39394
|
-
return { length: initial, nextOffset: offset + 1 };
|
|
39395
|
-
}
|
|
39396
|
-
const lengthOfLength = initial & 0x7f;
|
|
39397
|
-
if (lengthOfLength === 0 || lengthOfLength > 4) {
|
|
39398
|
-
throw new Error('Unsupported ASN.1 length encoding');
|
|
39399
|
-
}
|
|
39400
|
-
let length = 0;
|
|
39401
|
-
let position = offset + 1;
|
|
39402
|
-
for (let i = 0; i < lengthOfLength; i += 1) {
|
|
39403
|
-
const byte = data[position];
|
|
39404
|
-
if (byte === undefined) {
|
|
39405
|
-
throw new Error('Unexpected end of ASN.1 data');
|
|
39406
|
-
}
|
|
39407
|
-
length = (length << 8) | byte;
|
|
39408
|
-
position += 1;
|
|
39409
|
-
}
|
|
39410
|
-
return { length, nextOffset: position };
|
|
39411
|
-
}
|
|
39412
|
-
function readElement(data, offset, tag) {
|
|
39413
|
-
if (data[offset] !== tag) {
|
|
39414
|
-
throw new Error(`Unexpected ASN.1 tag: expected 0x${tag.toString(16)}, got 0x${(data[offset] ?? 0).toString(16)}`);
|
|
39415
|
-
}
|
|
39416
|
-
const { length, nextOffset } = readLength(data, offset + 1);
|
|
39417
|
-
const contentOffset = nextOffset;
|
|
39418
|
-
return {
|
|
39419
|
-
length,
|
|
39420
|
-
contentOffset,
|
|
39421
|
-
nextOffset: contentOffset + length,
|
|
39422
|
-
};
|
|
39423
|
-
}
|
|
39424
|
-
function parseEd25519PrivateKey(pem) {
|
|
39425
|
-
const raw = decodePem(pem);
|
|
39426
|
-
if (raw.length === 32) {
|
|
39427
|
-
return raw.slice();
|
|
39428
|
-
}
|
|
39429
|
-
// Handle PKCS#8 structure defined in RFC 8410
|
|
39430
|
-
const sequence = readElement(raw, 0, 0x30);
|
|
39431
|
-
const version = readElement(raw, sequence.contentOffset, 0x02);
|
|
39432
|
-
let offset = version.nextOffset;
|
|
39433
|
-
const algorithm = readElement(raw, offset, 0x30);
|
|
39434
|
-
offset = algorithm.nextOffset;
|
|
39435
|
-
const privateKey = readElement(raw, offset, 0x04);
|
|
39436
|
-
const privateContent = raw.subarray(privateKey.contentOffset, privateKey.contentOffset + privateKey.length);
|
|
39437
|
-
if (privateContent.length === 32) {
|
|
39438
|
-
return privateContent.slice();
|
|
39439
|
-
}
|
|
39440
|
-
if (privateContent.length >= 34 && privateContent[0] === 0x04) {
|
|
39441
|
-
const innerLength = privateContent[1];
|
|
39442
|
-
if (innerLength !== 32 || privateContent.length < innerLength + 2) {
|
|
39443
|
-
throw new Error('Unexpected Ed25519 private key length');
|
|
39444
|
-
}
|
|
39445
|
-
return privateContent.subarray(2, 34);
|
|
39446
|
-
}
|
|
39447
|
-
throw new Error('Unsupported Ed25519 private key structure');
|
|
39448
|
-
}
|
|
39449
|
-
const textEncoder = typeof TextEncoder !== 'undefined' ? new TextEncoder() : undefined;
|
|
39450
|
-
function encodeUtf8(value) {
|
|
39451
|
-
if (textEncoder) {
|
|
39452
|
-
return textEncoder.encode(value);
|
|
39453
|
-
}
|
|
39454
|
-
if (hasBuffer()) {
|
|
39455
|
-
return Uint8Array.from(Buffer.from(value, 'utf8'));
|
|
39456
|
-
}
|
|
39457
|
-
throw new Error('No UTF-8 encoder available in this environment');
|
|
39458
|
-
}
|
|
39459
|
-
|
|
39460
|
-
if (!ed25519.hashes.sha512) {
|
|
39461
|
-
ed25519.hashes.sha512 = (message) => sha2_js.sha512(message);
|
|
39462
|
-
}
|
|
39463
|
-
function normalizeSignerOptions(options) {
|
|
39464
|
-
if (!options || typeof options !== 'object') {
|
|
39465
|
-
return {};
|
|
39466
|
-
}
|
|
39467
|
-
const candidate = options;
|
|
39468
|
-
const result = {
|
|
39469
|
-
...options,
|
|
39470
|
-
};
|
|
39471
|
-
const cryptoProvider = resolveAlias(candidate, ['cryptoProvider', 'crypto_provider']);
|
|
39472
|
-
if (cryptoProvider !== undefined) {
|
|
39473
|
-
result.cryptoProvider = cryptoProvider ?? null;
|
|
39474
|
-
}
|
|
39475
|
-
const signingConfig = resolveAlias(candidate, ['signingConfig', 'signing_config']);
|
|
39476
|
-
if (signingConfig !== undefined) {
|
|
39477
|
-
result.signingConfig = signingConfig;
|
|
39478
|
-
}
|
|
39479
|
-
const privateKeyPem = resolveAlias(candidate, [
|
|
39480
|
-
'privateKeyPem',
|
|
39481
|
-
'private_key_pem',
|
|
39482
|
-
]);
|
|
39483
|
-
if (privateKeyPem !== undefined) {
|
|
39484
|
-
result.privateKeyPem = privateKeyPem;
|
|
39485
|
-
}
|
|
39486
|
-
const keyId = resolveAlias(candidate, [
|
|
39487
|
-
'keyId',
|
|
39488
|
-
'key_id',
|
|
39489
|
-
]);
|
|
39490
|
-
if (keyId !== undefined) {
|
|
39491
|
-
result.keyId = keyId;
|
|
39492
|
-
}
|
|
39493
|
-
return result;
|
|
39494
|
-
}
|
|
39495
|
-
class EdDSAEnvelopeSigner {
|
|
39496
|
-
constructor(options = {}) {
|
|
39497
|
-
const normalized = normalizeSignerOptions(options);
|
|
39498
|
-
const provider = normalized.cryptoProvider ?? null;
|
|
39499
|
-
if (!provider) {
|
|
39500
|
-
throw new Error('No crypto provider is configured for signing');
|
|
39501
|
-
}
|
|
39502
|
-
this.crypto = provider;
|
|
39503
|
-
const signingConfigOption = normalized.signingConfig;
|
|
39504
|
-
if (signingConfigOption instanceof SigningConfig) {
|
|
39505
|
-
this.signingConfig = signingConfigOption;
|
|
39506
|
-
}
|
|
39507
|
-
else if (signingConfigOption) {
|
|
39508
|
-
this.signingConfig = new SigningConfig(signingConfigOption);
|
|
39509
|
-
}
|
|
39510
|
-
else {
|
|
39511
|
-
this.signingConfig = new SigningConfig();
|
|
39512
|
-
}
|
|
39513
|
-
this.explicitPrivateKey = normalized.privateKeyPem;
|
|
39514
|
-
this.explicitKeyId = normalized.keyId;
|
|
39515
|
-
}
|
|
39516
|
-
signEnvelope(envelope, { physicalPath }) {
|
|
39517
|
-
if (!envelope.sid) {
|
|
39518
|
-
throw new Error('Envelope missing sid');
|
|
39519
|
-
}
|
|
39520
|
-
const frame = envelope.frame;
|
|
39521
|
-
if (frame.type === 'Data') {
|
|
39522
|
-
const dataFrame = frame;
|
|
39523
|
-
if (!dataFrame.pd) {
|
|
39524
|
-
const payload = dataFrame.payload ?? '';
|
|
39525
|
-
const payloadString = payload === '' ? '' : canonicalJson(payload);
|
|
39526
|
-
dataFrame.pd = secureDigest(payloadString);
|
|
39527
|
-
}
|
|
39528
|
-
}
|
|
39529
|
-
const digest = frameDigest(frame);
|
|
39530
|
-
const immutable = canonicalJson(immutableHeaders(envelope));
|
|
39531
|
-
const sidDigest = secureDigest(physicalPath);
|
|
39532
|
-
const tbs = new Uint8Array(encodeUtf8(sidDigest).length +
|
|
39533
|
-
1 +
|
|
39534
|
-
encodeUtf8(immutable).length +
|
|
39535
|
-
1 +
|
|
39536
|
-
encodeUtf8(digest).length);
|
|
39537
|
-
const sidBytes = encodeUtf8(sidDigest);
|
|
39538
|
-
const immBytes = encodeUtf8(immutable);
|
|
39539
|
-
const digBytes = encodeUtf8(digest);
|
|
39540
|
-
let offset = 0;
|
|
39541
|
-
tbs.set(sidBytes, offset);
|
|
39542
|
-
offset += sidBytes.length;
|
|
39543
|
-
tbs[offset] = 0x1f;
|
|
39544
|
-
offset += 1;
|
|
39545
|
-
tbs.set(immBytes, offset);
|
|
39546
|
-
offset += immBytes.length;
|
|
39547
|
-
tbs[offset] = 0x1f;
|
|
39548
|
-
offset += 1;
|
|
39549
|
-
tbs.set(digBytes, offset);
|
|
39550
|
-
const privateKey = this.loadPrivateKey();
|
|
39551
|
-
const signatureBytes = ed25519.sign(tbs, privateKey);
|
|
39552
|
-
const signature = urlsafeBase64Encode(signatureBytes);
|
|
39553
|
-
const kid = this.determineKeyId();
|
|
39554
|
-
const signatureHeader = {
|
|
39555
|
-
kid,
|
|
39556
|
-
val: signature,
|
|
39557
|
-
alg: 'EdDSA',
|
|
39558
|
-
};
|
|
39559
|
-
const secHeader = envelope.sec ?? {};
|
|
39560
|
-
secHeader.sig = signatureHeader;
|
|
39561
|
-
envelope.sec = secHeader;
|
|
39562
|
-
return envelope;
|
|
39563
|
-
}
|
|
39564
|
-
loadPrivateKey() {
|
|
39565
|
-
const pem = this.explicitPrivateKey ??
|
|
39566
|
-
readStringProperty(this.crypto, 'signingPrivatePem', 'signing_private_pem');
|
|
39567
|
-
if (!pem) {
|
|
39568
|
-
throw new Error('Crypto provider does not expose a signing private key');
|
|
39569
|
-
}
|
|
39570
|
-
return parseEd25519PrivateKey(pem);
|
|
39571
|
-
}
|
|
39572
|
-
determineKeyId() {
|
|
39573
|
-
if (this.explicitKeyId) {
|
|
39574
|
-
return this.explicitKeyId;
|
|
39575
|
-
}
|
|
39576
|
-
if (this.signingConfig.signingMaterial === core.SigningMaterial.X509_CHAIN) {
|
|
39577
|
-
const certificateProvider = this
|
|
39578
|
-
.crypto;
|
|
39579
|
-
const jwk = certificateProvider.nodeJwk?.();
|
|
39580
|
-
if (jwk && typeof jwk === 'object' && 'kid' in jwk && 'x5c' in jwk) {
|
|
39581
|
-
const kid = jwk.kid;
|
|
39582
|
-
if (typeof kid === 'string' && kid.length > 0) {
|
|
39583
|
-
return kid;
|
|
39584
|
-
}
|
|
39585
|
-
}
|
|
39586
|
-
}
|
|
39587
|
-
const fallback = readStringProperty(this.crypto, 'signatureKeyId', 'signature_key_id');
|
|
39588
|
-
if (!fallback) {
|
|
39589
|
-
throw new Error('Crypto provider does not expose a signature key id');
|
|
39590
|
-
}
|
|
39591
|
-
return fallback;
|
|
39592
|
-
}
|
|
39593
|
-
}
|
|
39594
|
-
|
|
39595
|
-
var eddsaEnvelopeSigner = /*#__PURE__*/Object.freeze({
|
|
39596
|
-
__proto__: null,
|
|
39597
|
-
EdDSAEnvelopeSigner: EdDSAEnvelopeSigner
|
|
39598
|
-
});
|
|
39599
|
-
|
|
39600
39600
|
async function loadPublicKey(jwk, signingConfig) {
|
|
39601
39601
|
if (jwk.x5c) {
|
|
39602
39602
|
if (signingConfig.signingMaterial !== core.SigningMaterial.X509_CHAIN) {
|
|
@@ -39884,6 +39884,7 @@ exports.ENV_VAR_JWT_REVERSE_AUTH_AUDIENCE = ENV_VAR_JWT_REVERSE_AUTH_AUDIENCE;
|
|
|
39884
39884
|
exports.ENV_VAR_JWT_REVERSE_AUTH_TRUSTED_ISSUER = ENV_VAR_JWT_REVERSE_AUTH_TRUSTED_ISSUER;
|
|
39885
39885
|
exports.ENV_VAR_JWT_TRUSTED_ISSUER = ENV_VAR_JWT_TRUSTED_ISSUER;
|
|
39886
39886
|
exports.ENV_VAR_SHOW_ENVELOPES = ENV_VAR_SHOW_ENVELOPES$1;
|
|
39887
|
+
exports.EdDSAEnvelopeSigner = EdDSAEnvelopeSigner;
|
|
39887
39888
|
exports.EncryptedKeyValueStore = EncryptedKeyValueStore;
|
|
39888
39889
|
exports.EncryptedStorageProviderBase = EncryptedStorageProviderBase;
|
|
39889
39890
|
exports.EncryptedValue = EncryptedValue;
|
|
@@ -40017,6 +40018,7 @@ exports.assertGrant = assertGrant;
|
|
|
40017
40018
|
exports.basicConfig = basicConfig;
|
|
40018
40019
|
exports.broadcastChannelGrantToConnectorConfig = broadcastChannelGrantToConnectorConfig;
|
|
40019
40020
|
exports.camelToSnakeCase = camelToSnakeCase;
|
|
40021
|
+
exports.canonicalJson = canonicalJson;
|
|
40020
40022
|
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
40021
40023
|
exports.color = color;
|
|
40022
40024
|
exports.compareCryptoLevels = compareCryptoLevels;
|
|
@@ -40036,12 +40038,14 @@ exports.createX25519Keypair = createX25519Keypair;
|
|
|
40036
40038
|
exports.credentialToString = credentialToString;
|
|
40037
40039
|
exports.currentTraceId = currentTraceId$1;
|
|
40038
40040
|
exports.debounce = debounce;
|
|
40041
|
+
exports.decodeBase64Url = decodeBase64Url;
|
|
40039
40042
|
exports.decodeFameDataPayload = decodeFameDataPayload;
|
|
40040
40043
|
exports.deepMerge = deepMerge;
|
|
40041
40044
|
exports.defaultJsonEncoder = defaultJsonEncoder;
|
|
40042
40045
|
exports.delay = delay;
|
|
40043
40046
|
exports.dropEmpty = dropEmpty;
|
|
40044
40047
|
exports.enableLogging = enableLogging;
|
|
40048
|
+
exports.encodeUtf8 = encodeUtf8;
|
|
40045
40049
|
exports.ensureRuntimeFactoriesRegistered = ensureRuntimeFactoriesRegistered;
|
|
40046
40050
|
exports.extractId = extractId;
|
|
40047
40051
|
exports.extractPoolAddressBase = extractPoolAddressBase;
|
|
@@ -40049,6 +40053,7 @@ exports.extractPoolBase = extractPoolBase;
|
|
|
40049
40053
|
exports.filterKeysByUse = filterKeysByUse;
|
|
40050
40054
|
exports.formatTimestamp = formatTimestamp;
|
|
40051
40055
|
exports.formatTimestampForConsole = formatTimestampForConsole$1;
|
|
40056
|
+
exports.frameDigest = frameDigest;
|
|
40052
40057
|
exports.getCurrentEnvelope = getCurrentEnvelope;
|
|
40053
40058
|
exports.getFameRoot = getFameRoot;
|
|
40054
40059
|
exports.getKeyProvider = getKeyProvider;
|
|
@@ -40058,6 +40063,7 @@ exports.hasCryptoSupport = hasCryptoSupport;
|
|
|
40058
40063
|
exports.hostnameToLogical = hostnameToLogical;
|
|
40059
40064
|
exports.hostnamesToLogicals = hostnamesToLogicals;
|
|
40060
40065
|
exports.httpGrantToConnectorConfig = httpGrantToConnectorConfig;
|
|
40066
|
+
exports.immutableHeaders = immutableHeaders;
|
|
40061
40067
|
exports.inPageGrantToConnectorConfig = inPageGrantToConnectorConfig;
|
|
40062
40068
|
exports.isAuthInjectionStrategy = isAuthInjectionStrategy;
|
|
40063
40069
|
exports.isBroadcastChannelConnectionGrant = isBroadcastChannelConnectionGrant;
|