@learncard/core 6.4.0 → 7.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/core.cjs.development.js +83 -47
- 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 +165 -118
- package/dist/core.esm.js +83 -47
- package/dist/core.esm.js.map +3 -3
- package/package.json +2 -2
package/dist/core.esm.js
CHANGED
@@ -42103,7 +42103,7 @@ var IdentifierEntryValidator = mod.object({
|
|
42103
42103
|
});
|
42104
42104
|
var ProfileValidator = mod.string().or(mod.object({
|
42105
42105
|
id: mod.string().optional(),
|
42106
|
-
type: mod.string().array().nonempty().optional(),
|
42106
|
+
type: mod.string().or(mod.string().array().nonempty().optional()),
|
42107
42107
|
name: mod.string().optional(),
|
42108
42108
|
url: mod.string().optional(),
|
42109
42109
|
phone: mod.string().optional(),
|
@@ -42367,13 +42367,7 @@ var CredentialInfoValidator = mod.object({
|
|
42367
42367
|
issuee: ProfileValidator.optional(),
|
42368
42368
|
credentialSubject: CredentialSubjectValidator.optional()
|
42369
42369
|
});
|
42370
|
-
var
|
42371
|
-
var StorageTypeEnum = StorageTypeValidator.enum;
|
42372
|
-
var IDXCredentialValidator = mod.object({
|
42373
|
-
id: mod.string(),
|
42374
|
-
title: mod.string(),
|
42375
|
-
storageType: StorageTypeValidator.optional()
|
42376
|
-
}).catchall(mod.any());
|
42370
|
+
var IDXCredentialValidator = mod.object({ id: mod.string(), uri: mod.string() }).catchall(mod.any());
|
42377
42371
|
var JWKValidator = mod.object({
|
42378
42372
|
kty: mod.string(),
|
42379
42373
|
crv: mod.string(),
|
@@ -56701,8 +56695,16 @@ var CeramicClient = class {
|
|
56701
56695
|
};
|
56702
56696
|
__name(CeramicClient, "CeramicClient");
|
56703
56697
|
|
56698
|
+
// src/wallet/plugins/idx/helpers.ts
|
56699
|
+
var streamIdToCeramicURI = /* @__PURE__ */ __name((id) => `lc:ceramic:${id}`, "streamIdToCeramicURI");
|
56700
|
+
|
56704
56701
|
// src/wallet/plugins/idx/types.ts
|
56702
|
+
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})");
|
56705
56703
|
var CredentialsListValidator = mod.object({ credentials: IDXCredentialValidator.array() }).strict();
|
56704
|
+
var BackwardsCompatIDXCredentialValidator = mod.object({ id: mod.string(), title: mod.string(), storageType: mod.literal("ceramic").optional() }).catchall(mod.any());
|
56705
|
+
var BackwardsCompatCredentialsListValidator = mod.object({
|
56706
|
+
credentials: IDXCredentialValidator.or(BackwardsCompatIDXCredentialValidator).array()
|
56707
|
+
}).strict();
|
56706
56708
|
|
56707
56709
|
// src/wallet/plugins/idx/idx.ts
|
56708
56710
|
var getCeramicClientFromWalletSuite = /* @__PURE__ */ __name((wallet, ceramicEndpoint) => __async(void 0, null, function* () {
|
@@ -56727,38 +56729,32 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
|
|
56727
56729
|
const validationResult = yield CredentialsListValidator.spa(list);
|
56728
56730
|
if (validationResult.success)
|
56729
56731
|
return validationResult.data;
|
56732
|
+
const backwardsCompatValidationResult = yield BackwardsCompatCredentialsListValidator.spa(list);
|
56733
|
+
if (backwardsCompatValidationResult.success) {
|
56734
|
+
const oldCreds = backwardsCompatValidationResult.data.credentials;
|
56735
|
+
const newCreds = oldCreds.map((cred) => {
|
56736
|
+
if ("uri" in cred)
|
56737
|
+
return cred;
|
56738
|
+
const _a = cred, { title, id, storageType } = _a, rest = __objRest(_a, ["title", "id", "storageType"]);
|
56739
|
+
return __spreadProps(__spreadValues({}, rest), {
|
56740
|
+
id: title,
|
56741
|
+
uri: `lc:ceramic:${id.replace("ceramic://", "")}`
|
56742
|
+
});
|
56743
|
+
});
|
56744
|
+
const credentialsList = { credentials: newCreds };
|
56745
|
+
yield dataStore.set(credentialAlias, credentialsList);
|
56746
|
+
return credentialsList;
|
56747
|
+
}
|
56730
56748
|
console.error(validationResult.error);
|
56731
56749
|
throw new Error("Invalid credentials list stored in IDX");
|
56732
56750
|
}), "getCredentialsListFromIdx");
|
56733
|
-
const
|
56734
|
-
|
56735
|
-
|
56736
|
-
throw new Error("record is required");
|
56737
|
-
if (!record.id)
|
56738
|
-
throw Error("No streamId provided");
|
56739
|
-
if (record.id.indexOf("ceramic://") === -1)
|
56740
|
-
record.id = "ceramic://" + record.id;
|
56741
|
-
if (!alias)
|
56742
|
-
alias = credentialAlias;
|
56743
|
-
const existing = yield getCredentialsListFromIdx(alias);
|
56744
|
-
const indexOfExistingCredential = existing.credentials.findIndex((credential) => {
|
56745
|
-
return credential.title === record.title;
|
56746
|
-
});
|
56747
|
-
if (indexOfExistingCredential > -1) {
|
56748
|
-
existing.credentials[indexOfExistingCredential] = __spreadValues({
|
56749
|
-
storageType: StorageTypeEnum.ceramic
|
56750
|
-
}, record);
|
56751
|
-
} else
|
56752
|
-
existing.credentials.push(__spreadValues({ storageType: StorageTypeEnum.ceramic }, record));
|
56753
|
-
return dataStore.set(alias, existing);
|
56754
|
-
}), "addCredentialStreamIdToIdx");
|
56755
|
-
const removeCredentialFromIdx = /* @__PURE__ */ __name((title, alias) => __async(void 0, null, function* () {
|
56756
|
-
if (!title)
|
56757
|
-
throw new Error("record is required");
|
56751
|
+
const removeCredentialFromIdx = /* @__PURE__ */ __name((id, alias) => __async(void 0, null, function* () {
|
56752
|
+
if (!id)
|
56753
|
+
throw new Error("Must provide id to remove");
|
56758
56754
|
if (!alias)
|
56759
56755
|
alias = credentialAlias;
|
56760
56756
|
const existing = yield getCredentialsListFromIdx(alias);
|
56761
|
-
existing.credentials = existing.credentials.filter((credential) => credential.
|
56757
|
+
existing.credentials = existing.credentials.filter((credential) => credential.id !== id);
|
56762
56758
|
return dataStore.set(alias, existing);
|
56763
56759
|
}), "removeCredentialFromIdx");
|
56764
56760
|
const publishContentToCeramic = /* @__PURE__ */ __name((_02, ..._12) => __async(void 0, [_02, ..._12], function* (content, metadata = {}, options = {}) {
|
@@ -56783,30 +56779,56 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
|
|
56783
56779
|
return getCredentialsListFromIdx(alias);
|
56784
56780
|
}),
|
56785
56781
|
publishContentToCeramic: (_wallet, cred) => __async(void 0, null, function* () {
|
56786
|
-
return publishContentToCeramic(cred);
|
56782
|
+
return streamIdToCeramicURI(yield publishContentToCeramic(cred));
|
56787
56783
|
}),
|
56788
56784
|
readContentFromCeramic: (_wallet, streamId) => __async(void 0, null, function* () {
|
56789
56785
|
return readContentFromCeramic(streamId);
|
56790
56786
|
}),
|
56791
|
-
getVerifiableCredentialFromIdx: (_wallet,
|
56787
|
+
getVerifiableCredentialFromIdx: (_wallet, id) => __async(void 0, null, function* () {
|
56792
56788
|
var _a;
|
56793
56789
|
const credentialList = yield getCredentialsListFromIdx();
|
56794
|
-
const credential = (_a = credentialList == null ? void 0 : credentialList.credentials) == null ? void 0 : _a.find((cred) => (cred == null ? void 0 : cred.
|
56795
|
-
return credential
|
56790
|
+
const credential = (_a = credentialList == null ? void 0 : credentialList.credentials) == null ? void 0 : _a.find((cred) => (cred == null ? void 0 : cred.id) === id);
|
56791
|
+
return (credential == null ? void 0 : credential.uri) ? _wallet.pluginMethods.resolveCredential(credential.uri) : void 0;
|
56796
56792
|
}),
|
56797
|
-
getVerifiableCredentialsFromIdx: () => __async(void 0, null, function* () {
|
56793
|
+
getVerifiableCredentialsFromIdx: (_wallet) => __async(void 0, null, function* () {
|
56798
56794
|
var _a, _b;
|
56799
56795
|
const credentialList = yield getCredentialsListFromIdx();
|
56800
|
-
const
|
56801
|
-
return Promise.all(
|
56802
|
-
return
|
56803
|
-
})));
|
56796
|
+
const uris = (_b = (_a = credentialList == null ? void 0 : credentialList.credentials) == null ? void 0 : _a.map((credential) => credential == null ? void 0 : credential.uri)) != null ? _b : [];
|
56797
|
+
return (yield Promise.all(uris.map((uri) => __async(void 0, null, function* () {
|
56798
|
+
return _wallet.pluginMethods.resolveCredential(uri);
|
56799
|
+
})))).filter((vc) => !!vc);
|
56804
56800
|
}),
|
56805
56801
|
addVerifiableCredentialInIdx: (_wallet, idxCredential) => __async(void 0, null, function* () {
|
56806
|
-
|
56802
|
+
const record = IDXCredentialValidator.parse(idxCredential);
|
56803
|
+
if (!record)
|
56804
|
+
throw new Error("record is required");
|
56805
|
+
if (!record.uri)
|
56806
|
+
throw Error("No URI provided");
|
56807
|
+
yield _wallet.pluginMethods.resolveCredential(record.uri);
|
56808
|
+
const existing = yield getCredentialsListFromIdx(credentialAlias);
|
56809
|
+
const indexOfExistingCredential = existing.credentials.findIndex((credential) => {
|
56810
|
+
return credential.id === record.id;
|
56811
|
+
});
|
56812
|
+
if (indexOfExistingCredential > -1) {
|
56813
|
+
existing.credentials[indexOfExistingCredential] = record;
|
56814
|
+
} else
|
56815
|
+
existing.credentials.push(record);
|
56816
|
+
return streamIdToCeramicURI(yield dataStore.set(credentialAlias, existing));
|
56817
|
+
}),
|
56818
|
+
removeVerifiableCredentialInIdx: (_wallet, id) => __async(void 0, null, function* () {
|
56819
|
+
return removeCredentialFromIdx(id);
|
56807
56820
|
}),
|
56808
|
-
|
56809
|
-
|
56821
|
+
resolveCredential: (_wallet, uri) => __async(void 0, null, function* () {
|
56822
|
+
if (!uri)
|
56823
|
+
return void 0;
|
56824
|
+
if (uri.startsWith("ceramic://")) {
|
56825
|
+
return VCValidator.parseAsync(yield readContentFromCeramic(uri));
|
56826
|
+
}
|
56827
|
+
const verificationResult = yield CeramicURIValidator.spa(uri);
|
56828
|
+
if (!verificationResult.success)
|
56829
|
+
return wallet.pluginMethods.resolveCredential(uri);
|
56830
|
+
const streamId = verificationResult.data.split(":")[2];
|
56831
|
+
return VCValidator.parseAsync(yield readContentFromCeramic(streamId));
|
56810
56832
|
})
|
56811
56833
|
}
|
56812
56834
|
};
|
@@ -60297,6 +60319,15 @@ var defaultEthereumArgs = {
|
|
60297
60319
|
network: "mainnet"
|
60298
60320
|
};
|
60299
60321
|
|
60322
|
+
// src/wallet/plugins/vc-resolution/index.ts
|
60323
|
+
var VCResolutionPlugin = {
|
60324
|
+
pluginMethods: {
|
60325
|
+
resolveCredential: (_wallet, uri) => __async(void 0, null, function* () {
|
60326
|
+
throw new Error(`No Credential Resolution Plugins found that can resolve ${uri}`);
|
60327
|
+
})
|
60328
|
+
}
|
60329
|
+
};
|
60330
|
+
|
60300
60331
|
// src/wallet/initializers/walletFromKey.ts
|
60301
60332
|
var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, ..._1], function* (key2, {
|
60302
60333
|
ceramicIdx = defaultCeramicIDXArgs,
|
@@ -60308,7 +60339,8 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
|
|
60308
60339
|
const didkeyWallet = yield didkitWallet.addPlugin(yield getDidKeyPlugin(didkitWallet, key2));
|
60309
60340
|
const didkeyAndVCWallet = yield didkeyWallet.addPlugin(getVCPlugin(didkeyWallet));
|
60310
60341
|
const templateWallet = yield didkeyAndVCWallet.addPlugin(getVCTemplatesPlugin());
|
60311
|
-
const
|
60342
|
+
const resolutionWallet = yield templateWallet.addPlugin(VCResolutionPlugin);
|
60343
|
+
const idxWallet = yield resolutionWallet.addPlugin(yield getIDXPlugin(resolutionWallet, ceramicIdx));
|
60312
60344
|
const expirationWallet = yield idxWallet.addPlugin(ExpirationPlugin(idxWallet));
|
60313
60345
|
const ethWallet = yield expirationWallet.addPlugin(getEthereumPlugin(expirationWallet, ethereumConfig));
|
60314
60346
|
const vpqrWallet = yield ethWallet.addPlugin(getVpqrPlugin(ethWallet));
|
@@ -60337,6 +60369,7 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
|
|
60337
60369
|
}),
|
60338
60370
|
resolveDid: wallet.pluginMethods.resolveDid,
|
60339
60371
|
readFromCeramic: wallet.pluginMethods.readContentFromCeramic,
|
60372
|
+
resolveCredential: wallet.pluginMethods.resolveCredential,
|
60340
60373
|
getTestVc: wallet.pluginMethods.getTestVc,
|
60341
60374
|
getTestVp: wallet.pluginMethods.getTestVp,
|
60342
60375
|
vpFromQrCode: wallet.pluginMethods.vpFromQrCode,
|
@@ -60488,6 +60521,9 @@ function initLearnCard() {
|
|
60488
60521
|
}
|
60489
60522
|
__name(initLearnCard, "initLearnCard");
|
60490
60523
|
export {
|
60524
|
+
BackwardsCompatCredentialsListValidator,
|
60525
|
+
BackwardsCompatIDXCredentialValidator,
|
60526
|
+
CeramicURIValidator,
|
60491
60527
|
CredentialsListValidator,
|
60492
60528
|
ExpirationPlugin,
|
60493
60529
|
emptyWallet,
|