@learncard/core 6.2.0 → 6.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/core.cjs.development.js +135 -35
- package/dist/core.cjs.development.js.map +3 -3
- package/dist/core.cjs.production.min.js +49 -49
- package/dist/core.cjs.production.min.js.map +3 -3
- package/dist/core.d.ts +98 -99
- package/dist/core.esm.js +135 -35
- package/dist/core.esm.js.map +3 -3
- package/package.json +2 -2
@@ -36939,8 +36939,7 @@ __export(src_exports2, {
|
|
36939
36939
|
getVCPlugin: () => getVCPlugin,
|
36940
36940
|
getVpqrPlugin: () => getVpqrPlugin,
|
36941
36941
|
initLearnCard: () => initLearnCard,
|
36942
|
-
|
36943
|
-
seedToId: () => seedToId,
|
36942
|
+
walletFromApiUrl: () => walletFromApiUrl,
|
36944
36943
|
walletFromKey: () => walletFromKey
|
36945
36944
|
});
|
36946
36945
|
module.exports = __toCommonJS(src_exports2);
|
@@ -36951,34 +36950,6 @@ var import_polyfill = require("abort-controller/polyfill");
|
|
36951
36950
|
var import_isomorphic_webcrypto = __toESM(require("isomorphic-webcrypto"));
|
36952
36951
|
if (typeof window === "undefined" && !globalThis.crypto)
|
36953
36952
|
globalThis.crypto = import_isomorphic_webcrypto.default;
|
36954
|
-
var crypto_default = import_isomorphic_webcrypto.default;
|
36955
|
-
|
36956
|
-
// src/wallet/base/functions/passwordToKey.ts
|
36957
|
-
var passwordToKey = /* @__PURE__ */ __name((password, salt = "salt", iterations = 1e5, digest2 = "SHA-256") => __async(void 0, null, function* () {
|
36958
|
-
var saltBuffer = Buffer.from(salt);
|
36959
|
-
var passphraseKey = Buffer.from(password);
|
36960
|
-
return crypto_default.subtle.importKey("raw", passphraseKey, { name: "PBKDF2" }, false, [
|
36961
|
-
"deriveBits",
|
36962
|
-
"deriveKey"
|
36963
|
-
]).then(function(key2) {
|
36964
|
-
return crypto_default.subtle.deriveKey({
|
36965
|
-
name: "PBKDF2",
|
36966
|
-
salt: saltBuffer,
|
36967
|
-
iterations,
|
36968
|
-
hash: digest2
|
36969
|
-
}, key2, { name: "AES-CBC", length: 256 }, true, ["encrypt", "decrypt"]);
|
36970
|
-
}).then((webKey) => {
|
36971
|
-
return crypto_default.subtle.exportKey("raw", webKey);
|
36972
|
-
}).then((buffer2) => {
|
36973
|
-
return new Uint8Array(buffer2);
|
36974
|
-
});
|
36975
|
-
}), "passwordToKey");
|
36976
|
-
|
36977
|
-
// src/wallet/base/functions/seedToId.ts
|
36978
|
-
var seedToId = /* @__PURE__ */ __name((seed) => __async(void 0, null, function* () {
|
36979
|
-
const buffer2 = yield crypto_default.subtle.digest("SHA-256", seed);
|
36980
|
-
return `urn:digest:${Buffer.from(new Int8Array(buffer2)).toString("hex")}`;
|
36981
|
-
}), "seedToId");
|
36982
36953
|
|
36983
36954
|
// src/wallet/base/wallet.ts
|
36984
36955
|
var addPluginToWallet = /* @__PURE__ */ __name((wallet, plugin) => __async(void 0, null, function* () {
|
@@ -39252,7 +39223,8 @@ var getCHAPIPlugin = /* @__PURE__ */ __name(() => __async(void 0, null, function
|
|
39252
39223
|
return { success: false, reason: "did not auth" };
|
39253
39224
|
const verification = yield wallet.pluginMethods.verifyPresentation(res.data, {
|
39254
39225
|
challenge,
|
39255
|
-
domain
|
39226
|
+
domain,
|
39227
|
+
proofPurpose: "authentication"
|
39256
39228
|
});
|
39257
39229
|
if (verification.warnings.length > 0 || verification.errors.length > 0) {
|
39258
39230
|
return { success: false, reason: "auth failed verification" };
|
@@ -39261,7 +39233,7 @@ var getCHAPIPlugin = /* @__PURE__ */ __name(() => __async(void 0, null, function
|
|
39261
39233
|
if (!Array.isArray(credential.credentialSubject)) {
|
39262
39234
|
credential.credentialSubject.id = subject;
|
39263
39235
|
}
|
39264
|
-
const vp = yield wallet.pluginMethods.
|
39236
|
+
const vp = yield wallet.pluginMethods.getTestVp(yield wallet.pluginMethods.issueCredential(credential));
|
39265
39237
|
const success = yield wallet.pluginMethods.storePresentationViaChapi(vp);
|
39266
39238
|
if (success)
|
39267
39239
|
return { success: true };
|
@@ -42220,7 +42192,7 @@ var AlignmentValidator = mod.object({
|
|
42220
42192
|
targetType: AlignmentTargetTypeValidator.optional(),
|
42221
42193
|
targetUrl: mod.string()
|
42222
42194
|
});
|
42223
|
-
var
|
42195
|
+
var KnownAchievementTypeValidator = mod.enum([
|
42224
42196
|
"Achievement",
|
42225
42197
|
"ApprenticeshipCertificate",
|
42226
42198
|
"Assessment",
|
@@ -42252,7 +42224,8 @@ var AchievementTypeValidator = mod.enum([
|
|
42252
42224
|
"MicroCredential",
|
42253
42225
|
"ResearchDoctorate",
|
42254
42226
|
"SecondarySchoolDiploma"
|
42255
|
-
])
|
42227
|
+
]);
|
42228
|
+
var AchievementTypeValidator = KnownAchievementTypeValidator.or(mod.string());
|
42256
42229
|
var CriteriaValidator = mod.object({ id: mod.string().optional(), narrative: mod.string().optional() }).catchall(mod.any());
|
42257
42230
|
var EndorsementSubjectValidator = mod.object({
|
42258
42231
|
id: mod.string(),
|
@@ -42411,6 +42384,13 @@ var IDXCredentialValidator = mod.object({
|
|
42411
42384
|
id: mod.string(),
|
42412
42385
|
title: mod.string(),
|
42413
42386
|
storageType: StorageTypeValidator.optional()
|
42387
|
+
}).catchall(mod.any());
|
42388
|
+
var JWKValidator = mod.object({
|
42389
|
+
kty: mod.string(),
|
42390
|
+
crv: mod.string(),
|
42391
|
+
x: mod.string(),
|
42392
|
+
y: mod.string().optional(),
|
42393
|
+
d: mod.string()
|
42414
42394
|
});
|
42415
42395
|
|
42416
42396
|
// ../../node_modules/.pnpm/date-fns@2.28.0/node_modules/date-fns/esm/_lib/toInteger/index.js
|
@@ -60387,11 +60367,131 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
|
|
60387
60367
|
};
|
60388
60368
|
}), "walletFromKey");
|
60389
60369
|
|
60370
|
+
// src/wallet/plugins/vc-api/helpers.ts
|
60371
|
+
var post = /* @__PURE__ */ __name((url, data) => __async(void 0, null, function* () {
|
60372
|
+
return fetch(url, {
|
60373
|
+
method: "POST",
|
60374
|
+
headers: { "Content-Type": "application/json" },
|
60375
|
+
body: JSON.stringify(data)
|
60376
|
+
});
|
60377
|
+
}), "post");
|
60378
|
+
var isSuccessful = /* @__PURE__ */ __name((status) => status.toString().startsWith("2"), "isSuccessful");
|
60379
|
+
|
60380
|
+
// src/wallet/plugins/vc-api/index.ts
|
60381
|
+
var getVCAPIPlugin = /* @__PURE__ */ __name((_0) => __async(void 0, [_0], function* ({
|
60382
|
+
url: _url,
|
60383
|
+
did: _did
|
60384
|
+
}) {
|
60385
|
+
const url = _url.endsWith("/") ? _url.slice(0, -1) : _url;
|
60386
|
+
let did = _did;
|
60387
|
+
if (!did) {
|
60388
|
+
const res = yield fetch(`${url}/did`);
|
60389
|
+
if (res.status === 200)
|
60390
|
+
did = yield res.text();
|
60391
|
+
}
|
60392
|
+
if (!did)
|
60393
|
+
throw new Error("Could not retrieve did from VC API! Please suppy a did.");
|
60394
|
+
return {
|
60395
|
+
pluginMethods: {
|
60396
|
+
getSubjectDid: () => did,
|
60397
|
+
issueCredential: (_wallet, credential, options) => __async(void 0, null, function* () {
|
60398
|
+
yield UnsignedVCValidator.parseAsync(credential);
|
60399
|
+
const response = yield post(`${url}/credentials/issue`, { credential, options });
|
60400
|
+
if (!isSuccessful(response.status)) {
|
60401
|
+
throw new Error(`API Error: ${response.status} ${response.statusText}`);
|
60402
|
+
}
|
60403
|
+
return VCValidator.parseAsync(yield response.json());
|
60404
|
+
}),
|
60405
|
+
verifyCredential: (_wallet, verifiableCredential, options) => __async(void 0, null, function* () {
|
60406
|
+
yield VCValidator.parseAsync(verifiableCredential);
|
60407
|
+
const response = yield post(`${url}/credentials/verify`, {
|
60408
|
+
verifiableCredential,
|
60409
|
+
options
|
60410
|
+
});
|
60411
|
+
if (!isSuccessful(response.status)) {
|
60412
|
+
throw new Error(`API Error: ${response.status} ${response.statusText}`);
|
60413
|
+
}
|
60414
|
+
return VerificationCheckValidator.parseAsync(yield response.json());
|
60415
|
+
}),
|
60416
|
+
issuePresentation: (_wallet, presentation, options) => __async(void 0, null, function* () {
|
60417
|
+
yield UnsignedVPValidator.parseAsync(presentation);
|
60418
|
+
const response = yield post(`${url}/presentations/issue`, {
|
60419
|
+
presentation,
|
60420
|
+
options
|
60421
|
+
});
|
60422
|
+
if (!isSuccessful(response.status)) {
|
60423
|
+
throw new Error(`API Error: ${response.status} ${response.statusText}`);
|
60424
|
+
}
|
60425
|
+
return VPValidator.parseAsync(yield response.json());
|
60426
|
+
}),
|
60427
|
+
verifyPresentation: (_wallet, verifiablePresentation, options) => __async(void 0, null, function* () {
|
60428
|
+
yield VPValidator.parseAsync(verifiablePresentation);
|
60429
|
+
const response = yield post(`${url}/presentations/verify`, {
|
60430
|
+
verifiablePresentation,
|
60431
|
+
options
|
60432
|
+
});
|
60433
|
+
if (!isSuccessful(response.status)) {
|
60434
|
+
throw new Error(`API Error: ${response.status} ${response.statusText}`);
|
60435
|
+
}
|
60436
|
+
return VerificationCheckValidator.parseAsync(yield response.json());
|
60437
|
+
}),
|
60438
|
+
getTestVc: (_wallet, subject = "did:example:d23dd687a7dc6787646f2eb98d0") => {
|
60439
|
+
return {
|
60440
|
+
"@context": ["https://www.w3.org/2018/credentials/v1"],
|
60441
|
+
id: "http://example.org/credentials/3731",
|
60442
|
+
type: ["VerifiableCredential"],
|
60443
|
+
issuer: did,
|
60444
|
+
issuanceDate: "2020-08-19T21:41:50Z",
|
60445
|
+
credentialSubject: { id: subject }
|
60446
|
+
};
|
60447
|
+
},
|
60448
|
+
getTestVp: (_wallet, _credential) => __async(void 0, null, function* () {
|
60449
|
+
const credential = _credential || (yield _wallet.pluginMethods.issueCredential(_wallet.pluginMethods.getTestVc()));
|
60450
|
+
return {
|
60451
|
+
"@context": ["https://www.w3.org/2018/credentials/v1"],
|
60452
|
+
type: ["VerifiablePresentation"],
|
60453
|
+
holder: did,
|
60454
|
+
verifiableCredential: credential
|
60455
|
+
};
|
60456
|
+
})
|
60457
|
+
}
|
60458
|
+
};
|
60459
|
+
}), "getVCAPIPlugin");
|
60460
|
+
|
60461
|
+
// src/wallet/initializers/apiWallet.ts
|
60462
|
+
var walletFromApiUrl = /* @__PURE__ */ __name((_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (url, did, { defaultContents = [] } = {}) {
|
60463
|
+
const apiWallet = yield (yield generateWallet(defaultContents)).addPlugin(yield getVCAPIPlugin({ url, did }));
|
60464
|
+
const expirationWallet = yield apiWallet.addPlugin(ExpirationPlugin(apiWallet));
|
60465
|
+
const templateWallet = yield expirationWallet.addPlugin(getVCTemplatesPlugin());
|
60466
|
+
const wallet = yield templateWallet.addPlugin(yield getCHAPIPlugin());
|
60467
|
+
return {
|
60468
|
+
_wallet: wallet,
|
60469
|
+
did: (type = "key") => wallet.pluginMethods.getSubjectDid(type),
|
60470
|
+
newCredential: wallet.pluginMethods.newCredential,
|
60471
|
+
newPresentation: wallet.pluginMethods.newPresentation,
|
60472
|
+
issueCredential: wallet.pluginMethods.issueCredential,
|
60473
|
+
verifyCredential: verifyCredential2(wallet),
|
60474
|
+
issuePresentation: wallet.pluginMethods.issuePresentation,
|
60475
|
+
verifyPresentation: wallet.pluginMethods.verifyPresentation,
|
60476
|
+
getTestVc: wallet.pluginMethods.getTestVc,
|
60477
|
+
getTestVp: wallet.pluginMethods.getTestVp,
|
60478
|
+
installChapiHandler: wallet.pluginMethods.installChapiHandler,
|
60479
|
+
activateChapiHandler: wallet.pluginMethods.activateChapiHandler,
|
60480
|
+
receiveChapiEvent: wallet.pluginMethods.receiveChapiEvent,
|
60481
|
+
storePresentationViaChapi: wallet.pluginMethods.storePresentationViaChapi,
|
60482
|
+
storeCredentialViaChapiDidAuth: wallet.pluginMethods.storeCredentialViaChapiDidAuth
|
60483
|
+
};
|
60484
|
+
}), "walletFromApiUrl");
|
60485
|
+
|
60390
60486
|
// src/wallet/init.ts
|
60391
60487
|
function initLearnCard() {
|
60392
60488
|
return __async(this, arguments, function* (config2 = {}) {
|
60489
|
+
if ("vcApi" in config2) {
|
60490
|
+
const _a = config2, { vcApi, did } = _a, apiConfig = __objRest(_a, ["vcApi", "did"]);
|
60491
|
+
return walletFromApiUrl(typeof vcApi === "string" ? vcApi : "https://bridge.learncard.com", vcApi === true ? "did:key:z6MkjSz4mYqcn7dePGuktJ5PxecMkXQQHWRg8Lm6okATyFVh" : did, apiConfig);
|
60492
|
+
}
|
60393
60493
|
if ("seed" in config2) {
|
60394
|
-
const
|
60494
|
+
const _b = config2, { seed } = _b, keyConfig = __objRest(_b, ["seed"]);
|
60395
60495
|
return walletFromKey(seed, keyConfig);
|
60396
60496
|
}
|
60397
60497
|
return emptyWallet(config2);
|