@covia/covia-sdk 1.19.1 → 1.21.0
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/README.md +8 -0
- package/dist/index.d.mts +108 -14
- package/dist/index.d.ts +108 -14
- package/dist/index.js +201 -48
- package/dist/index.mjs +194 -49
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -165,15 +165,15 @@ var isBig = (n) => typeof n === "bigint";
|
|
|
165
165
|
var isStr = (s) => typeof s === "string";
|
|
166
166
|
var isBytes = (a) => a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
167
167
|
var abytes = (value, length, title = "") => {
|
|
168
|
-
const
|
|
168
|
+
const bytes2 = isBytes(value);
|
|
169
169
|
const len = value?.length;
|
|
170
170
|
const needsLen = length !== void 0;
|
|
171
|
-
if (!
|
|
171
|
+
if (!bytes2 || needsLen && len !== length) {
|
|
172
172
|
const prefix = title && `"${title}" `;
|
|
173
173
|
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
174
|
-
const got =
|
|
174
|
+
const got = bytes2 ? `length=${len}` : `type=${typeof value}`;
|
|
175
175
|
const msg = prefix + "expected Uint8Array" + ofLen + ", got " + got;
|
|
176
|
-
throw
|
|
176
|
+
throw bytes2 ? new RangeError(msg) : new TypeError(msg);
|
|
177
177
|
}
|
|
178
178
|
return value;
|
|
179
179
|
};
|
|
@@ -632,15 +632,15 @@ function isBytes2(a) {
|
|
|
632
632
|
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
633
633
|
}
|
|
634
634
|
function abytes2(value, length, title = "") {
|
|
635
|
-
const
|
|
635
|
+
const bytes2 = isBytes2(value);
|
|
636
636
|
const len = value?.length;
|
|
637
637
|
const needsLen = length !== void 0;
|
|
638
|
-
if (!
|
|
638
|
+
if (!bytes2 || needsLen) {
|
|
639
639
|
const prefix = title && `"${title}" `;
|
|
640
640
|
const ofLen = "";
|
|
641
|
-
const got =
|
|
641
|
+
const got = bytes2 ? `length=${len}` : `type=${typeof value}`;
|
|
642
642
|
const message = prefix + "expected Uint8Array" + ofLen + ", got " + got;
|
|
643
|
-
if (!
|
|
643
|
+
if (!bytes2)
|
|
644
644
|
throw new TypeError(message);
|
|
645
645
|
throw new RangeError(message);
|
|
646
646
|
}
|
|
@@ -1061,11 +1061,11 @@ function hexToPrivateKey(hex) {
|
|
|
1061
1061
|
if (!/^[0-9a-fA-F]{64}$/.test(cleaned)) {
|
|
1062
1062
|
throw new Error("Invalid Ed25519 private key: expected 64 hex characters (32 bytes)");
|
|
1063
1063
|
}
|
|
1064
|
-
const
|
|
1065
|
-
for (let i = 0; i <
|
|
1066
|
-
|
|
1064
|
+
const bytes2 = new Uint8Array(32);
|
|
1065
|
+
for (let i = 0; i < bytes2.length; i++) {
|
|
1066
|
+
bytes2[i] = parseInt(cleaned.substring(i * 2, i * 2 + 2), 16);
|
|
1067
1067
|
}
|
|
1068
|
-
return
|
|
1068
|
+
return bytes2;
|
|
1069
1069
|
}
|
|
1070
1070
|
|
|
1071
1071
|
// src/crypto/base58.ts
|
|
@@ -1075,13 +1075,13 @@ var ALPHABET_MAP = /* @__PURE__ */ new Map();
|
|
|
1075
1075
|
for (let i = 0; i < ALPHABET.length; i++) {
|
|
1076
1076
|
ALPHABET_MAP.set(ALPHABET[i], i);
|
|
1077
1077
|
}
|
|
1078
|
-
function encode(
|
|
1079
|
-
if (
|
|
1078
|
+
function encode(bytes2) {
|
|
1079
|
+
if (bytes2.length === 0) return "";
|
|
1080
1080
|
let zeros = 0;
|
|
1081
|
-
while (zeros <
|
|
1081
|
+
while (zeros < bytes2.length && bytes2[zeros] === 0) zeros++;
|
|
1082
1082
|
const digits = [];
|
|
1083
|
-
for (let i = zeros; i <
|
|
1084
|
-
let carry =
|
|
1083
|
+
for (let i = zeros; i < bytes2.length; i++) {
|
|
1084
|
+
let carry = bytes2[i];
|
|
1085
1085
|
for (let j = 0; j < digits.length; j++) {
|
|
1086
1086
|
carry += digits[j] << 8;
|
|
1087
1087
|
digits[j] = carry % BASE;
|
|
@@ -1102,24 +1102,24 @@ function decode(str) {
|
|
|
1102
1102
|
if (str.length === 0) return new Uint8Array(0);
|
|
1103
1103
|
let zeros = 0;
|
|
1104
1104
|
while (zeros < str.length && str[zeros] === ALPHABET[0]) zeros++;
|
|
1105
|
-
const
|
|
1105
|
+
const bytes2 = [];
|
|
1106
1106
|
for (let i = zeros; i < str.length; i++) {
|
|
1107
1107
|
const val = ALPHABET_MAP.get(str[i]);
|
|
1108
1108
|
if (val === void 0) throw new Error(`Invalid base58 character: ${str[i]}`);
|
|
1109
1109
|
let carry = val;
|
|
1110
|
-
for (let j = 0; j <
|
|
1111
|
-
carry +=
|
|
1112
|
-
|
|
1110
|
+
for (let j = 0; j < bytes2.length; j++) {
|
|
1111
|
+
carry += bytes2[j] * BASE;
|
|
1112
|
+
bytes2[j] = carry & 255;
|
|
1113
1113
|
carry >>= 8;
|
|
1114
1114
|
}
|
|
1115
1115
|
while (carry > 0) {
|
|
1116
|
-
|
|
1116
|
+
bytes2.push(carry & 255);
|
|
1117
1117
|
carry >>= 8;
|
|
1118
1118
|
}
|
|
1119
1119
|
}
|
|
1120
|
-
const result = new Uint8Array(zeros +
|
|
1120
|
+
const result = new Uint8Array(zeros + bytes2.length);
|
|
1121
1121
|
for (let i = 0; i < zeros; i++) result[i] = 0;
|
|
1122
|
-
for (let i = 0; i <
|
|
1122
|
+
for (let i = 0; i < bytes2.length; i++) result[zeros + i] = bytes2[bytes2.length - 1 - i];
|
|
1123
1123
|
return result;
|
|
1124
1124
|
}
|
|
1125
1125
|
|
|
@@ -1155,7 +1155,16 @@ function base64UrlEncode(data) {
|
|
|
1155
1155
|
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
1156
1156
|
}
|
|
1157
1157
|
function createEdDSAJWT(privateKey, lifetimeSeconds = 300, audience) {
|
|
1158
|
-
const
|
|
1158
|
+
const signingInput = edDSASigningInput(getPublicKey2(privateKey), lifetimeSeconds, audience);
|
|
1159
|
+
const signature = sign(encoder.encode(signingInput), privateKey);
|
|
1160
|
+
return `${signingInput}.${base64UrlEncode(signature)}`;
|
|
1161
|
+
}
|
|
1162
|
+
async function createEdDSAJWTWith(signer, lifetimeSeconds = 300, audience) {
|
|
1163
|
+
const signingInput = edDSASigningInput(signer.publicKey, lifetimeSeconds, audience);
|
|
1164
|
+
const signature = await signer.sign(encoder.encode(signingInput));
|
|
1165
|
+
return `${signingInput}.${base64UrlEncode(signature)}`;
|
|
1166
|
+
}
|
|
1167
|
+
function edDSASigningInput(publicKey, lifetimeSeconds, audience) {
|
|
1159
1168
|
const multikey = encodePublicKey(publicKey);
|
|
1160
1169
|
const did = `did:key:${multikey}`;
|
|
1161
1170
|
const nowSecs = Math.floor(Date.now() / 1e3);
|
|
@@ -1173,18 +1182,95 @@ function createEdDSAJWT(privateKey, lifetimeSeconds = 300, audience) {
|
|
|
1173
1182
|
const payload = JSON.stringify(claims);
|
|
1174
1183
|
const headerB64 = base64UrlEncode(encoder.encode(header));
|
|
1175
1184
|
const payloadB64 = base64UrlEncode(encoder.encode(payload));
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1185
|
+
return `${headerB64}.${payloadB64}`;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
// src/crypto/signer.ts
|
|
1189
|
+
var ED25519 = "Ed25519";
|
|
1190
|
+
var PKCS8_ED25519_PREFIX = new Uint8Array([
|
|
1191
|
+
48,
|
|
1192
|
+
46,
|
|
1193
|
+
2,
|
|
1194
|
+
1,
|
|
1195
|
+
0,
|
|
1196
|
+
48,
|
|
1197
|
+
5,
|
|
1198
|
+
6,
|
|
1199
|
+
3,
|
|
1200
|
+
43,
|
|
1201
|
+
101,
|
|
1202
|
+
112,
|
|
1203
|
+
4,
|
|
1204
|
+
34,
|
|
1205
|
+
4,
|
|
1206
|
+
32
|
|
1207
|
+
]);
|
|
1208
|
+
function subtle2() {
|
|
1209
|
+
const s = globalThis.crypto?.subtle;
|
|
1210
|
+
if (!s) {
|
|
1211
|
+
throw new Error("WebCrypto is unavailable: crypto.subtle requires a secure context (HTTPS or localhost)");
|
|
1212
|
+
}
|
|
1213
|
+
return s;
|
|
1214
|
+
}
|
|
1215
|
+
function bytes(data) {
|
|
1216
|
+
return new Uint8Array(data);
|
|
1217
|
+
}
|
|
1218
|
+
function rawKeySigner(privateKey) {
|
|
1219
|
+
const publicKey = getPublicKey2(privateKey);
|
|
1220
|
+
return {
|
|
1221
|
+
publicKey,
|
|
1222
|
+
sign: (data) => Promise.resolve(sign(data, privateKey))
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
async function webCryptoSigner(keyPair) {
|
|
1226
|
+
const publicKey = new Uint8Array(await subtle2().exportKey("raw", keyPair.publicKey));
|
|
1227
|
+
const privateKey = keyPair.privateKey;
|
|
1228
|
+
return {
|
|
1229
|
+
publicKey,
|
|
1230
|
+
sign: async (data) => new Uint8Array(await subtle2().sign(ED25519, privateKey, bytes(data)))
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
async function generateNonExtractableKeyPair() {
|
|
1234
|
+
return subtle2().generateKey(ED25519, false, ["sign", "verify"]);
|
|
1235
|
+
}
|
|
1236
|
+
async function importNonExtractableKey(privateKey) {
|
|
1237
|
+
if (privateKey.length !== 32) {
|
|
1238
|
+
throw new Error("Invalid Ed25519 private key: expected 32 bytes");
|
|
1239
|
+
}
|
|
1240
|
+
const pkcs8 = new Uint8Array(PKCS8_ED25519_PREFIX.length + 32);
|
|
1241
|
+
pkcs8.set(PKCS8_ED25519_PREFIX, 0);
|
|
1242
|
+
pkcs8.set(privateKey, PKCS8_ED25519_PREFIX.length);
|
|
1243
|
+
try {
|
|
1244
|
+
const s = subtle2();
|
|
1245
|
+
const [priv, pub] = await Promise.all([
|
|
1246
|
+
s.importKey("pkcs8", pkcs8, ED25519, false, ["sign"]),
|
|
1247
|
+
s.importKey("raw", bytes(getPublicKey2(privateKey)), ED25519, true, ["verify"])
|
|
1248
|
+
]);
|
|
1249
|
+
return { privateKey: priv, publicKey: pub };
|
|
1250
|
+
} finally {
|
|
1251
|
+
pkcs8.fill(0);
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
var supported;
|
|
1255
|
+
function isWebCryptoEd25519Supported() {
|
|
1256
|
+
supported ?? (supported = (async () => {
|
|
1257
|
+
try {
|
|
1258
|
+
const kp = await generateNonExtractableKeyPair();
|
|
1259
|
+
await subtle2().sign(ED25519, kp.privateKey, new Uint8Array(1));
|
|
1260
|
+
return true;
|
|
1261
|
+
} catch {
|
|
1262
|
+
return false;
|
|
1263
|
+
}
|
|
1264
|
+
})());
|
|
1265
|
+
return supported;
|
|
1180
1266
|
}
|
|
1181
1267
|
|
|
1182
1268
|
// src/Credentials.ts
|
|
1183
1269
|
function base64Encode(text) {
|
|
1184
|
-
const
|
|
1270
|
+
const bytes2 = new TextEncoder().encode(text);
|
|
1185
1271
|
let binary = "";
|
|
1186
|
-
for (let i = 0; i <
|
|
1187
|
-
binary += String.fromCharCode(
|
|
1272
|
+
for (let i = 0; i < bytes2.length; i++) {
|
|
1273
|
+
binary += String.fromCharCode(bytes2[i]);
|
|
1188
1274
|
}
|
|
1189
1275
|
return btoa(binary);
|
|
1190
1276
|
}
|
|
@@ -1216,18 +1302,29 @@ var BasicAuth = class extends Auth {
|
|
|
1216
1302
|
};
|
|
1217
1303
|
var Ed25519Auth = class _Ed25519Auth extends Auth {
|
|
1218
1304
|
/**
|
|
1219
|
-
* @param
|
|
1305
|
+
* @param key - 32-byte Ed25519 private key, or an {@link Ed25519Signer}
|
|
1220
1306
|
* @param tokenLifetimeSeconds - JWT lifetime in seconds (default 300 = 5 min)
|
|
1221
1307
|
*/
|
|
1222
|
-
constructor(
|
|
1308
|
+
constructor(key, tokenLifetimeSeconds = 300) {
|
|
1223
1309
|
super();
|
|
1224
|
-
|
|
1225
|
-
|
|
1310
|
+
if (isSigner(key)) {
|
|
1311
|
+
this._signer = key;
|
|
1312
|
+
} else {
|
|
1313
|
+
this._privateKey = key;
|
|
1314
|
+
this._signer = rawKeySigner(key);
|
|
1315
|
+
}
|
|
1316
|
+
this._publicKey = this._signer.publicKey;
|
|
1226
1317
|
this._did = didFromPublicKey(this._publicKey);
|
|
1227
1318
|
this._lifetime = tokenLifetimeSeconds;
|
|
1228
1319
|
}
|
|
1229
1320
|
apply(headers, audience) {
|
|
1230
|
-
|
|
1321
|
+
if (this._privateKey) {
|
|
1322
|
+
headers["Authorization"] = `Bearer ${this.identityToken(audience)}`;
|
|
1323
|
+
return;
|
|
1324
|
+
}
|
|
1325
|
+
return this.mintIdentityToken(audience).then((token) => {
|
|
1326
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
1327
|
+
});
|
|
1231
1328
|
}
|
|
1232
1329
|
/**
|
|
1233
1330
|
* Mint a bearer-usable identity JWT for this key — the same token
|
|
@@ -1240,17 +1337,37 @@ var Ed25519Auth = class _Ed25519Auth extends Auth {
|
|
|
1240
1337
|
* at any venue that accepts the caller's DID, so minting one is refused
|
|
1241
1338
|
* rather than silently weakened.
|
|
1242
1339
|
*
|
|
1340
|
+
* Raw-key instances only: a signer-backed instance signs asynchronously,
|
|
1341
|
+
* so use {@link mintIdentityToken}, which works for both.
|
|
1342
|
+
*
|
|
1243
1343
|
* @param audience - The venue DID the token is bound to (`aud` claim).
|
|
1244
1344
|
* @param lifetimeSeconds - Token lifetime; defaults to this instance's.
|
|
1245
1345
|
*/
|
|
1246
1346
|
identityToken(audience, lifetimeSeconds) {
|
|
1347
|
+
const aud = this.resolveAudience(audience);
|
|
1348
|
+
if (!this._privateKey) {
|
|
1349
|
+
throw new CoviaError(
|
|
1350
|
+
"Ed25519Auth.identityToken() needs a raw private key; this instance signs through an Ed25519Signer, so use the async mintIdentityToken() instead."
|
|
1351
|
+
);
|
|
1352
|
+
}
|
|
1353
|
+
return createEdDSAJWT(this._privateKey, lifetimeSeconds ?? this._lifetime, aud);
|
|
1354
|
+
}
|
|
1355
|
+
/**
|
|
1356
|
+
* Async {@link identityToken} that works for raw-key and signer-backed
|
|
1357
|
+
* instances alike. Same token, same audience rules.
|
|
1358
|
+
*/
|
|
1359
|
+
async mintIdentityToken(audience, lifetimeSeconds) {
|
|
1360
|
+
const aud = this.resolveAudience(audience);
|
|
1361
|
+
return createEdDSAJWTWith(this._signer, lifetimeSeconds ?? this._lifetime, aud);
|
|
1362
|
+
}
|
|
1363
|
+
resolveAudience(audience) {
|
|
1247
1364
|
const aud = this._audience ?? (audience || void 0);
|
|
1248
1365
|
if (!aud) {
|
|
1249
1366
|
throw new CoviaError(
|
|
1250
1367
|
"Ed25519Auth requires a venue audience to bind the token to: connect via Grid.connect()/Venue.connect() so the venue DID is known, or pin auth.audience explicitly."
|
|
1251
1368
|
);
|
|
1252
1369
|
}
|
|
1253
|
-
return
|
|
1370
|
+
return aud;
|
|
1254
1371
|
}
|
|
1255
1372
|
/** The caller's DID derived from the public key. */
|
|
1256
1373
|
getDID() {
|
|
@@ -1279,7 +1396,17 @@ var Ed25519Auth = class _Ed25519Auth extends Auth {
|
|
|
1279
1396
|
static fromHex(privateKeyHex, tokenLifetimeSeconds = 300) {
|
|
1280
1397
|
return new _Ed25519Auth(hexToPrivateKey(privateKeyHex), tokenLifetimeSeconds);
|
|
1281
1398
|
}
|
|
1399
|
+
/**
|
|
1400
|
+
* Create from an {@link Ed25519Signer}, e.g. `await webCryptoSigner(keyPair)`
|
|
1401
|
+
* over a non-extractable WebCrypto key. Requests sign asynchronously.
|
|
1402
|
+
*/
|
|
1403
|
+
static fromSigner(signer, tokenLifetimeSeconds = 300) {
|
|
1404
|
+
return new _Ed25519Auth(signer, tokenLifetimeSeconds);
|
|
1405
|
+
}
|
|
1282
1406
|
};
|
|
1407
|
+
function isSigner(key) {
|
|
1408
|
+
return !ArrayBuffer.isView(key) && typeof key.sign === "function";
|
|
1409
|
+
}
|
|
1283
1410
|
var KeyPairAuth = Ed25519Auth;
|
|
1284
1411
|
var CredentialsHTTP = class {
|
|
1285
1412
|
constructor(venueId, apiKey, userId) {
|
|
@@ -1703,7 +1830,7 @@ var AdapterManager = class {
|
|
|
1703
1830
|
};
|
|
1704
1831
|
|
|
1705
1832
|
// src/VenueTransport.ts
|
|
1706
|
-
function requestOptions(venue, options) {
|
|
1833
|
+
async function requestOptions(venue, options) {
|
|
1707
1834
|
const {
|
|
1708
1835
|
contentType,
|
|
1709
1836
|
headers: suppliedHeaders = {},
|
|
@@ -1714,19 +1841,19 @@ function requestOptions(venue, options) {
|
|
|
1714
1841
|
if (effectiveContentType && headers["Content-Type"] === void 0) {
|
|
1715
1842
|
headers["Content-Type"] = effectiveContentType;
|
|
1716
1843
|
}
|
|
1717
|
-
venue.auth.apply(headers, venue.venueId);
|
|
1844
|
+
await venue.auth.apply(headers, venue.venueId);
|
|
1718
1845
|
return { ...request, headers };
|
|
1719
1846
|
}
|
|
1720
|
-
function venueJson(venue, path, options = {}) {
|
|
1847
|
+
async function venueJson(venue, path, options = {}) {
|
|
1721
1848
|
return fetchWithError(
|
|
1722
1849
|
`${venue.baseUrl}${path}`,
|
|
1723
|
-
requestOptions(venue, options)
|
|
1850
|
+
await requestOptions(venue, options)
|
|
1724
1851
|
);
|
|
1725
1852
|
}
|
|
1726
|
-
function venueStream(venue, path, options = {}) {
|
|
1853
|
+
async function venueStream(venue, path, options = {}) {
|
|
1727
1854
|
return fetchStreamWithError(
|
|
1728
1855
|
`${venue.baseUrl}${path}`,
|
|
1729
|
-
requestOptions(venue, options)
|
|
1856
|
+
await requestOptions(venue, options)
|
|
1730
1857
|
);
|
|
1731
1858
|
}
|
|
1732
1859
|
|
|
@@ -2531,6 +2658,9 @@ var AssetManager = class {
|
|
|
2531
2658
|
if (options.expand !== void 0) {
|
|
2532
2659
|
params.set("expand", options.expand);
|
|
2533
2660
|
}
|
|
2661
|
+
if (options.kind !== void 0) {
|
|
2662
|
+
params.set("kind", options.kind);
|
|
2663
|
+
}
|
|
2534
2664
|
return venueJson(
|
|
2535
2665
|
this.venue,
|
|
2536
2666
|
`/api/v1/assets?${params.toString()}`,
|
|
@@ -4067,7 +4197,17 @@ function didFor(privateKey) {
|
|
|
4067
4197
|
return `did:key:${encodePublicKey(getPublicKey2(privateKey))}`;
|
|
4068
4198
|
}
|
|
4069
4199
|
function createUCANJWT(privateKey, audienceDID, att, lifetimeSeconds, proofs = []) {
|
|
4070
|
-
const
|
|
4200
|
+
const signingInput = ucanSigningInput(getPublicKey2(privateKey), audienceDID, att, lifetimeSeconds, proofs);
|
|
4201
|
+
const signature = sign(encoder2.encode(signingInput), privateKey);
|
|
4202
|
+
return `${signingInput}.${base64UrlEncode(signature)}`;
|
|
4203
|
+
}
|
|
4204
|
+
async function createUCANJWTWith(signer, audienceDID, att, lifetimeSeconds, proofs = []) {
|
|
4205
|
+
const signingInput = ucanSigningInput(signer.publicKey, audienceDID, att, lifetimeSeconds, proofs);
|
|
4206
|
+
const signature = await signer.sign(encoder2.encode(signingInput));
|
|
4207
|
+
return `${signingInput}.${base64UrlEncode(signature)}`;
|
|
4208
|
+
}
|
|
4209
|
+
function ucanSigningInput(publicKey, audienceDID, att, lifetimeSeconds, proofs) {
|
|
4210
|
+
const multikey = encodePublicKey(publicKey);
|
|
4071
4211
|
const nowSecs = Math.floor(Date.now() / 1e3);
|
|
4072
4212
|
const header = JSON.stringify({ alg: "EdDSA", typ: "JWT", kid: multikey });
|
|
4073
4213
|
const claims = {
|
|
@@ -4083,9 +4223,7 @@ function createUCANJWT(privateKey, audienceDID, att, lifetimeSeconds, proofs = [
|
|
|
4083
4223
|
// CVMDouble the venue's UcanJwtValidator rejects outright (covia-sdk#46).
|
|
4084
4224
|
exp: lifetimeSeconds === null ? null : Math.floor(nowSecs + lifetimeSeconds)
|
|
4085
4225
|
};
|
|
4086
|
-
|
|
4087
|
-
const signature = sign(encoder2.encode(signingInput), privateKey);
|
|
4088
|
-
return `${signingInput}.${base64UrlEncode(signature)}`;
|
|
4226
|
+
return `${base64UrlEncode(encoder2.encode(header))}.${base64UrlEncode(encoder2.encode(JSON.stringify(claims)))}`;
|
|
4089
4227
|
}
|
|
4090
4228
|
function identityToken(privateKey, venueDID, lifetimeSeconds = 300) {
|
|
4091
4229
|
return createUCANJWT(privateKey, venueDID, [], lifetimeSeconds);
|
|
@@ -4093,10 +4231,17 @@ function identityToken(privateKey, venueDID, lifetimeSeconds = 300) {
|
|
|
4093
4231
|
function grant(ownerPrivateKey, audienceDID, withResource, can, lifetimeSeconds) {
|
|
4094
4232
|
return createUCANJWT(ownerPrivateKey, audienceDID, [{ with: withResource, can }], lifetimeSeconds);
|
|
4095
4233
|
}
|
|
4234
|
+
function grantWith(ownerSigner, audienceDID, withResource, can, lifetimeSeconds) {
|
|
4235
|
+
return createUCANJWTWith(ownerSigner, audienceDID, [{ with: withResource, can }], lifetimeSeconds);
|
|
4236
|
+
}
|
|
4096
4237
|
function relayDelegation(privateKey, venueDID, lifetimeSeconds, caps = []) {
|
|
4097
4238
|
const att = [{ with: didFor(privateKey), can: VENUE_RELAY }, ...caps];
|
|
4098
4239
|
return createUCANJWT(privateKey, venueDID, att, lifetimeSeconds);
|
|
4099
4240
|
}
|
|
4241
|
+
function relayDelegationWith(signer, venueDID, lifetimeSeconds, caps = []) {
|
|
4242
|
+
const att = [{ with: didFromPublicKey(signer.publicKey), can: VENUE_RELAY }, ...caps];
|
|
4243
|
+
return createUCANJWTWith(signer, venueDID, att, lifetimeSeconds);
|
|
4244
|
+
}
|
|
4100
4245
|
/*! Bundled license information:
|
|
4101
4246
|
|
|
4102
4247
|
@noble/ed25519/index.js:
|
|
@@ -4154,6 +4299,7 @@ exports.WorkspaceManager = WorkspaceManager;
|
|
|
4154
4299
|
exports.assetHash = assetHash;
|
|
4155
4300
|
exports.createSSEEvent = createSSEEvent;
|
|
4156
4301
|
exports.createUCANJWT = createUCANJWT;
|
|
4302
|
+
exports.createUCANJWTWith = createUCANJWTWith;
|
|
4157
4303
|
exports.decodePublicKey = decodePublicKey;
|
|
4158
4304
|
exports.didFor = didFor;
|
|
4159
4305
|
exports.didFromPublicKey = didFromPublicKey;
|
|
@@ -4163,23 +4309,30 @@ exports.encodePublicKey = encodePublicKey;
|
|
|
4163
4309
|
exports.fetchStreamWithError = fetchStreamWithError;
|
|
4164
4310
|
exports.fetchWithError = fetchWithError;
|
|
4165
4311
|
exports.generateKeyPair = generateKeyPair;
|
|
4312
|
+
exports.generateNonExtractableKeyPair = generateNonExtractableKeyPair;
|
|
4166
4313
|
exports.getAssetIdFromPath = getAssetIdFromPath;
|
|
4167
4314
|
exports.getAssetIdFromVenueId = getAssetIdFromVenueId;
|
|
4168
4315
|
exports.getAssetMetadataStore = getAssetMetadataStore;
|
|
4169
4316
|
exports.getParsedAssetId = getParsedAssetId;
|
|
4170
4317
|
exports.grant = grant;
|
|
4318
|
+
exports.grantWith = grantWith;
|
|
4171
4319
|
exports.hexToPrivateKey = hexToPrivateKey;
|
|
4172
4320
|
exports.identityToken = identityToken;
|
|
4321
|
+
exports.importNonExtractableKey = importNonExtractableKey;
|
|
4173
4322
|
exports.isDid = isDid;
|
|
4174
4323
|
exports.isJobComplete = isJobComplete;
|
|
4175
4324
|
exports.isJobFinished = isJobFinished;
|
|
4176
4325
|
exports.isJobPaused = isJobPaused;
|
|
4326
|
+
exports.isWebCryptoEd25519Supported = isWebCryptoEd25519Supported;
|
|
4177
4327
|
exports.logger = logger;
|
|
4178
4328
|
exports.parseDidUrl = parseDidUrl;
|
|
4179
4329
|
exports.parseRetryAfterMs = parseRetryAfterMs;
|
|
4180
4330
|
exports.parseSSEStream = parseSSEStream;
|
|
4181
4331
|
exports.privateKeyToHex = privateKeyToHex;
|
|
4332
|
+
exports.rawKeySigner = rawKeySigner;
|
|
4182
4333
|
exports.relayDelegation = relayDelegation;
|
|
4334
|
+
exports.relayDelegationWith = relayDelegationWith;
|
|
4183
4335
|
exports.retryDelayMs = retryDelayMs;
|
|
4184
4336
|
exports.setAssetMetadataStore = setAssetMetadataStore;
|
|
4185
4337
|
exports.venueBaseUrlCandidates = venueBaseUrlCandidates;
|
|
4338
|
+
exports.webCryptoSigner = webCryptoSigner;
|