@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/node/node.cjs
CHANGED
|
@@ -12,11 +12,11 @@ var ed25519_js = require('@noble/curves/ed25519.js');
|
|
|
12
12
|
var hkdf_js = require('@noble/hashes/hkdf.js');
|
|
13
13
|
var sha2_js = require('@noble/hashes/sha2.js');
|
|
14
14
|
var utils_js = require('@noble/hashes/utils.js');
|
|
15
|
+
var ed25519 = require('@noble/ed25519');
|
|
15
16
|
var fastify = require('fastify');
|
|
16
17
|
var websocketPlugin = require('@fastify/websocket');
|
|
17
18
|
var formbody = require('@fastify/formbody');
|
|
18
19
|
var node_crypto = require('node:crypto');
|
|
19
|
-
var ed25519 = require('@noble/ed25519');
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Cross-platform logging utilities for Naylence Fame
|
|
@@ -5372,12 +5372,12 @@ for (const [name, config] of Object.entries(SQLITE_PROFILES)) {
|
|
|
5372
5372
|
}
|
|
5373
5373
|
|
|
5374
5374
|
// This file is auto-generated during build - do not edit manually
|
|
5375
|
-
// Generated from package.json version: 0.3.5-test.
|
|
5375
|
+
// Generated from package.json version: 0.3.5-test.923
|
|
5376
5376
|
/**
|
|
5377
5377
|
* The package version, injected at build time.
|
|
5378
5378
|
* @internal
|
|
5379
5379
|
*/
|
|
5380
|
-
const VERSION = '0.3.5-test.
|
|
5380
|
+
const VERSION = '0.3.5-test.923';
|
|
5381
5381
|
|
|
5382
5382
|
/**
|
|
5383
5383
|
* Fame errors module - Fame protocol specific error classes
|
|
@@ -26322,6 +26322,251 @@ class SigningConfig {
|
|
|
26322
26322
|
}
|
|
26323
26323
|
}
|
|
26324
26324
|
|
|
26325
|
+
function hasBuffer() {
|
|
26326
|
+
return typeof Buffer !== 'undefined';
|
|
26327
|
+
}
|
|
26328
|
+
function readStringProperty(source, ...names) {
|
|
26329
|
+
if (!source || typeof source !== 'object') {
|
|
26330
|
+
return undefined;
|
|
26331
|
+
}
|
|
26332
|
+
for (const name of names) {
|
|
26333
|
+
const value = source[name];
|
|
26334
|
+
if (typeof value === 'string' && value.length > 0) {
|
|
26335
|
+
return value;
|
|
26336
|
+
}
|
|
26337
|
+
}
|
|
26338
|
+
return undefined;
|
|
26339
|
+
}
|
|
26340
|
+
function decodePem(pem) {
|
|
26341
|
+
const base64 = pem
|
|
26342
|
+
.replace(/-----BEGIN[^-]+-----/g, '')
|
|
26343
|
+
.replace(/-----END[^-]+-----/g, '')
|
|
26344
|
+
.replace(/\s+/g, '');
|
|
26345
|
+
if (typeof atob === 'function') {
|
|
26346
|
+
const binary = atob(base64);
|
|
26347
|
+
const bytes = new Uint8Array(binary.length);
|
|
26348
|
+
for (let i = 0; i < binary.length; i += 1) {
|
|
26349
|
+
bytes[i] = binary.charCodeAt(i);
|
|
26350
|
+
}
|
|
26351
|
+
return bytes;
|
|
26352
|
+
}
|
|
26353
|
+
if (hasBuffer()) {
|
|
26354
|
+
return Uint8Array.from(Buffer.from(base64, 'base64'));
|
|
26355
|
+
}
|
|
26356
|
+
throw new Error('Base64 decoding is not available in this environment');
|
|
26357
|
+
}
|
|
26358
|
+
function readLength(data, offset) {
|
|
26359
|
+
const initial = data[offset];
|
|
26360
|
+
if (initial === undefined) {
|
|
26361
|
+
throw new Error('Unexpected end of ASN.1 data');
|
|
26362
|
+
}
|
|
26363
|
+
if ((initial & 0x80) === 0) {
|
|
26364
|
+
return { length: initial, nextOffset: offset + 1 };
|
|
26365
|
+
}
|
|
26366
|
+
const lengthOfLength = initial & 0x7f;
|
|
26367
|
+
if (lengthOfLength === 0 || lengthOfLength > 4) {
|
|
26368
|
+
throw new Error('Unsupported ASN.1 length encoding');
|
|
26369
|
+
}
|
|
26370
|
+
let length = 0;
|
|
26371
|
+
let position = offset + 1;
|
|
26372
|
+
for (let i = 0; i < lengthOfLength; i += 1) {
|
|
26373
|
+
const byte = data[position];
|
|
26374
|
+
if (byte === undefined) {
|
|
26375
|
+
throw new Error('Unexpected end of ASN.1 data');
|
|
26376
|
+
}
|
|
26377
|
+
length = (length << 8) | byte;
|
|
26378
|
+
position += 1;
|
|
26379
|
+
}
|
|
26380
|
+
return { length, nextOffset: position };
|
|
26381
|
+
}
|
|
26382
|
+
function readElement(data, offset, tag) {
|
|
26383
|
+
if (data[offset] !== tag) {
|
|
26384
|
+
throw new Error(`Unexpected ASN.1 tag: expected 0x${tag.toString(16)}, got 0x${(data[offset] ?? 0).toString(16)}`);
|
|
26385
|
+
}
|
|
26386
|
+
const { length, nextOffset } = readLength(data, offset + 1);
|
|
26387
|
+
const contentOffset = nextOffset;
|
|
26388
|
+
return {
|
|
26389
|
+
length,
|
|
26390
|
+
contentOffset,
|
|
26391
|
+
nextOffset: contentOffset + length,
|
|
26392
|
+
};
|
|
26393
|
+
}
|
|
26394
|
+
function parseEd25519PrivateKey(pem) {
|
|
26395
|
+
const raw = decodePem(pem);
|
|
26396
|
+
if (raw.length === 32) {
|
|
26397
|
+
return raw.slice();
|
|
26398
|
+
}
|
|
26399
|
+
// Handle PKCS#8 structure defined in RFC 8410
|
|
26400
|
+
const sequence = readElement(raw, 0, 0x30);
|
|
26401
|
+
const version = readElement(raw, sequence.contentOffset, 0x02);
|
|
26402
|
+
let offset = version.nextOffset;
|
|
26403
|
+
const algorithm = readElement(raw, offset, 0x30);
|
|
26404
|
+
offset = algorithm.nextOffset;
|
|
26405
|
+
const privateKey = readElement(raw, offset, 0x04);
|
|
26406
|
+
const privateContent = raw.subarray(privateKey.contentOffset, privateKey.contentOffset + privateKey.length);
|
|
26407
|
+
if (privateContent.length === 32) {
|
|
26408
|
+
return privateContent.slice();
|
|
26409
|
+
}
|
|
26410
|
+
if (privateContent.length >= 34 && privateContent[0] === 0x04) {
|
|
26411
|
+
const innerLength = privateContent[1];
|
|
26412
|
+
if (innerLength !== 32 || privateContent.length < innerLength + 2) {
|
|
26413
|
+
throw new Error('Unexpected Ed25519 private key length');
|
|
26414
|
+
}
|
|
26415
|
+
return privateContent.subarray(2, 34);
|
|
26416
|
+
}
|
|
26417
|
+
throw new Error('Unsupported Ed25519 private key structure');
|
|
26418
|
+
}
|
|
26419
|
+
const textEncoder = typeof TextEncoder !== 'undefined' ? new TextEncoder() : undefined;
|
|
26420
|
+
function encodeUtf8(value) {
|
|
26421
|
+
if (textEncoder) {
|
|
26422
|
+
return textEncoder.encode(value);
|
|
26423
|
+
}
|
|
26424
|
+
if (hasBuffer()) {
|
|
26425
|
+
return Uint8Array.from(Buffer.from(value, 'utf8'));
|
|
26426
|
+
}
|
|
26427
|
+
throw new Error('No UTF-8 encoder available in this environment');
|
|
26428
|
+
}
|
|
26429
|
+
|
|
26430
|
+
if (!ed25519.hashes.sha512) {
|
|
26431
|
+
ed25519.hashes.sha512 = (message) => sha2_js.sha512(message);
|
|
26432
|
+
}
|
|
26433
|
+
function normalizeSignerOptions(options) {
|
|
26434
|
+
if (!options || typeof options !== 'object') {
|
|
26435
|
+
return {};
|
|
26436
|
+
}
|
|
26437
|
+
const candidate = options;
|
|
26438
|
+
const result = {
|
|
26439
|
+
...options,
|
|
26440
|
+
};
|
|
26441
|
+
const cryptoProvider = resolveAlias(candidate, ['cryptoProvider', 'crypto_provider']);
|
|
26442
|
+
if (cryptoProvider !== undefined) {
|
|
26443
|
+
result.cryptoProvider = cryptoProvider ?? null;
|
|
26444
|
+
}
|
|
26445
|
+
const signingConfig = resolveAlias(candidate, ['signingConfig', 'signing_config']);
|
|
26446
|
+
if (signingConfig !== undefined) {
|
|
26447
|
+
result.signingConfig = signingConfig;
|
|
26448
|
+
}
|
|
26449
|
+
const privateKeyPem = resolveAlias(candidate, [
|
|
26450
|
+
'privateKeyPem',
|
|
26451
|
+
'private_key_pem',
|
|
26452
|
+
]);
|
|
26453
|
+
if (privateKeyPem !== undefined) {
|
|
26454
|
+
result.privateKeyPem = privateKeyPem;
|
|
26455
|
+
}
|
|
26456
|
+
const keyId = resolveAlias(candidate, [
|
|
26457
|
+
'keyId',
|
|
26458
|
+
'key_id',
|
|
26459
|
+
]);
|
|
26460
|
+
if (keyId !== undefined) {
|
|
26461
|
+
result.keyId = keyId;
|
|
26462
|
+
}
|
|
26463
|
+
return result;
|
|
26464
|
+
}
|
|
26465
|
+
class EdDSAEnvelopeSigner {
|
|
26466
|
+
constructor(options = {}) {
|
|
26467
|
+
const normalized = normalizeSignerOptions(options);
|
|
26468
|
+
const provider = normalized.cryptoProvider ?? null;
|
|
26469
|
+
if (!provider) {
|
|
26470
|
+
throw new Error('No crypto provider is configured for signing');
|
|
26471
|
+
}
|
|
26472
|
+
this.crypto = provider;
|
|
26473
|
+
const signingConfigOption = normalized.signingConfig;
|
|
26474
|
+
if (signingConfigOption instanceof SigningConfig) {
|
|
26475
|
+
this.signingConfig = signingConfigOption;
|
|
26476
|
+
}
|
|
26477
|
+
else if (signingConfigOption) {
|
|
26478
|
+
this.signingConfig = new SigningConfig(signingConfigOption);
|
|
26479
|
+
}
|
|
26480
|
+
else {
|
|
26481
|
+
this.signingConfig = new SigningConfig();
|
|
26482
|
+
}
|
|
26483
|
+
this.explicitPrivateKey = normalized.privateKeyPem;
|
|
26484
|
+
this.explicitKeyId = normalized.keyId;
|
|
26485
|
+
}
|
|
26486
|
+
signEnvelope(envelope, { physicalPath }) {
|
|
26487
|
+
if (!envelope.sid) {
|
|
26488
|
+
throw new Error('Envelope missing sid');
|
|
26489
|
+
}
|
|
26490
|
+
const frame = envelope.frame;
|
|
26491
|
+
if (frame.type === 'Data') {
|
|
26492
|
+
const dataFrame = frame;
|
|
26493
|
+
if (!dataFrame.pd) {
|
|
26494
|
+
const payload = dataFrame.payload ?? '';
|
|
26495
|
+
const payloadString = payload === '' ? '' : canonicalJson(payload);
|
|
26496
|
+
dataFrame.pd = secureDigest(payloadString);
|
|
26497
|
+
}
|
|
26498
|
+
}
|
|
26499
|
+
const digest = frameDigest(frame);
|
|
26500
|
+
const immutable = canonicalJson(immutableHeaders(envelope));
|
|
26501
|
+
const sidDigest = secureDigest(physicalPath);
|
|
26502
|
+
const tbs = new Uint8Array(encodeUtf8(sidDigest).length +
|
|
26503
|
+
1 +
|
|
26504
|
+
encodeUtf8(immutable).length +
|
|
26505
|
+
1 +
|
|
26506
|
+
encodeUtf8(digest).length);
|
|
26507
|
+
const sidBytes = encodeUtf8(sidDigest);
|
|
26508
|
+
const immBytes = encodeUtf8(immutable);
|
|
26509
|
+
const digBytes = encodeUtf8(digest);
|
|
26510
|
+
let offset = 0;
|
|
26511
|
+
tbs.set(sidBytes, offset);
|
|
26512
|
+
offset += sidBytes.length;
|
|
26513
|
+
tbs[offset] = 0x1f;
|
|
26514
|
+
offset += 1;
|
|
26515
|
+
tbs.set(immBytes, offset);
|
|
26516
|
+
offset += immBytes.length;
|
|
26517
|
+
tbs[offset] = 0x1f;
|
|
26518
|
+
offset += 1;
|
|
26519
|
+
tbs.set(digBytes, offset);
|
|
26520
|
+
const privateKey = this.loadPrivateKey();
|
|
26521
|
+
const signatureBytes = ed25519.sign(tbs, privateKey);
|
|
26522
|
+
const signature = urlsafeBase64Encode(signatureBytes);
|
|
26523
|
+
const kid = this.determineKeyId();
|
|
26524
|
+
const signatureHeader = {
|
|
26525
|
+
kid,
|
|
26526
|
+
val: signature,
|
|
26527
|
+
alg: 'EdDSA',
|
|
26528
|
+
};
|
|
26529
|
+
const secHeader = envelope.sec ?? {};
|
|
26530
|
+
secHeader.sig = signatureHeader;
|
|
26531
|
+
envelope.sec = secHeader;
|
|
26532
|
+
return envelope;
|
|
26533
|
+
}
|
|
26534
|
+
loadPrivateKey() {
|
|
26535
|
+
const pem = this.explicitPrivateKey ??
|
|
26536
|
+
readStringProperty(this.crypto, 'signingPrivatePem', 'signing_private_pem');
|
|
26537
|
+
if (!pem) {
|
|
26538
|
+
throw new Error('Crypto provider does not expose a signing private key');
|
|
26539
|
+
}
|
|
26540
|
+
return parseEd25519PrivateKey(pem);
|
|
26541
|
+
}
|
|
26542
|
+
determineKeyId() {
|
|
26543
|
+
if (this.explicitKeyId) {
|
|
26544
|
+
return this.explicitKeyId;
|
|
26545
|
+
}
|
|
26546
|
+
if (this.signingConfig.signingMaterial === core.SigningMaterial.X509_CHAIN) {
|
|
26547
|
+
const certificateProvider = this
|
|
26548
|
+
.crypto;
|
|
26549
|
+
const jwk = certificateProvider.nodeJwk?.();
|
|
26550
|
+
if (jwk && typeof jwk === 'object' && 'kid' in jwk && 'x5c' in jwk) {
|
|
26551
|
+
const kid = jwk.kid;
|
|
26552
|
+
if (typeof kid === 'string' && kid.length > 0) {
|
|
26553
|
+
return kid;
|
|
26554
|
+
}
|
|
26555
|
+
}
|
|
26556
|
+
}
|
|
26557
|
+
const fallback = readStringProperty(this.crypto, 'signatureKeyId', 'signature_key_id');
|
|
26558
|
+
if (!fallback) {
|
|
26559
|
+
throw new Error('Crypto provider does not expose a signature key id');
|
|
26560
|
+
}
|
|
26561
|
+
return fallback;
|
|
26562
|
+
}
|
|
26563
|
+
}
|
|
26564
|
+
|
|
26565
|
+
var eddsaEnvelopeSigner = /*#__PURE__*/Object.freeze({
|
|
26566
|
+
__proto__: null,
|
|
26567
|
+
EdDSAEnvelopeSigner: EdDSAEnvelopeSigner
|
|
26568
|
+
});
|
|
26569
|
+
|
|
26325
26570
|
// Legacy global crypto provider accessors are intentionally disabled to force
|
|
26326
26571
|
// explicit dependency wiring. If a component still needs a global provider,
|
|
26327
26572
|
// refactor it to accept one via configuration instead of re-enabling this code.
|
|
@@ -41484,251 +41729,6 @@ var sharedSecretTokenVerifier = /*#__PURE__*/Object.freeze({
|
|
|
41484
41729
|
SharedSecretTokenVerifier: SharedSecretTokenVerifier
|
|
41485
41730
|
});
|
|
41486
41731
|
|
|
41487
|
-
function hasBuffer() {
|
|
41488
|
-
return typeof Buffer !== 'undefined';
|
|
41489
|
-
}
|
|
41490
|
-
function readStringProperty(source, ...names) {
|
|
41491
|
-
if (!source || typeof source !== 'object') {
|
|
41492
|
-
return undefined;
|
|
41493
|
-
}
|
|
41494
|
-
for (const name of names) {
|
|
41495
|
-
const value = source[name];
|
|
41496
|
-
if (typeof value === 'string' && value.length > 0) {
|
|
41497
|
-
return value;
|
|
41498
|
-
}
|
|
41499
|
-
}
|
|
41500
|
-
return undefined;
|
|
41501
|
-
}
|
|
41502
|
-
function decodePem(pem) {
|
|
41503
|
-
const base64 = pem
|
|
41504
|
-
.replace(/-----BEGIN[^-]+-----/g, '')
|
|
41505
|
-
.replace(/-----END[^-]+-----/g, '')
|
|
41506
|
-
.replace(/\s+/g, '');
|
|
41507
|
-
if (typeof atob === 'function') {
|
|
41508
|
-
const binary = atob(base64);
|
|
41509
|
-
const bytes = new Uint8Array(binary.length);
|
|
41510
|
-
for (let i = 0; i < binary.length; i += 1) {
|
|
41511
|
-
bytes[i] = binary.charCodeAt(i);
|
|
41512
|
-
}
|
|
41513
|
-
return bytes;
|
|
41514
|
-
}
|
|
41515
|
-
if (hasBuffer()) {
|
|
41516
|
-
return Uint8Array.from(Buffer.from(base64, 'base64'));
|
|
41517
|
-
}
|
|
41518
|
-
throw new Error('Base64 decoding is not available in this environment');
|
|
41519
|
-
}
|
|
41520
|
-
function readLength(data, offset) {
|
|
41521
|
-
const initial = data[offset];
|
|
41522
|
-
if (initial === undefined) {
|
|
41523
|
-
throw new Error('Unexpected end of ASN.1 data');
|
|
41524
|
-
}
|
|
41525
|
-
if ((initial & 0x80) === 0) {
|
|
41526
|
-
return { length: initial, nextOffset: offset + 1 };
|
|
41527
|
-
}
|
|
41528
|
-
const lengthOfLength = initial & 0x7f;
|
|
41529
|
-
if (lengthOfLength === 0 || lengthOfLength > 4) {
|
|
41530
|
-
throw new Error('Unsupported ASN.1 length encoding');
|
|
41531
|
-
}
|
|
41532
|
-
let length = 0;
|
|
41533
|
-
let position = offset + 1;
|
|
41534
|
-
for (let i = 0; i < lengthOfLength; i += 1) {
|
|
41535
|
-
const byte = data[position];
|
|
41536
|
-
if (byte === undefined) {
|
|
41537
|
-
throw new Error('Unexpected end of ASN.1 data');
|
|
41538
|
-
}
|
|
41539
|
-
length = (length << 8) | byte;
|
|
41540
|
-
position += 1;
|
|
41541
|
-
}
|
|
41542
|
-
return { length, nextOffset: position };
|
|
41543
|
-
}
|
|
41544
|
-
function readElement(data, offset, tag) {
|
|
41545
|
-
if (data[offset] !== tag) {
|
|
41546
|
-
throw new Error(`Unexpected ASN.1 tag: expected 0x${tag.toString(16)}, got 0x${(data[offset] ?? 0).toString(16)}`);
|
|
41547
|
-
}
|
|
41548
|
-
const { length, nextOffset } = readLength(data, offset + 1);
|
|
41549
|
-
const contentOffset = nextOffset;
|
|
41550
|
-
return {
|
|
41551
|
-
length,
|
|
41552
|
-
contentOffset,
|
|
41553
|
-
nextOffset: contentOffset + length,
|
|
41554
|
-
};
|
|
41555
|
-
}
|
|
41556
|
-
function parseEd25519PrivateKey(pem) {
|
|
41557
|
-
const raw = decodePem(pem);
|
|
41558
|
-
if (raw.length === 32) {
|
|
41559
|
-
return raw.slice();
|
|
41560
|
-
}
|
|
41561
|
-
// Handle PKCS#8 structure defined in RFC 8410
|
|
41562
|
-
const sequence = readElement(raw, 0, 0x30);
|
|
41563
|
-
const version = readElement(raw, sequence.contentOffset, 0x02);
|
|
41564
|
-
let offset = version.nextOffset;
|
|
41565
|
-
const algorithm = readElement(raw, offset, 0x30);
|
|
41566
|
-
offset = algorithm.nextOffset;
|
|
41567
|
-
const privateKey = readElement(raw, offset, 0x04);
|
|
41568
|
-
const privateContent = raw.subarray(privateKey.contentOffset, privateKey.contentOffset + privateKey.length);
|
|
41569
|
-
if (privateContent.length === 32) {
|
|
41570
|
-
return privateContent.slice();
|
|
41571
|
-
}
|
|
41572
|
-
if (privateContent.length >= 34 && privateContent[0] === 0x04) {
|
|
41573
|
-
const innerLength = privateContent[1];
|
|
41574
|
-
if (innerLength !== 32 || privateContent.length < innerLength + 2) {
|
|
41575
|
-
throw new Error('Unexpected Ed25519 private key length');
|
|
41576
|
-
}
|
|
41577
|
-
return privateContent.subarray(2, 34);
|
|
41578
|
-
}
|
|
41579
|
-
throw new Error('Unsupported Ed25519 private key structure');
|
|
41580
|
-
}
|
|
41581
|
-
const textEncoder = typeof TextEncoder !== 'undefined' ? new TextEncoder() : undefined;
|
|
41582
|
-
function encodeUtf8(value) {
|
|
41583
|
-
if (textEncoder) {
|
|
41584
|
-
return textEncoder.encode(value);
|
|
41585
|
-
}
|
|
41586
|
-
if (hasBuffer()) {
|
|
41587
|
-
return Uint8Array.from(Buffer.from(value, 'utf8'));
|
|
41588
|
-
}
|
|
41589
|
-
throw new Error('No UTF-8 encoder available in this environment');
|
|
41590
|
-
}
|
|
41591
|
-
|
|
41592
|
-
if (!ed25519.hashes.sha512) {
|
|
41593
|
-
ed25519.hashes.sha512 = (message) => sha2_js.sha512(message);
|
|
41594
|
-
}
|
|
41595
|
-
function normalizeSignerOptions(options) {
|
|
41596
|
-
if (!options || typeof options !== 'object') {
|
|
41597
|
-
return {};
|
|
41598
|
-
}
|
|
41599
|
-
const candidate = options;
|
|
41600
|
-
const result = {
|
|
41601
|
-
...options,
|
|
41602
|
-
};
|
|
41603
|
-
const cryptoProvider = resolveAlias(candidate, ['cryptoProvider', 'crypto_provider']);
|
|
41604
|
-
if (cryptoProvider !== undefined) {
|
|
41605
|
-
result.cryptoProvider = cryptoProvider ?? null;
|
|
41606
|
-
}
|
|
41607
|
-
const signingConfig = resolveAlias(candidate, ['signingConfig', 'signing_config']);
|
|
41608
|
-
if (signingConfig !== undefined) {
|
|
41609
|
-
result.signingConfig = signingConfig;
|
|
41610
|
-
}
|
|
41611
|
-
const privateKeyPem = resolveAlias(candidate, [
|
|
41612
|
-
'privateKeyPem',
|
|
41613
|
-
'private_key_pem',
|
|
41614
|
-
]);
|
|
41615
|
-
if (privateKeyPem !== undefined) {
|
|
41616
|
-
result.privateKeyPem = privateKeyPem;
|
|
41617
|
-
}
|
|
41618
|
-
const keyId = resolveAlias(candidate, [
|
|
41619
|
-
'keyId',
|
|
41620
|
-
'key_id',
|
|
41621
|
-
]);
|
|
41622
|
-
if (keyId !== undefined) {
|
|
41623
|
-
result.keyId = keyId;
|
|
41624
|
-
}
|
|
41625
|
-
return result;
|
|
41626
|
-
}
|
|
41627
|
-
class EdDSAEnvelopeSigner {
|
|
41628
|
-
constructor(options = {}) {
|
|
41629
|
-
const normalized = normalizeSignerOptions(options);
|
|
41630
|
-
const provider = normalized.cryptoProvider ?? null;
|
|
41631
|
-
if (!provider) {
|
|
41632
|
-
throw new Error('No crypto provider is configured for signing');
|
|
41633
|
-
}
|
|
41634
|
-
this.crypto = provider;
|
|
41635
|
-
const signingConfigOption = normalized.signingConfig;
|
|
41636
|
-
if (signingConfigOption instanceof SigningConfig) {
|
|
41637
|
-
this.signingConfig = signingConfigOption;
|
|
41638
|
-
}
|
|
41639
|
-
else if (signingConfigOption) {
|
|
41640
|
-
this.signingConfig = new SigningConfig(signingConfigOption);
|
|
41641
|
-
}
|
|
41642
|
-
else {
|
|
41643
|
-
this.signingConfig = new SigningConfig();
|
|
41644
|
-
}
|
|
41645
|
-
this.explicitPrivateKey = normalized.privateKeyPem;
|
|
41646
|
-
this.explicitKeyId = normalized.keyId;
|
|
41647
|
-
}
|
|
41648
|
-
signEnvelope(envelope, { physicalPath }) {
|
|
41649
|
-
if (!envelope.sid) {
|
|
41650
|
-
throw new Error('Envelope missing sid');
|
|
41651
|
-
}
|
|
41652
|
-
const frame = envelope.frame;
|
|
41653
|
-
if (frame.type === 'Data') {
|
|
41654
|
-
const dataFrame = frame;
|
|
41655
|
-
if (!dataFrame.pd) {
|
|
41656
|
-
const payload = dataFrame.payload ?? '';
|
|
41657
|
-
const payloadString = payload === '' ? '' : canonicalJson(payload);
|
|
41658
|
-
dataFrame.pd = secureDigest(payloadString);
|
|
41659
|
-
}
|
|
41660
|
-
}
|
|
41661
|
-
const digest = frameDigest(frame);
|
|
41662
|
-
const immutable = canonicalJson(immutableHeaders(envelope));
|
|
41663
|
-
const sidDigest = secureDigest(physicalPath);
|
|
41664
|
-
const tbs = new Uint8Array(encodeUtf8(sidDigest).length +
|
|
41665
|
-
1 +
|
|
41666
|
-
encodeUtf8(immutable).length +
|
|
41667
|
-
1 +
|
|
41668
|
-
encodeUtf8(digest).length);
|
|
41669
|
-
const sidBytes = encodeUtf8(sidDigest);
|
|
41670
|
-
const immBytes = encodeUtf8(immutable);
|
|
41671
|
-
const digBytes = encodeUtf8(digest);
|
|
41672
|
-
let offset = 0;
|
|
41673
|
-
tbs.set(sidBytes, offset);
|
|
41674
|
-
offset += sidBytes.length;
|
|
41675
|
-
tbs[offset] = 0x1f;
|
|
41676
|
-
offset += 1;
|
|
41677
|
-
tbs.set(immBytes, offset);
|
|
41678
|
-
offset += immBytes.length;
|
|
41679
|
-
tbs[offset] = 0x1f;
|
|
41680
|
-
offset += 1;
|
|
41681
|
-
tbs.set(digBytes, offset);
|
|
41682
|
-
const privateKey = this.loadPrivateKey();
|
|
41683
|
-
const signatureBytes = ed25519.sign(tbs, privateKey);
|
|
41684
|
-
const signature = urlsafeBase64Encode(signatureBytes);
|
|
41685
|
-
const kid = this.determineKeyId();
|
|
41686
|
-
const signatureHeader = {
|
|
41687
|
-
kid,
|
|
41688
|
-
val: signature,
|
|
41689
|
-
alg: 'EdDSA',
|
|
41690
|
-
};
|
|
41691
|
-
const secHeader = envelope.sec ?? {};
|
|
41692
|
-
secHeader.sig = signatureHeader;
|
|
41693
|
-
envelope.sec = secHeader;
|
|
41694
|
-
return envelope;
|
|
41695
|
-
}
|
|
41696
|
-
loadPrivateKey() {
|
|
41697
|
-
const pem = this.explicitPrivateKey ??
|
|
41698
|
-
readStringProperty(this.crypto, 'signingPrivatePem', 'signing_private_pem');
|
|
41699
|
-
if (!pem) {
|
|
41700
|
-
throw new Error('Crypto provider does not expose a signing private key');
|
|
41701
|
-
}
|
|
41702
|
-
return parseEd25519PrivateKey(pem);
|
|
41703
|
-
}
|
|
41704
|
-
determineKeyId() {
|
|
41705
|
-
if (this.explicitKeyId) {
|
|
41706
|
-
return this.explicitKeyId;
|
|
41707
|
-
}
|
|
41708
|
-
if (this.signingConfig.signingMaterial === core.SigningMaterial.X509_CHAIN) {
|
|
41709
|
-
const certificateProvider = this
|
|
41710
|
-
.crypto;
|
|
41711
|
-
const jwk = certificateProvider.nodeJwk?.();
|
|
41712
|
-
if (jwk && typeof jwk === 'object' && 'kid' in jwk && 'x5c' in jwk) {
|
|
41713
|
-
const kid = jwk.kid;
|
|
41714
|
-
if (typeof kid === 'string' && kid.length > 0) {
|
|
41715
|
-
return kid;
|
|
41716
|
-
}
|
|
41717
|
-
}
|
|
41718
|
-
}
|
|
41719
|
-
const fallback = readStringProperty(this.crypto, 'signatureKeyId', 'signature_key_id');
|
|
41720
|
-
if (!fallback) {
|
|
41721
|
-
throw new Error('Crypto provider does not expose a signature key id');
|
|
41722
|
-
}
|
|
41723
|
-
return fallback;
|
|
41724
|
-
}
|
|
41725
|
-
}
|
|
41726
|
-
|
|
41727
|
-
var eddsaEnvelopeSigner = /*#__PURE__*/Object.freeze({
|
|
41728
|
-
__proto__: null,
|
|
41729
|
-
EdDSAEnvelopeSigner: EdDSAEnvelopeSigner
|
|
41730
|
-
});
|
|
41731
|
-
|
|
41732
41732
|
async function loadPublicKey(jwk, signingConfig) {
|
|
41733
41733
|
if (jwk.x5c) {
|
|
41734
41734
|
if (signingConfig.signingMaterial !== core.SigningMaterial.X509_CHAIN) {
|
|
@@ -42010,6 +42010,7 @@ exports.ENV_VAR_JWT_REVERSE_AUTH_AUDIENCE = ENV_VAR_JWT_REVERSE_AUTH_AUDIENCE;
|
|
|
42010
42010
|
exports.ENV_VAR_JWT_REVERSE_AUTH_TRUSTED_ISSUER = ENV_VAR_JWT_REVERSE_AUTH_TRUSTED_ISSUER;
|
|
42011
42011
|
exports.ENV_VAR_JWT_TRUSTED_ISSUER = ENV_VAR_JWT_TRUSTED_ISSUER;
|
|
42012
42012
|
exports.ENV_VAR_SHOW_ENVELOPES = ENV_VAR_SHOW_ENVELOPES$1;
|
|
42013
|
+
exports.EdDSAEnvelopeSigner = EdDSAEnvelopeSigner;
|
|
42013
42014
|
exports.EncryptedKeyValueStore = EncryptedKeyValueStore;
|
|
42014
42015
|
exports.EncryptedStorageProviderBase = EncryptedStorageProviderBase;
|
|
42015
42016
|
exports.EncryptedValue = EncryptedValue;
|
|
@@ -42150,6 +42151,7 @@ exports.assertGrant = assertGrant;
|
|
|
42150
42151
|
exports.basicConfig = basicConfig;
|
|
42151
42152
|
exports.broadcastChannelGrantToConnectorConfig = broadcastChannelGrantToConnectorConfig;
|
|
42152
42153
|
exports.camelToSnakeCase = camelToSnakeCase;
|
|
42154
|
+
exports.canonicalJson = canonicalJson;
|
|
42153
42155
|
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
42154
42156
|
exports.color = color;
|
|
42155
42157
|
exports.compareCryptoLevels = compareCryptoLevels;
|
|
@@ -42173,12 +42175,14 @@ exports.createX25519Keypair = createX25519Keypair;
|
|
|
42173
42175
|
exports.credentialToString = credentialToString;
|
|
42174
42176
|
exports.currentTraceId = currentTraceId$1;
|
|
42175
42177
|
exports.debounce = debounce;
|
|
42178
|
+
exports.decodeBase64Url = decodeBase64Url;
|
|
42176
42179
|
exports.decodeFameDataPayload = decodeFameDataPayload;
|
|
42177
42180
|
exports.deepMerge = deepMerge;
|
|
42178
42181
|
exports.defaultJsonEncoder = defaultJsonEncoder;
|
|
42179
42182
|
exports.delay = delay;
|
|
42180
42183
|
exports.dropEmpty = dropEmpty;
|
|
42181
42184
|
exports.enableLogging = enableLogging;
|
|
42185
|
+
exports.encodeUtf8 = encodeUtf8;
|
|
42182
42186
|
exports.ensureRuntimeFactoriesRegistered = ensureRuntimeFactoriesRegistered;
|
|
42183
42187
|
exports.extractId = extractId;
|
|
42184
42188
|
exports.extractPoolAddressBase = extractPoolAddressBase;
|
|
@@ -42186,6 +42190,7 @@ exports.extractPoolBase = extractPoolBase;
|
|
|
42186
42190
|
exports.filterKeysByUse = filterKeysByUse;
|
|
42187
42191
|
exports.formatTimestamp = formatTimestamp;
|
|
42188
42192
|
exports.formatTimestampForConsole = formatTimestampForConsole$1;
|
|
42193
|
+
exports.frameDigest = frameDigest;
|
|
42189
42194
|
exports.getCurrentEnvelope = getCurrentEnvelope;
|
|
42190
42195
|
exports.getFameRoot = getFameRoot;
|
|
42191
42196
|
exports.getHttpListenerInstance = getHttpListenerInstance;
|
|
@@ -42198,6 +42203,7 @@ exports.hasCryptoSupport = hasCryptoSupport;
|
|
|
42198
42203
|
exports.hostnameToLogical = hostnameToLogical;
|
|
42199
42204
|
exports.hostnamesToLogicals = hostnamesToLogicals;
|
|
42200
42205
|
exports.httpGrantToConnectorConfig = httpGrantToConnectorConfig;
|
|
42206
|
+
exports.immutableHeaders = immutableHeaders;
|
|
42201
42207
|
exports.inPageGrantToConnectorConfig = inPageGrantToConnectorConfig;
|
|
42202
42208
|
exports.isAuthInjectionStrategy = isAuthInjectionStrategy;
|
|
42203
42209
|
exports.isBroadcastChannelConnectionGrant = isBroadcastChannelConnectionGrant;
|