@learncard/core 6.2.0 → 6.3.1
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/core.cjs.development.js +132 -33
- 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 +81 -51
- package/dist/core.esm.js +132 -33
- 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 };
|
@@ -42412,6 +42384,13 @@ var IDXCredentialValidator = mod.object({
|
|
42412
42384
|
title: mod.string(),
|
42413
42385
|
storageType: StorageTypeValidator.optional()
|
42414
42386
|
});
|
42387
|
+
var JWKValidator = mod.object({
|
42388
|
+
kty: mod.string(),
|
42389
|
+
crv: mod.string(),
|
42390
|
+
x: mod.string(),
|
42391
|
+
y: mod.string().optional(),
|
42392
|
+
d: mod.string()
|
42393
|
+
});
|
42415
42394
|
|
42416
42395
|
// ../../node_modules/.pnpm/date-fns@2.28.0/node_modules/date-fns/esm/_lib/toInteger/index.js
|
42417
42396
|
function toInteger(dirtyNumber) {
|
@@ -60387,11 +60366,131 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
|
|
60387
60366
|
};
|
60388
60367
|
}), "walletFromKey");
|
60389
60368
|
|
60369
|
+
// src/wallet/plugins/vc-api/helpers.ts
|
60370
|
+
var post = /* @__PURE__ */ __name((url, data) => __async(void 0, null, function* () {
|
60371
|
+
return fetch(url, {
|
60372
|
+
method: "POST",
|
60373
|
+
headers: { "Content-Type": "application/json" },
|
60374
|
+
body: JSON.stringify(data)
|
60375
|
+
});
|
60376
|
+
}), "post");
|
60377
|
+
var isSuccessful = /* @__PURE__ */ __name((status) => status.toString().startsWith("2"), "isSuccessful");
|
60378
|
+
|
60379
|
+
// src/wallet/plugins/vc-api/index.ts
|
60380
|
+
var getVCAPIPlugin = /* @__PURE__ */ __name((_0) => __async(void 0, [_0], function* ({
|
60381
|
+
url: _url,
|
60382
|
+
did: _did
|
60383
|
+
}) {
|
60384
|
+
const url = _url.endsWith("/") ? _url.slice(0, -1) : _url;
|
60385
|
+
let did = _did;
|
60386
|
+
if (!did) {
|
60387
|
+
const res = yield fetch(`${url}/did`);
|
60388
|
+
if (res.status === 200)
|
60389
|
+
did = yield res.text();
|
60390
|
+
}
|
60391
|
+
if (!did)
|
60392
|
+
throw new Error("Could not retrieve did from VC API! Please suppy a did.");
|
60393
|
+
return {
|
60394
|
+
pluginMethods: {
|
60395
|
+
getSubjectDid: () => did,
|
60396
|
+
issueCredential: (_wallet, credential, options) => __async(void 0, null, function* () {
|
60397
|
+
yield UnsignedVCValidator.parseAsync(credential);
|
60398
|
+
const response = yield post(`${url}/credentials/issue`, { credential, options });
|
60399
|
+
if (!isSuccessful(response.status)) {
|
60400
|
+
throw new Error(`API Error: ${response.status} ${response.statusText}`);
|
60401
|
+
}
|
60402
|
+
return VCValidator.parseAsync(yield response.json());
|
60403
|
+
}),
|
60404
|
+
verifyCredential: (_wallet, verifiableCredential, options) => __async(void 0, null, function* () {
|
60405
|
+
yield VCValidator.parseAsync(verifiableCredential);
|
60406
|
+
const response = yield post(`${url}/credentials/verify`, {
|
60407
|
+
verifiableCredential,
|
60408
|
+
options
|
60409
|
+
});
|
60410
|
+
if (!isSuccessful(response.status)) {
|
60411
|
+
throw new Error(`API Error: ${response.status} ${response.statusText}`);
|
60412
|
+
}
|
60413
|
+
return VerificationCheckValidator.parseAsync(yield response.json());
|
60414
|
+
}),
|
60415
|
+
issuePresentation: (_wallet, presentation, options) => __async(void 0, null, function* () {
|
60416
|
+
yield UnsignedVPValidator.parseAsync(presentation);
|
60417
|
+
const response = yield post(`${url}/presentations/issue`, {
|
60418
|
+
presentation,
|
60419
|
+
options
|
60420
|
+
});
|
60421
|
+
if (!isSuccessful(response.status)) {
|
60422
|
+
throw new Error(`API Error: ${response.status} ${response.statusText}`);
|
60423
|
+
}
|
60424
|
+
return VPValidator.parseAsync(yield response.json());
|
60425
|
+
}),
|
60426
|
+
verifyPresentation: (_wallet, verifiablePresentation, options) => __async(void 0, null, function* () {
|
60427
|
+
yield VPValidator.parseAsync(verifiablePresentation);
|
60428
|
+
const response = yield post(`${url}/presentations/verify`, {
|
60429
|
+
verifiablePresentation,
|
60430
|
+
options
|
60431
|
+
});
|
60432
|
+
if (!isSuccessful(response.status)) {
|
60433
|
+
throw new Error(`API Error: ${response.status} ${response.statusText}`);
|
60434
|
+
}
|
60435
|
+
return VerificationCheckValidator.parseAsync(yield response.json());
|
60436
|
+
}),
|
60437
|
+
getTestVc: (_wallet, subject = "did:example:d23dd687a7dc6787646f2eb98d0") => {
|
60438
|
+
return {
|
60439
|
+
"@context": ["https://www.w3.org/2018/credentials/v1"],
|
60440
|
+
id: "http://example.org/credentials/3731",
|
60441
|
+
type: ["VerifiableCredential"],
|
60442
|
+
issuer: did,
|
60443
|
+
issuanceDate: "2020-08-19T21:41:50Z",
|
60444
|
+
credentialSubject: { id: subject }
|
60445
|
+
};
|
60446
|
+
},
|
60447
|
+
getTestVp: (_wallet, _credential) => __async(void 0, null, function* () {
|
60448
|
+
const credential = _credential || (yield _wallet.pluginMethods.issueCredential(_wallet.pluginMethods.getTestVc()));
|
60449
|
+
return {
|
60450
|
+
"@context": ["https://www.w3.org/2018/credentials/v1"],
|
60451
|
+
type: ["VerifiablePresentation"],
|
60452
|
+
holder: did,
|
60453
|
+
verifiableCredential: credential
|
60454
|
+
};
|
60455
|
+
})
|
60456
|
+
}
|
60457
|
+
};
|
60458
|
+
}), "getVCAPIPlugin");
|
60459
|
+
|
60460
|
+
// src/wallet/initializers/apiWallet.ts
|
60461
|
+
var walletFromApiUrl = /* @__PURE__ */ __name((_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (url, did, { defaultContents = [] } = {}) {
|
60462
|
+
const apiWallet = yield (yield generateWallet(defaultContents)).addPlugin(yield getVCAPIPlugin({ url, did }));
|
60463
|
+
const expirationWallet = yield apiWallet.addPlugin(ExpirationPlugin(apiWallet));
|
60464
|
+
const templateWallet = yield expirationWallet.addPlugin(getVCTemplatesPlugin());
|
60465
|
+
const wallet = yield templateWallet.addPlugin(yield getCHAPIPlugin());
|
60466
|
+
return {
|
60467
|
+
_wallet: wallet,
|
60468
|
+
did: (type = "key") => wallet.pluginMethods.getSubjectDid(type),
|
60469
|
+
newCredential: wallet.pluginMethods.newCredential,
|
60470
|
+
newPresentation: wallet.pluginMethods.newPresentation,
|
60471
|
+
issueCredential: wallet.pluginMethods.issueCredential,
|
60472
|
+
verifyCredential: verifyCredential2(wallet),
|
60473
|
+
issuePresentation: wallet.pluginMethods.issuePresentation,
|
60474
|
+
verifyPresentation: wallet.pluginMethods.verifyPresentation,
|
60475
|
+
getTestVc: wallet.pluginMethods.getTestVc,
|
60476
|
+
getTestVp: wallet.pluginMethods.getTestVp,
|
60477
|
+
installChapiHandler: wallet.pluginMethods.installChapiHandler,
|
60478
|
+
activateChapiHandler: wallet.pluginMethods.activateChapiHandler,
|
60479
|
+
receiveChapiEvent: wallet.pluginMethods.receiveChapiEvent,
|
60480
|
+
storePresentationViaChapi: wallet.pluginMethods.storePresentationViaChapi,
|
60481
|
+
storeCredentialViaChapiDidAuth: wallet.pluginMethods.storeCredentialViaChapiDidAuth
|
60482
|
+
};
|
60483
|
+
}), "walletFromApiUrl");
|
60484
|
+
|
60390
60485
|
// src/wallet/init.ts
|
60391
60486
|
function initLearnCard() {
|
60392
60487
|
return __async(this, arguments, function* (config2 = {}) {
|
60488
|
+
if ("vcApi" in config2) {
|
60489
|
+
const _a = config2, { vcApi, did } = _a, apiConfig = __objRest(_a, ["vcApi", "did"]);
|
60490
|
+
return walletFromApiUrl(typeof vcApi === "string" ? vcApi : "https://bridge.learncard.com", vcApi === true ? "did:key:z6MkjSz4mYqcn7dePGuktJ5PxecMkXQQHWRg8Lm6okATyFVh" : did, apiConfig);
|
60491
|
+
}
|
60393
60492
|
if ("seed" in config2) {
|
60394
|
-
const
|
60493
|
+
const _b = config2, { seed } = _b, keyConfig = __objRest(_b, ["seed"]);
|
60395
60494
|
return walletFromKey(seed, keyConfig);
|
60396
60495
|
}
|
60397
60496
|
return emptyWallet(config2);
|