@learncard/core 6.3.1 → 7.0.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/dist/core.cjs.development.js +85 -48
- package/dist/core.cjs.development.js.map +3 -3
- package/dist/core.cjs.production.min.js +125 -125
- package/dist/core.cjs.production.min.js.map +3 -3
- package/dist/core.d.ts +115 -117
- package/dist/core.esm.js +85 -48
- package/dist/core.esm.js.map +3 -3
- package/package.json +2 -2
@@ -36927,6 +36927,9 @@ var require_base32_decode = __commonJS({
|
|
36927
36927
|
// src/index.ts
|
36928
36928
|
var src_exports2 = {};
|
36929
36929
|
__export(src_exports2, {
|
36930
|
+
BackwardsCompatCredentialsListValidator: () => BackwardsCompatCredentialsListValidator,
|
36931
|
+
BackwardsCompatIDXCredentialValidator: () => BackwardsCompatIDXCredentialValidator,
|
36932
|
+
CeramicURIValidator: () => CeramicURIValidator,
|
36930
36933
|
CredentialsListValidator: () => CredentialsListValidator,
|
36931
36934
|
ExpirationPlugin: () => ExpirationPlugin,
|
36932
36935
|
emptyWallet: () => emptyWallet,
|
@@ -42192,7 +42195,7 @@ var AlignmentValidator = mod.object({
|
|
42192
42195
|
targetType: AlignmentTargetTypeValidator.optional(),
|
42193
42196
|
targetUrl: mod.string()
|
42194
42197
|
});
|
42195
|
-
var
|
42198
|
+
var KnownAchievementTypeValidator = mod.enum([
|
42196
42199
|
"Achievement",
|
42197
42200
|
"ApprenticeshipCertificate",
|
42198
42201
|
"Assessment",
|
@@ -42224,7 +42227,8 @@ var AchievementTypeValidator = mod.enum([
|
|
42224
42227
|
"MicroCredential",
|
42225
42228
|
"ResearchDoctorate",
|
42226
42229
|
"SecondarySchoolDiploma"
|
42227
|
-
])
|
42230
|
+
]);
|
42231
|
+
var AchievementTypeValidator = KnownAchievementTypeValidator.or(mod.string());
|
42228
42232
|
var CriteriaValidator = mod.object({ id: mod.string().optional(), narrative: mod.string().optional() }).catchall(mod.any());
|
42229
42233
|
var EndorsementSubjectValidator = mod.object({
|
42230
42234
|
id: mod.string(),
|
@@ -42377,13 +42381,7 @@ var CredentialInfoValidator = mod.object({
|
|
42377
42381
|
issuee: ProfileValidator.optional(),
|
42378
42382
|
credentialSubject: CredentialSubjectValidator.optional()
|
42379
42383
|
});
|
42380
|
-
var
|
42381
|
-
var StorageTypeEnum = StorageTypeValidator.enum;
|
42382
|
-
var IDXCredentialValidator = mod.object({
|
42383
|
-
id: mod.string(),
|
42384
|
-
title: mod.string(),
|
42385
|
-
storageType: StorageTypeValidator.optional()
|
42386
|
-
});
|
42384
|
+
var IDXCredentialValidator = mod.object({ id: mod.string(), uri: mod.string() }).catchall(mod.any());
|
42387
42385
|
var JWKValidator = mod.object({
|
42388
42386
|
kty: mod.string(),
|
42389
42387
|
crv: mod.string(),
|
@@ -56711,8 +56709,16 @@ var CeramicClient = class {
|
|
56711
56709
|
};
|
56712
56710
|
__name(CeramicClient, "CeramicClient");
|
56713
56711
|
|
56712
|
+
// src/wallet/plugins/idx/helpers.ts
|
56713
|
+
var streamIdToCeramicURI = /* @__PURE__ */ __name((id) => `lc:ceramic:${id}`, "streamIdToCeramicURI");
|
56714
|
+
|
56714
56715
|
// src/wallet/plugins/idx/types.ts
|
56716
|
+
var CeramicURIValidator = mod.string().refine((string2) => string2.split(":").length === 3 && string2.split(":")[0] === "lc", "URI must be of the form lc:${storage}:${url}").refine((string2) => string2.split(":")[1] === "ceramic", "URI must use storage type ceramic (i.e. must be lc:ceramic:${streamID})");
|
56715
56717
|
var CredentialsListValidator = mod.object({ credentials: IDXCredentialValidator.array() }).strict();
|
56718
|
+
var BackwardsCompatIDXCredentialValidator = mod.object({ id: mod.string(), title: mod.string(), storageType: mod.literal("ceramic").optional() }).catchall(mod.any());
|
56719
|
+
var BackwardsCompatCredentialsListValidator = mod.object({
|
56720
|
+
credentials: IDXCredentialValidator.or(BackwardsCompatIDXCredentialValidator).array()
|
56721
|
+
}).strict();
|
56716
56722
|
|
56717
56723
|
// src/wallet/plugins/idx/idx.ts
|
56718
56724
|
var getCeramicClientFromWalletSuite = /* @__PURE__ */ __name((wallet, ceramicEndpoint) => __async(void 0, null, function* () {
|
@@ -56737,38 +56743,32 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
|
|
56737
56743
|
const validationResult = yield CredentialsListValidator.spa(list);
|
56738
56744
|
if (validationResult.success)
|
56739
56745
|
return validationResult.data;
|
56746
|
+
const backwardsCompatValidationResult = yield BackwardsCompatCredentialsListValidator.spa(list);
|
56747
|
+
if (backwardsCompatValidationResult.success) {
|
56748
|
+
const oldCreds = backwardsCompatValidationResult.data.credentials;
|
56749
|
+
const newCreds = oldCreds.map((cred) => {
|
56750
|
+
if ("uri" in cred)
|
56751
|
+
return cred;
|
56752
|
+
const _a = cred, { title, id, storageType } = _a, rest = __objRest(_a, ["title", "id", "storageType"]);
|
56753
|
+
return __spreadProps(__spreadValues({}, rest), {
|
56754
|
+
id: title,
|
56755
|
+
uri: `lc:ceramic:${id.replace("ceramic://", "")}`
|
56756
|
+
});
|
56757
|
+
});
|
56758
|
+
const credentialsList = { credentials: newCreds };
|
56759
|
+
yield dataStore.set(credentialAlias, credentialsList);
|
56760
|
+
return credentialsList;
|
56761
|
+
}
|
56740
56762
|
console.error(validationResult.error);
|
56741
56763
|
throw new Error("Invalid credentials list stored in IDX");
|
56742
56764
|
}), "getCredentialsListFromIdx");
|
56743
|
-
const
|
56744
|
-
|
56745
|
-
|
56746
|
-
throw new Error("record is required");
|
56747
|
-
if (!record.id)
|
56748
|
-
throw Error("No streamId provided");
|
56749
|
-
if (record.id.indexOf("ceramic://") === -1)
|
56750
|
-
record.id = "ceramic://" + record.id;
|
56751
|
-
if (!alias)
|
56752
|
-
alias = credentialAlias;
|
56753
|
-
const existing = yield getCredentialsListFromIdx(alias);
|
56754
|
-
const indexOfExistingCredential = existing.credentials.findIndex((credential) => {
|
56755
|
-
return credential.title === record.title;
|
56756
|
-
});
|
56757
|
-
if (indexOfExistingCredential > -1) {
|
56758
|
-
existing.credentials[indexOfExistingCredential] = __spreadValues({
|
56759
|
-
storageType: StorageTypeEnum.ceramic
|
56760
|
-
}, record);
|
56761
|
-
} else
|
56762
|
-
existing.credentials.push(__spreadValues({ storageType: StorageTypeEnum.ceramic }, record));
|
56763
|
-
return dataStore.set(alias, existing);
|
56764
|
-
}), "addCredentialStreamIdToIdx");
|
56765
|
-
const removeCredentialFromIdx = /* @__PURE__ */ __name((title, alias) => __async(void 0, null, function* () {
|
56766
|
-
if (!title)
|
56767
|
-
throw new Error("record is required");
|
56765
|
+
const removeCredentialFromIdx = /* @__PURE__ */ __name((id, alias) => __async(void 0, null, function* () {
|
56766
|
+
if (!id)
|
56767
|
+
throw new Error("Must provide id to remove");
|
56768
56768
|
if (!alias)
|
56769
56769
|
alias = credentialAlias;
|
56770
56770
|
const existing = yield getCredentialsListFromIdx(alias);
|
56771
|
-
existing.credentials = existing.credentials.filter((credential) => credential.
|
56771
|
+
existing.credentials = existing.credentials.filter((credential) => credential.id !== id);
|
56772
56772
|
return dataStore.set(alias, existing);
|
56773
56773
|
}), "removeCredentialFromIdx");
|
56774
56774
|
const publishContentToCeramic = /* @__PURE__ */ __name((_02, ..._12) => __async(void 0, [_02, ..._12], function* (content, metadata = {}, options = {}) {
|
@@ -56793,30 +56793,56 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
|
|
56793
56793
|
return getCredentialsListFromIdx(alias);
|
56794
56794
|
}),
|
56795
56795
|
publishContentToCeramic: (_wallet, cred) => __async(void 0, null, function* () {
|
56796
|
-
return publishContentToCeramic(cred);
|
56796
|
+
return streamIdToCeramicURI(yield publishContentToCeramic(cred));
|
56797
56797
|
}),
|
56798
56798
|
readContentFromCeramic: (_wallet, streamId) => __async(void 0, null, function* () {
|
56799
56799
|
return readContentFromCeramic(streamId);
|
56800
56800
|
}),
|
56801
|
-
getVerifiableCredentialFromIdx: (_wallet,
|
56801
|
+
getVerifiableCredentialFromIdx: (_wallet, id) => __async(void 0, null, function* () {
|
56802
56802
|
var _a;
|
56803
56803
|
const credentialList = yield getCredentialsListFromIdx();
|
56804
|
-
const credential = (_a = credentialList == null ? void 0 : credentialList.credentials) == null ? void 0 : _a.find((cred) => (cred == null ? void 0 : cred.
|
56805
|
-
return credential
|
56804
|
+
const credential = (_a = credentialList == null ? void 0 : credentialList.credentials) == null ? void 0 : _a.find((cred) => (cred == null ? void 0 : cred.id) === id);
|
56805
|
+
return (credential == null ? void 0 : credential.uri) ? _wallet.pluginMethods.resolveCredential(credential.uri) : void 0;
|
56806
56806
|
}),
|
56807
|
-
getVerifiableCredentialsFromIdx: () => __async(void 0, null, function* () {
|
56807
|
+
getVerifiableCredentialsFromIdx: (_wallet) => __async(void 0, null, function* () {
|
56808
56808
|
var _a, _b;
|
56809
56809
|
const credentialList = yield getCredentialsListFromIdx();
|
56810
|
-
const
|
56811
|
-
return Promise.all(
|
56812
|
-
return
|
56813
|
-
})));
|
56810
|
+
const uris = (_b = (_a = credentialList == null ? void 0 : credentialList.credentials) == null ? void 0 : _a.map((credential) => credential == null ? void 0 : credential.uri)) != null ? _b : [];
|
56811
|
+
return (yield Promise.all(uris.map((uri) => __async(void 0, null, function* () {
|
56812
|
+
return _wallet.pluginMethods.resolveCredential(uri);
|
56813
|
+
})))).filter((vc) => !!vc);
|
56814
56814
|
}),
|
56815
56815
|
addVerifiableCredentialInIdx: (_wallet, idxCredential) => __async(void 0, null, function* () {
|
56816
|
-
|
56816
|
+
const record = IDXCredentialValidator.parse(idxCredential);
|
56817
|
+
if (!record)
|
56818
|
+
throw new Error("record is required");
|
56819
|
+
if (!record.uri)
|
56820
|
+
throw Error("No URI provided");
|
56821
|
+
yield _wallet.pluginMethods.resolveCredential(record.uri);
|
56822
|
+
const existing = yield getCredentialsListFromIdx(credentialAlias);
|
56823
|
+
const indexOfExistingCredential = existing.credentials.findIndex((credential) => {
|
56824
|
+
return credential.id === record.id;
|
56825
|
+
});
|
56826
|
+
if (indexOfExistingCredential > -1) {
|
56827
|
+
existing.credentials[indexOfExistingCredential] = record;
|
56828
|
+
} else
|
56829
|
+
existing.credentials.push(record);
|
56830
|
+
return streamIdToCeramicURI(yield dataStore.set(credentialAlias, existing));
|
56817
56831
|
}),
|
56818
|
-
removeVerifiableCredentialInIdx: (_wallet,
|
56819
|
-
return removeCredentialFromIdx(
|
56832
|
+
removeVerifiableCredentialInIdx: (_wallet, id) => __async(void 0, null, function* () {
|
56833
|
+
return removeCredentialFromIdx(id);
|
56834
|
+
}),
|
56835
|
+
resolveCredential: (_wallet, uri) => __async(void 0, null, function* () {
|
56836
|
+
if (!uri)
|
56837
|
+
return void 0;
|
56838
|
+
if (uri.startsWith("ceramic://")) {
|
56839
|
+
return VCValidator.parseAsync(yield readContentFromCeramic(uri));
|
56840
|
+
}
|
56841
|
+
const verificationResult = yield CeramicURIValidator.spa(uri);
|
56842
|
+
if (!verificationResult.success)
|
56843
|
+
return wallet.pluginMethods.resolveCredential(uri);
|
56844
|
+
const streamId = verificationResult.data.split(":")[2];
|
56845
|
+
return VCValidator.parseAsync(yield readContentFromCeramic(streamId));
|
56820
56846
|
})
|
56821
56847
|
}
|
56822
56848
|
};
|
@@ -60307,6 +60333,15 @@ var defaultEthereumArgs = {
|
|
60307
60333
|
network: "mainnet"
|
60308
60334
|
};
|
60309
60335
|
|
60336
|
+
// src/wallet/plugins/vc-resolution/index.ts
|
60337
|
+
var VCResolutionPlugin = {
|
60338
|
+
pluginMethods: {
|
60339
|
+
resolveCredential: (_wallet, uri) => __async(void 0, null, function* () {
|
60340
|
+
throw new Error(`No Credential Resolution Plugins found that can resolve ${uri}`);
|
60341
|
+
})
|
60342
|
+
}
|
60343
|
+
};
|
60344
|
+
|
60310
60345
|
// src/wallet/initializers/walletFromKey.ts
|
60311
60346
|
var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, ..._1], function* (key2, {
|
60312
60347
|
ceramicIdx = defaultCeramicIDXArgs,
|
@@ -60318,7 +60353,8 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
|
|
60318
60353
|
const didkeyWallet = yield didkitWallet.addPlugin(yield getDidKeyPlugin(didkitWallet, key2));
|
60319
60354
|
const didkeyAndVCWallet = yield didkeyWallet.addPlugin(getVCPlugin(didkeyWallet));
|
60320
60355
|
const templateWallet = yield didkeyAndVCWallet.addPlugin(getVCTemplatesPlugin());
|
60321
|
-
const
|
60356
|
+
const resolutionWallet = yield templateWallet.addPlugin(VCResolutionPlugin);
|
60357
|
+
const idxWallet = yield resolutionWallet.addPlugin(yield getIDXPlugin(resolutionWallet, ceramicIdx));
|
60322
60358
|
const expirationWallet = yield idxWallet.addPlugin(ExpirationPlugin(idxWallet));
|
60323
60359
|
const ethWallet = yield expirationWallet.addPlugin(getEthereumPlugin(expirationWallet, ethereumConfig));
|
60324
60360
|
const vpqrWallet = yield ethWallet.addPlugin(getVpqrPlugin(ethWallet));
|
@@ -60347,6 +60383,7 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
|
|
60347
60383
|
}),
|
60348
60384
|
resolveDid: wallet.pluginMethods.resolveDid,
|
60349
60385
|
readFromCeramic: wallet.pluginMethods.readContentFromCeramic,
|
60386
|
+
resolveCredential: wallet.pluginMethods.resolveCredential,
|
60350
60387
|
getTestVc: wallet.pluginMethods.getTestVc,
|
60351
60388
|
getTestVp: wallet.pluginMethods.getTestVp,
|
60352
60389
|
vpFromQrCode: wallet.pluginMethods.vpFromQrCode,
|