@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/index.cjs
CHANGED
|
@@ -3,23 +3,23 @@
|
|
|
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
|
// This file is auto-generated during build - do not edit manually
|
|
17
|
-
// Generated from package.json version: 0.3.5-test.
|
|
17
|
+
// Generated from package.json version: 0.3.5-test.923
|
|
18
18
|
/**
|
|
19
19
|
* The package version, injected at build time.
|
|
20
20
|
* @internal
|
|
21
21
|
*/
|
|
22
|
-
const VERSION = '0.3.5-test.
|
|
22
|
+
const VERSION = '0.3.5-test.923';
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Fame protocol specific error classes with WebSocket close codes and proper inheritance.
|
|
@@ -25161,6 +25161,251 @@ class SigningConfig {
|
|
|
25161
25161
|
}
|
|
25162
25162
|
}
|
|
25163
25163
|
|
|
25164
|
+
function hasBuffer() {
|
|
25165
|
+
return typeof Buffer !== 'undefined';
|
|
25166
|
+
}
|
|
25167
|
+
function readStringProperty(source, ...names) {
|
|
25168
|
+
if (!source || typeof source !== 'object') {
|
|
25169
|
+
return undefined;
|
|
25170
|
+
}
|
|
25171
|
+
for (const name of names) {
|
|
25172
|
+
const value = source[name];
|
|
25173
|
+
if (typeof value === 'string' && value.length > 0) {
|
|
25174
|
+
return value;
|
|
25175
|
+
}
|
|
25176
|
+
}
|
|
25177
|
+
return undefined;
|
|
25178
|
+
}
|
|
25179
|
+
function decodePem(pem) {
|
|
25180
|
+
const base64 = pem
|
|
25181
|
+
.replace(/-----BEGIN[^-]+-----/g, '')
|
|
25182
|
+
.replace(/-----END[^-]+-----/g, '')
|
|
25183
|
+
.replace(/\s+/g, '');
|
|
25184
|
+
if (typeof atob === 'function') {
|
|
25185
|
+
const binary = atob(base64);
|
|
25186
|
+
const bytes = new Uint8Array(binary.length);
|
|
25187
|
+
for (let i = 0; i < binary.length; i += 1) {
|
|
25188
|
+
bytes[i] = binary.charCodeAt(i);
|
|
25189
|
+
}
|
|
25190
|
+
return bytes;
|
|
25191
|
+
}
|
|
25192
|
+
if (hasBuffer()) {
|
|
25193
|
+
return Uint8Array.from(Buffer.from(base64, 'base64'));
|
|
25194
|
+
}
|
|
25195
|
+
throw new Error('Base64 decoding is not available in this environment');
|
|
25196
|
+
}
|
|
25197
|
+
function readLength(data, offset) {
|
|
25198
|
+
const initial = data[offset];
|
|
25199
|
+
if (initial === undefined) {
|
|
25200
|
+
throw new Error('Unexpected end of ASN.1 data');
|
|
25201
|
+
}
|
|
25202
|
+
if ((initial & 0x80) === 0) {
|
|
25203
|
+
return { length: initial, nextOffset: offset + 1 };
|
|
25204
|
+
}
|
|
25205
|
+
const lengthOfLength = initial & 0x7f;
|
|
25206
|
+
if (lengthOfLength === 0 || lengthOfLength > 4) {
|
|
25207
|
+
throw new Error('Unsupported ASN.1 length encoding');
|
|
25208
|
+
}
|
|
25209
|
+
let length = 0;
|
|
25210
|
+
let position = offset + 1;
|
|
25211
|
+
for (let i = 0; i < lengthOfLength; i += 1) {
|
|
25212
|
+
const byte = data[position];
|
|
25213
|
+
if (byte === undefined) {
|
|
25214
|
+
throw new Error('Unexpected end of ASN.1 data');
|
|
25215
|
+
}
|
|
25216
|
+
length = (length << 8) | byte;
|
|
25217
|
+
position += 1;
|
|
25218
|
+
}
|
|
25219
|
+
return { length, nextOffset: position };
|
|
25220
|
+
}
|
|
25221
|
+
function readElement(data, offset, tag) {
|
|
25222
|
+
if (data[offset] !== tag) {
|
|
25223
|
+
throw new Error(`Unexpected ASN.1 tag: expected 0x${tag.toString(16)}, got 0x${(data[offset] ?? 0).toString(16)}`);
|
|
25224
|
+
}
|
|
25225
|
+
const { length, nextOffset } = readLength(data, offset + 1);
|
|
25226
|
+
const contentOffset = nextOffset;
|
|
25227
|
+
return {
|
|
25228
|
+
length,
|
|
25229
|
+
contentOffset,
|
|
25230
|
+
nextOffset: contentOffset + length,
|
|
25231
|
+
};
|
|
25232
|
+
}
|
|
25233
|
+
function parseEd25519PrivateKey(pem) {
|
|
25234
|
+
const raw = decodePem(pem);
|
|
25235
|
+
if (raw.length === 32) {
|
|
25236
|
+
return raw.slice();
|
|
25237
|
+
}
|
|
25238
|
+
// Handle PKCS#8 structure defined in RFC 8410
|
|
25239
|
+
const sequence = readElement(raw, 0, 0x30);
|
|
25240
|
+
const version = readElement(raw, sequence.contentOffset, 0x02);
|
|
25241
|
+
let offset = version.nextOffset;
|
|
25242
|
+
const algorithm = readElement(raw, offset, 0x30);
|
|
25243
|
+
offset = algorithm.nextOffset;
|
|
25244
|
+
const privateKey = readElement(raw, offset, 0x04);
|
|
25245
|
+
const privateContent = raw.subarray(privateKey.contentOffset, privateKey.contentOffset + privateKey.length);
|
|
25246
|
+
if (privateContent.length === 32) {
|
|
25247
|
+
return privateContent.slice();
|
|
25248
|
+
}
|
|
25249
|
+
if (privateContent.length >= 34 && privateContent[0] === 0x04) {
|
|
25250
|
+
const innerLength = privateContent[1];
|
|
25251
|
+
if (innerLength !== 32 || privateContent.length < innerLength + 2) {
|
|
25252
|
+
throw new Error('Unexpected Ed25519 private key length');
|
|
25253
|
+
}
|
|
25254
|
+
return privateContent.subarray(2, 34);
|
|
25255
|
+
}
|
|
25256
|
+
throw new Error('Unsupported Ed25519 private key structure');
|
|
25257
|
+
}
|
|
25258
|
+
const textEncoder = typeof TextEncoder !== 'undefined' ? new TextEncoder() : undefined;
|
|
25259
|
+
function encodeUtf8(value) {
|
|
25260
|
+
if (textEncoder) {
|
|
25261
|
+
return textEncoder.encode(value);
|
|
25262
|
+
}
|
|
25263
|
+
if (hasBuffer()) {
|
|
25264
|
+
return Uint8Array.from(Buffer.from(value, 'utf8'));
|
|
25265
|
+
}
|
|
25266
|
+
throw new Error('No UTF-8 encoder available in this environment');
|
|
25267
|
+
}
|
|
25268
|
+
|
|
25269
|
+
if (!ed25519.hashes.sha512) {
|
|
25270
|
+
ed25519.hashes.sha512 = (message) => sha2_js.sha512(message);
|
|
25271
|
+
}
|
|
25272
|
+
function normalizeSignerOptions(options) {
|
|
25273
|
+
if (!options || typeof options !== 'object') {
|
|
25274
|
+
return {};
|
|
25275
|
+
}
|
|
25276
|
+
const candidate = options;
|
|
25277
|
+
const result = {
|
|
25278
|
+
...options,
|
|
25279
|
+
};
|
|
25280
|
+
const cryptoProvider = resolveAlias(candidate, ['cryptoProvider', 'crypto_provider']);
|
|
25281
|
+
if (cryptoProvider !== undefined) {
|
|
25282
|
+
result.cryptoProvider = cryptoProvider ?? null;
|
|
25283
|
+
}
|
|
25284
|
+
const signingConfig = resolveAlias(candidate, ['signingConfig', 'signing_config']);
|
|
25285
|
+
if (signingConfig !== undefined) {
|
|
25286
|
+
result.signingConfig = signingConfig;
|
|
25287
|
+
}
|
|
25288
|
+
const privateKeyPem = resolveAlias(candidate, [
|
|
25289
|
+
'privateKeyPem',
|
|
25290
|
+
'private_key_pem',
|
|
25291
|
+
]);
|
|
25292
|
+
if (privateKeyPem !== undefined) {
|
|
25293
|
+
result.privateKeyPem = privateKeyPem;
|
|
25294
|
+
}
|
|
25295
|
+
const keyId = resolveAlias(candidate, [
|
|
25296
|
+
'keyId',
|
|
25297
|
+
'key_id',
|
|
25298
|
+
]);
|
|
25299
|
+
if (keyId !== undefined) {
|
|
25300
|
+
result.keyId = keyId;
|
|
25301
|
+
}
|
|
25302
|
+
return result;
|
|
25303
|
+
}
|
|
25304
|
+
class EdDSAEnvelopeSigner {
|
|
25305
|
+
constructor(options = {}) {
|
|
25306
|
+
const normalized = normalizeSignerOptions(options);
|
|
25307
|
+
const provider = normalized.cryptoProvider ?? null;
|
|
25308
|
+
if (!provider) {
|
|
25309
|
+
throw new Error('No crypto provider is configured for signing');
|
|
25310
|
+
}
|
|
25311
|
+
this.crypto = provider;
|
|
25312
|
+
const signingConfigOption = normalized.signingConfig;
|
|
25313
|
+
if (signingConfigOption instanceof SigningConfig) {
|
|
25314
|
+
this.signingConfig = signingConfigOption;
|
|
25315
|
+
}
|
|
25316
|
+
else if (signingConfigOption) {
|
|
25317
|
+
this.signingConfig = new SigningConfig(signingConfigOption);
|
|
25318
|
+
}
|
|
25319
|
+
else {
|
|
25320
|
+
this.signingConfig = new SigningConfig();
|
|
25321
|
+
}
|
|
25322
|
+
this.explicitPrivateKey = normalized.privateKeyPem;
|
|
25323
|
+
this.explicitKeyId = normalized.keyId;
|
|
25324
|
+
}
|
|
25325
|
+
signEnvelope(envelope, { physicalPath }) {
|
|
25326
|
+
if (!envelope.sid) {
|
|
25327
|
+
throw new Error('Envelope missing sid');
|
|
25328
|
+
}
|
|
25329
|
+
const frame = envelope.frame;
|
|
25330
|
+
if (frame.type === 'Data') {
|
|
25331
|
+
const dataFrame = frame;
|
|
25332
|
+
if (!dataFrame.pd) {
|
|
25333
|
+
const payload = dataFrame.payload ?? '';
|
|
25334
|
+
const payloadString = payload === '' ? '' : canonicalJson(payload);
|
|
25335
|
+
dataFrame.pd = secureDigest(payloadString);
|
|
25336
|
+
}
|
|
25337
|
+
}
|
|
25338
|
+
const digest = frameDigest(frame);
|
|
25339
|
+
const immutable = canonicalJson(immutableHeaders(envelope));
|
|
25340
|
+
const sidDigest = secureDigest(physicalPath);
|
|
25341
|
+
const tbs = new Uint8Array(encodeUtf8(sidDigest).length +
|
|
25342
|
+
1 +
|
|
25343
|
+
encodeUtf8(immutable).length +
|
|
25344
|
+
1 +
|
|
25345
|
+
encodeUtf8(digest).length);
|
|
25346
|
+
const sidBytes = encodeUtf8(sidDigest);
|
|
25347
|
+
const immBytes = encodeUtf8(immutable);
|
|
25348
|
+
const digBytes = encodeUtf8(digest);
|
|
25349
|
+
let offset = 0;
|
|
25350
|
+
tbs.set(sidBytes, offset);
|
|
25351
|
+
offset += sidBytes.length;
|
|
25352
|
+
tbs[offset] = 0x1f;
|
|
25353
|
+
offset += 1;
|
|
25354
|
+
tbs.set(immBytes, offset);
|
|
25355
|
+
offset += immBytes.length;
|
|
25356
|
+
tbs[offset] = 0x1f;
|
|
25357
|
+
offset += 1;
|
|
25358
|
+
tbs.set(digBytes, offset);
|
|
25359
|
+
const privateKey = this.loadPrivateKey();
|
|
25360
|
+
const signatureBytes = ed25519.sign(tbs, privateKey);
|
|
25361
|
+
const signature = urlsafeBase64Encode(signatureBytes);
|
|
25362
|
+
const kid = this.determineKeyId();
|
|
25363
|
+
const signatureHeader = {
|
|
25364
|
+
kid,
|
|
25365
|
+
val: signature,
|
|
25366
|
+
alg: 'EdDSA',
|
|
25367
|
+
};
|
|
25368
|
+
const secHeader = envelope.sec ?? {};
|
|
25369
|
+
secHeader.sig = signatureHeader;
|
|
25370
|
+
envelope.sec = secHeader;
|
|
25371
|
+
return envelope;
|
|
25372
|
+
}
|
|
25373
|
+
loadPrivateKey() {
|
|
25374
|
+
const pem = this.explicitPrivateKey ??
|
|
25375
|
+
readStringProperty(this.crypto, 'signingPrivatePem', 'signing_private_pem');
|
|
25376
|
+
if (!pem) {
|
|
25377
|
+
throw new Error('Crypto provider does not expose a signing private key');
|
|
25378
|
+
}
|
|
25379
|
+
return parseEd25519PrivateKey(pem);
|
|
25380
|
+
}
|
|
25381
|
+
determineKeyId() {
|
|
25382
|
+
if (this.explicitKeyId) {
|
|
25383
|
+
return this.explicitKeyId;
|
|
25384
|
+
}
|
|
25385
|
+
if (this.signingConfig.signingMaterial === core.SigningMaterial.X509_CHAIN) {
|
|
25386
|
+
const certificateProvider = this
|
|
25387
|
+
.crypto;
|
|
25388
|
+
const jwk = certificateProvider.nodeJwk?.();
|
|
25389
|
+
if (jwk && typeof jwk === 'object' && 'kid' in jwk && 'x5c' in jwk) {
|
|
25390
|
+
const kid = jwk.kid;
|
|
25391
|
+
if (typeof kid === 'string' && kid.length > 0) {
|
|
25392
|
+
return kid;
|
|
25393
|
+
}
|
|
25394
|
+
}
|
|
25395
|
+
}
|
|
25396
|
+
const fallback = readStringProperty(this.crypto, 'signatureKeyId', 'signature_key_id');
|
|
25397
|
+
if (!fallback) {
|
|
25398
|
+
throw new Error('Crypto provider does not expose a signature key id');
|
|
25399
|
+
}
|
|
25400
|
+
return fallback;
|
|
25401
|
+
}
|
|
25402
|
+
}
|
|
25403
|
+
|
|
25404
|
+
var eddsaEnvelopeSigner = /*#__PURE__*/Object.freeze({
|
|
25405
|
+
__proto__: null,
|
|
25406
|
+
EdDSAEnvelopeSigner: EdDSAEnvelopeSigner
|
|
25407
|
+
});
|
|
25408
|
+
|
|
25164
25409
|
const logger$x = getLogger('naylence.fame.security.auth.jwt_token_issuer');
|
|
25165
25410
|
let joseModulePromise = null;
|
|
25166
25411
|
async function requireJose() {
|
|
@@ -39266,251 +39511,6 @@ var sharedSecretTokenVerifier = /*#__PURE__*/Object.freeze({
|
|
|
39266
39511
|
SharedSecretTokenVerifier: SharedSecretTokenVerifier
|
|
39267
39512
|
});
|
|
39268
39513
|
|
|
39269
|
-
function hasBuffer() {
|
|
39270
|
-
return typeof Buffer !== 'undefined';
|
|
39271
|
-
}
|
|
39272
|
-
function readStringProperty(source, ...names) {
|
|
39273
|
-
if (!source || typeof source !== 'object') {
|
|
39274
|
-
return undefined;
|
|
39275
|
-
}
|
|
39276
|
-
for (const name of names) {
|
|
39277
|
-
const value = source[name];
|
|
39278
|
-
if (typeof value === 'string' && value.length > 0) {
|
|
39279
|
-
return value;
|
|
39280
|
-
}
|
|
39281
|
-
}
|
|
39282
|
-
return undefined;
|
|
39283
|
-
}
|
|
39284
|
-
function decodePem(pem) {
|
|
39285
|
-
const base64 = pem
|
|
39286
|
-
.replace(/-----BEGIN[^-]+-----/g, '')
|
|
39287
|
-
.replace(/-----END[^-]+-----/g, '')
|
|
39288
|
-
.replace(/\s+/g, '');
|
|
39289
|
-
if (typeof atob === 'function') {
|
|
39290
|
-
const binary = atob(base64);
|
|
39291
|
-
const bytes = new Uint8Array(binary.length);
|
|
39292
|
-
for (let i = 0; i < binary.length; i += 1) {
|
|
39293
|
-
bytes[i] = binary.charCodeAt(i);
|
|
39294
|
-
}
|
|
39295
|
-
return bytes;
|
|
39296
|
-
}
|
|
39297
|
-
if (hasBuffer()) {
|
|
39298
|
-
return Uint8Array.from(Buffer.from(base64, 'base64'));
|
|
39299
|
-
}
|
|
39300
|
-
throw new Error('Base64 decoding is not available in this environment');
|
|
39301
|
-
}
|
|
39302
|
-
function readLength(data, offset) {
|
|
39303
|
-
const initial = data[offset];
|
|
39304
|
-
if (initial === undefined) {
|
|
39305
|
-
throw new Error('Unexpected end of ASN.1 data');
|
|
39306
|
-
}
|
|
39307
|
-
if ((initial & 0x80) === 0) {
|
|
39308
|
-
return { length: initial, nextOffset: offset + 1 };
|
|
39309
|
-
}
|
|
39310
|
-
const lengthOfLength = initial & 0x7f;
|
|
39311
|
-
if (lengthOfLength === 0 || lengthOfLength > 4) {
|
|
39312
|
-
throw new Error('Unsupported ASN.1 length encoding');
|
|
39313
|
-
}
|
|
39314
|
-
let length = 0;
|
|
39315
|
-
let position = offset + 1;
|
|
39316
|
-
for (let i = 0; i < lengthOfLength; i += 1) {
|
|
39317
|
-
const byte = data[position];
|
|
39318
|
-
if (byte === undefined) {
|
|
39319
|
-
throw new Error('Unexpected end of ASN.1 data');
|
|
39320
|
-
}
|
|
39321
|
-
length = (length << 8) | byte;
|
|
39322
|
-
position += 1;
|
|
39323
|
-
}
|
|
39324
|
-
return { length, nextOffset: position };
|
|
39325
|
-
}
|
|
39326
|
-
function readElement(data, offset, tag) {
|
|
39327
|
-
if (data[offset] !== tag) {
|
|
39328
|
-
throw new Error(`Unexpected ASN.1 tag: expected 0x${tag.toString(16)}, got 0x${(data[offset] ?? 0).toString(16)}`);
|
|
39329
|
-
}
|
|
39330
|
-
const { length, nextOffset } = readLength(data, offset + 1);
|
|
39331
|
-
const contentOffset = nextOffset;
|
|
39332
|
-
return {
|
|
39333
|
-
length,
|
|
39334
|
-
contentOffset,
|
|
39335
|
-
nextOffset: contentOffset + length,
|
|
39336
|
-
};
|
|
39337
|
-
}
|
|
39338
|
-
function parseEd25519PrivateKey(pem) {
|
|
39339
|
-
const raw = decodePem(pem);
|
|
39340
|
-
if (raw.length === 32) {
|
|
39341
|
-
return raw.slice();
|
|
39342
|
-
}
|
|
39343
|
-
// Handle PKCS#8 structure defined in RFC 8410
|
|
39344
|
-
const sequence = readElement(raw, 0, 0x30);
|
|
39345
|
-
const version = readElement(raw, sequence.contentOffset, 0x02);
|
|
39346
|
-
let offset = version.nextOffset;
|
|
39347
|
-
const algorithm = readElement(raw, offset, 0x30);
|
|
39348
|
-
offset = algorithm.nextOffset;
|
|
39349
|
-
const privateKey = readElement(raw, offset, 0x04);
|
|
39350
|
-
const privateContent = raw.subarray(privateKey.contentOffset, privateKey.contentOffset + privateKey.length);
|
|
39351
|
-
if (privateContent.length === 32) {
|
|
39352
|
-
return privateContent.slice();
|
|
39353
|
-
}
|
|
39354
|
-
if (privateContent.length >= 34 && privateContent[0] === 0x04) {
|
|
39355
|
-
const innerLength = privateContent[1];
|
|
39356
|
-
if (innerLength !== 32 || privateContent.length < innerLength + 2) {
|
|
39357
|
-
throw new Error('Unexpected Ed25519 private key length');
|
|
39358
|
-
}
|
|
39359
|
-
return privateContent.subarray(2, 34);
|
|
39360
|
-
}
|
|
39361
|
-
throw new Error('Unsupported Ed25519 private key structure');
|
|
39362
|
-
}
|
|
39363
|
-
const textEncoder = typeof TextEncoder !== 'undefined' ? new TextEncoder() : undefined;
|
|
39364
|
-
function encodeUtf8(value) {
|
|
39365
|
-
if (textEncoder) {
|
|
39366
|
-
return textEncoder.encode(value);
|
|
39367
|
-
}
|
|
39368
|
-
if (hasBuffer()) {
|
|
39369
|
-
return Uint8Array.from(Buffer.from(value, 'utf8'));
|
|
39370
|
-
}
|
|
39371
|
-
throw new Error('No UTF-8 encoder available in this environment');
|
|
39372
|
-
}
|
|
39373
|
-
|
|
39374
|
-
if (!ed25519.hashes.sha512) {
|
|
39375
|
-
ed25519.hashes.sha512 = (message) => sha2_js.sha512(message);
|
|
39376
|
-
}
|
|
39377
|
-
function normalizeSignerOptions(options) {
|
|
39378
|
-
if (!options || typeof options !== 'object') {
|
|
39379
|
-
return {};
|
|
39380
|
-
}
|
|
39381
|
-
const candidate = options;
|
|
39382
|
-
const result = {
|
|
39383
|
-
...options,
|
|
39384
|
-
};
|
|
39385
|
-
const cryptoProvider = resolveAlias(candidate, ['cryptoProvider', 'crypto_provider']);
|
|
39386
|
-
if (cryptoProvider !== undefined) {
|
|
39387
|
-
result.cryptoProvider = cryptoProvider ?? null;
|
|
39388
|
-
}
|
|
39389
|
-
const signingConfig = resolveAlias(candidate, ['signingConfig', 'signing_config']);
|
|
39390
|
-
if (signingConfig !== undefined) {
|
|
39391
|
-
result.signingConfig = signingConfig;
|
|
39392
|
-
}
|
|
39393
|
-
const privateKeyPem = resolveAlias(candidate, [
|
|
39394
|
-
'privateKeyPem',
|
|
39395
|
-
'private_key_pem',
|
|
39396
|
-
]);
|
|
39397
|
-
if (privateKeyPem !== undefined) {
|
|
39398
|
-
result.privateKeyPem = privateKeyPem;
|
|
39399
|
-
}
|
|
39400
|
-
const keyId = resolveAlias(candidate, [
|
|
39401
|
-
'keyId',
|
|
39402
|
-
'key_id',
|
|
39403
|
-
]);
|
|
39404
|
-
if (keyId !== undefined) {
|
|
39405
|
-
result.keyId = keyId;
|
|
39406
|
-
}
|
|
39407
|
-
return result;
|
|
39408
|
-
}
|
|
39409
|
-
class EdDSAEnvelopeSigner {
|
|
39410
|
-
constructor(options = {}) {
|
|
39411
|
-
const normalized = normalizeSignerOptions(options);
|
|
39412
|
-
const provider = normalized.cryptoProvider ?? null;
|
|
39413
|
-
if (!provider) {
|
|
39414
|
-
throw new Error('No crypto provider is configured for signing');
|
|
39415
|
-
}
|
|
39416
|
-
this.crypto = provider;
|
|
39417
|
-
const signingConfigOption = normalized.signingConfig;
|
|
39418
|
-
if (signingConfigOption instanceof SigningConfig) {
|
|
39419
|
-
this.signingConfig = signingConfigOption;
|
|
39420
|
-
}
|
|
39421
|
-
else if (signingConfigOption) {
|
|
39422
|
-
this.signingConfig = new SigningConfig(signingConfigOption);
|
|
39423
|
-
}
|
|
39424
|
-
else {
|
|
39425
|
-
this.signingConfig = new SigningConfig();
|
|
39426
|
-
}
|
|
39427
|
-
this.explicitPrivateKey = normalized.privateKeyPem;
|
|
39428
|
-
this.explicitKeyId = normalized.keyId;
|
|
39429
|
-
}
|
|
39430
|
-
signEnvelope(envelope, { physicalPath }) {
|
|
39431
|
-
if (!envelope.sid) {
|
|
39432
|
-
throw new Error('Envelope missing sid');
|
|
39433
|
-
}
|
|
39434
|
-
const frame = envelope.frame;
|
|
39435
|
-
if (frame.type === 'Data') {
|
|
39436
|
-
const dataFrame = frame;
|
|
39437
|
-
if (!dataFrame.pd) {
|
|
39438
|
-
const payload = dataFrame.payload ?? '';
|
|
39439
|
-
const payloadString = payload === '' ? '' : canonicalJson(payload);
|
|
39440
|
-
dataFrame.pd = secureDigest(payloadString);
|
|
39441
|
-
}
|
|
39442
|
-
}
|
|
39443
|
-
const digest = frameDigest(frame);
|
|
39444
|
-
const immutable = canonicalJson(immutableHeaders(envelope));
|
|
39445
|
-
const sidDigest = secureDigest(physicalPath);
|
|
39446
|
-
const tbs = new Uint8Array(encodeUtf8(sidDigest).length +
|
|
39447
|
-
1 +
|
|
39448
|
-
encodeUtf8(immutable).length +
|
|
39449
|
-
1 +
|
|
39450
|
-
encodeUtf8(digest).length);
|
|
39451
|
-
const sidBytes = encodeUtf8(sidDigest);
|
|
39452
|
-
const immBytes = encodeUtf8(immutable);
|
|
39453
|
-
const digBytes = encodeUtf8(digest);
|
|
39454
|
-
let offset = 0;
|
|
39455
|
-
tbs.set(sidBytes, offset);
|
|
39456
|
-
offset += sidBytes.length;
|
|
39457
|
-
tbs[offset] = 0x1f;
|
|
39458
|
-
offset += 1;
|
|
39459
|
-
tbs.set(immBytes, offset);
|
|
39460
|
-
offset += immBytes.length;
|
|
39461
|
-
tbs[offset] = 0x1f;
|
|
39462
|
-
offset += 1;
|
|
39463
|
-
tbs.set(digBytes, offset);
|
|
39464
|
-
const privateKey = this.loadPrivateKey();
|
|
39465
|
-
const signatureBytes = ed25519.sign(tbs, privateKey);
|
|
39466
|
-
const signature = urlsafeBase64Encode(signatureBytes);
|
|
39467
|
-
const kid = this.determineKeyId();
|
|
39468
|
-
const signatureHeader = {
|
|
39469
|
-
kid,
|
|
39470
|
-
val: signature,
|
|
39471
|
-
alg: 'EdDSA',
|
|
39472
|
-
};
|
|
39473
|
-
const secHeader = envelope.sec ?? {};
|
|
39474
|
-
secHeader.sig = signatureHeader;
|
|
39475
|
-
envelope.sec = secHeader;
|
|
39476
|
-
return envelope;
|
|
39477
|
-
}
|
|
39478
|
-
loadPrivateKey() {
|
|
39479
|
-
const pem = this.explicitPrivateKey ??
|
|
39480
|
-
readStringProperty(this.crypto, 'signingPrivatePem', 'signing_private_pem');
|
|
39481
|
-
if (!pem) {
|
|
39482
|
-
throw new Error('Crypto provider does not expose a signing private key');
|
|
39483
|
-
}
|
|
39484
|
-
return parseEd25519PrivateKey(pem);
|
|
39485
|
-
}
|
|
39486
|
-
determineKeyId() {
|
|
39487
|
-
if (this.explicitKeyId) {
|
|
39488
|
-
return this.explicitKeyId;
|
|
39489
|
-
}
|
|
39490
|
-
if (this.signingConfig.signingMaterial === core.SigningMaterial.X509_CHAIN) {
|
|
39491
|
-
const certificateProvider = this
|
|
39492
|
-
.crypto;
|
|
39493
|
-
const jwk = certificateProvider.nodeJwk?.();
|
|
39494
|
-
if (jwk && typeof jwk === 'object' && 'kid' in jwk && 'x5c' in jwk) {
|
|
39495
|
-
const kid = jwk.kid;
|
|
39496
|
-
if (typeof kid === 'string' && kid.length > 0) {
|
|
39497
|
-
return kid;
|
|
39498
|
-
}
|
|
39499
|
-
}
|
|
39500
|
-
}
|
|
39501
|
-
const fallback = readStringProperty(this.crypto, 'signatureKeyId', 'signature_key_id');
|
|
39502
|
-
if (!fallback) {
|
|
39503
|
-
throw new Error('Crypto provider does not expose a signature key id');
|
|
39504
|
-
}
|
|
39505
|
-
return fallback;
|
|
39506
|
-
}
|
|
39507
|
-
}
|
|
39508
|
-
|
|
39509
|
-
var eddsaEnvelopeSigner = /*#__PURE__*/Object.freeze({
|
|
39510
|
-
__proto__: null,
|
|
39511
|
-
EdDSAEnvelopeSigner: EdDSAEnvelopeSigner
|
|
39512
|
-
});
|
|
39513
|
-
|
|
39514
39514
|
async function loadPublicKey(jwk, signingConfig) {
|
|
39515
39515
|
if (jwk.x5c) {
|
|
39516
39516
|
if (signingConfig.signingMaterial !== core.SigningMaterial.X509_CHAIN) {
|
|
@@ -39791,6 +39791,7 @@ exports.ENV_VAR_JWT_REVERSE_AUTH_AUDIENCE = ENV_VAR_JWT_REVERSE_AUTH_AUDIENCE;
|
|
|
39791
39791
|
exports.ENV_VAR_JWT_REVERSE_AUTH_TRUSTED_ISSUER = ENV_VAR_JWT_REVERSE_AUTH_TRUSTED_ISSUER;
|
|
39792
39792
|
exports.ENV_VAR_JWT_TRUSTED_ISSUER = ENV_VAR_JWT_TRUSTED_ISSUER;
|
|
39793
39793
|
exports.ENV_VAR_SHOW_ENVELOPES = ENV_VAR_SHOW_ENVELOPES$1;
|
|
39794
|
+
exports.EdDSAEnvelopeSigner = EdDSAEnvelopeSigner;
|
|
39794
39795
|
exports.EncryptedKeyValueStore = EncryptedKeyValueStore;
|
|
39795
39796
|
exports.EncryptedStorageProviderBase = EncryptedStorageProviderBase;
|
|
39796
39797
|
exports.EncryptedValue = EncryptedValue;
|
|
@@ -39919,6 +39920,7 @@ exports.assertGrant = assertGrant;
|
|
|
39919
39920
|
exports.basicConfig = basicConfig;
|
|
39920
39921
|
exports.broadcastChannelGrantToConnectorConfig = broadcastChannelGrantToConnectorConfig;
|
|
39921
39922
|
exports.camelToSnakeCase = camelToSnakeCase;
|
|
39923
|
+
exports.canonicalJson = canonicalJson;
|
|
39922
39924
|
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
39923
39925
|
exports.color = color;
|
|
39924
39926
|
exports.compareCryptoLevels = compareCryptoLevels;
|
|
@@ -39938,12 +39940,14 @@ exports.createX25519Keypair = createX25519Keypair;
|
|
|
39938
39940
|
exports.credentialToString = credentialToString;
|
|
39939
39941
|
exports.currentTraceId = currentTraceId$1;
|
|
39940
39942
|
exports.debounce = debounce;
|
|
39943
|
+
exports.decodeBase64Url = decodeBase64Url;
|
|
39941
39944
|
exports.decodeFameDataPayload = decodeFameDataPayload;
|
|
39942
39945
|
exports.deepMerge = deepMerge;
|
|
39943
39946
|
exports.defaultJsonEncoder = defaultJsonEncoder;
|
|
39944
39947
|
exports.delay = delay;
|
|
39945
39948
|
exports.dropEmpty = dropEmpty;
|
|
39946
39949
|
exports.enableLogging = enableLogging;
|
|
39950
|
+
exports.encodeUtf8 = encodeUtf8;
|
|
39947
39951
|
exports.ensureRuntimeFactoriesRegistered = ensureRuntimeFactoriesRegistered;
|
|
39948
39952
|
exports.extractId = extractId;
|
|
39949
39953
|
exports.extractPoolAddressBase = extractPoolAddressBase;
|
|
@@ -39951,6 +39955,7 @@ exports.extractPoolBase = extractPoolBase;
|
|
|
39951
39955
|
exports.filterKeysByUse = filterKeysByUse;
|
|
39952
39956
|
exports.formatTimestamp = formatTimestamp;
|
|
39953
39957
|
exports.formatTimestampForConsole = formatTimestampForConsole$1;
|
|
39958
|
+
exports.frameDigest = frameDigest;
|
|
39954
39959
|
exports.getCurrentEnvelope = getCurrentEnvelope;
|
|
39955
39960
|
exports.getFameRoot = getFameRoot;
|
|
39956
39961
|
exports.getKeyProvider = getKeyProvider;
|
|
@@ -39960,6 +39965,7 @@ exports.hasCryptoSupport = hasCryptoSupport;
|
|
|
39960
39965
|
exports.hostnameToLogical = hostnameToLogical;
|
|
39961
39966
|
exports.hostnamesToLogicals = hostnamesToLogicals;
|
|
39962
39967
|
exports.httpGrantToConnectorConfig = httpGrantToConnectorConfig;
|
|
39968
|
+
exports.immutableHeaders = immutableHeaders;
|
|
39963
39969
|
exports.inPageGrantToConnectorConfig = inPageGrantToConnectorConfig;
|
|
39964
39970
|
exports.isAuthInjectionStrategy = isAuthInjectionStrategy;
|
|
39965
39971
|
exports.isBroadcastChannelConnectionGrant = isBroadcastChannelConnectionGrant;
|