@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
@@ -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,
|
@@ -42114,7 +42117,7 @@ var IdentifierEntryValidator = mod.object({
|
|
42114
42117
|
});
|
42115
42118
|
var ProfileValidator = mod.string().or(mod.object({
|
42116
42119
|
id: mod.string().optional(),
|
42117
|
-
type: mod.string().array().nonempty().optional(),
|
42120
|
+
type: mod.string().or(mod.string().array().nonempty().optional()),
|
42118
42121
|
name: mod.string().optional(),
|
42119
42122
|
url: mod.string().optional(),
|
42120
42123
|
phone: mod.string().optional(),
|
@@ -42378,13 +42381,7 @@ var CredentialInfoValidator = mod.object({
|
|
42378
42381
|
issuee: ProfileValidator.optional(),
|
42379
42382
|
credentialSubject: CredentialSubjectValidator.optional()
|
42380
42383
|
});
|
42381
|
-
var
|
42382
|
-
var StorageTypeEnum = StorageTypeValidator.enum;
|
42383
|
-
var IDXCredentialValidator = mod.object({
|
42384
|
-
id: mod.string(),
|
42385
|
-
title: mod.string(),
|
42386
|
-
storageType: StorageTypeValidator.optional()
|
42387
|
-
}).catchall(mod.any());
|
42384
|
+
var IDXCredentialValidator = mod.object({ id: mod.string(), uri: mod.string() }).catchall(mod.any());
|
42388
42385
|
var JWKValidator = mod.object({
|
42389
42386
|
kty: mod.string(),
|
42390
42387
|
crv: mod.string(),
|
@@ -56712,8 +56709,16 @@ var CeramicClient = class {
|
|
56712
56709
|
};
|
56713
56710
|
__name(CeramicClient, "CeramicClient");
|
56714
56711
|
|
56712
|
+
// src/wallet/plugins/idx/helpers.ts
|
56713
|
+
var streamIdToCeramicURI = /* @__PURE__ */ __name((id) => `lc:ceramic:${id}`, "streamIdToCeramicURI");
|
56714
|
+
|
56715
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})");
|
56716
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();
|
56717
56722
|
|
56718
56723
|
// src/wallet/plugins/idx/idx.ts
|
56719
56724
|
var getCeramicClientFromWalletSuite = /* @__PURE__ */ __name((wallet, ceramicEndpoint) => __async(void 0, null, function* () {
|
@@ -56738,38 +56743,32 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
|
|
56738
56743
|
const validationResult = yield CredentialsListValidator.spa(list);
|
56739
56744
|
if (validationResult.success)
|
56740
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
|
+
}
|
56741
56762
|
console.error(validationResult.error);
|
56742
56763
|
throw new Error("Invalid credentials list stored in IDX");
|
56743
56764
|
}), "getCredentialsListFromIdx");
|
56744
|
-
const
|
56745
|
-
|
56746
|
-
|
56747
|
-
throw new Error("record is required");
|
56748
|
-
if (!record.id)
|
56749
|
-
throw Error("No streamId provided");
|
56750
|
-
if (record.id.indexOf("ceramic://") === -1)
|
56751
|
-
record.id = "ceramic://" + record.id;
|
56752
|
-
if (!alias)
|
56753
|
-
alias = credentialAlias;
|
56754
|
-
const existing = yield getCredentialsListFromIdx(alias);
|
56755
|
-
const indexOfExistingCredential = existing.credentials.findIndex((credential) => {
|
56756
|
-
return credential.title === record.title;
|
56757
|
-
});
|
56758
|
-
if (indexOfExistingCredential > -1) {
|
56759
|
-
existing.credentials[indexOfExistingCredential] = __spreadValues({
|
56760
|
-
storageType: StorageTypeEnum.ceramic
|
56761
|
-
}, record);
|
56762
|
-
} else
|
56763
|
-
existing.credentials.push(__spreadValues({ storageType: StorageTypeEnum.ceramic }, record));
|
56764
|
-
return dataStore.set(alias, existing);
|
56765
|
-
}), "addCredentialStreamIdToIdx");
|
56766
|
-
const removeCredentialFromIdx = /* @__PURE__ */ __name((title, alias) => __async(void 0, null, function* () {
|
56767
|
-
if (!title)
|
56768
|
-
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");
|
56769
56768
|
if (!alias)
|
56770
56769
|
alias = credentialAlias;
|
56771
56770
|
const existing = yield getCredentialsListFromIdx(alias);
|
56772
|
-
existing.credentials = existing.credentials.filter((credential) => credential.
|
56771
|
+
existing.credentials = existing.credentials.filter((credential) => credential.id !== id);
|
56773
56772
|
return dataStore.set(alias, existing);
|
56774
56773
|
}), "removeCredentialFromIdx");
|
56775
56774
|
const publishContentToCeramic = /* @__PURE__ */ __name((_02, ..._12) => __async(void 0, [_02, ..._12], function* (content, metadata = {}, options = {}) {
|
@@ -56794,30 +56793,56 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
|
|
56794
56793
|
return getCredentialsListFromIdx(alias);
|
56795
56794
|
}),
|
56796
56795
|
publishContentToCeramic: (_wallet, cred) => __async(void 0, null, function* () {
|
56797
|
-
return publishContentToCeramic(cred);
|
56796
|
+
return streamIdToCeramicURI(yield publishContentToCeramic(cred));
|
56798
56797
|
}),
|
56799
56798
|
readContentFromCeramic: (_wallet, streamId) => __async(void 0, null, function* () {
|
56800
56799
|
return readContentFromCeramic(streamId);
|
56801
56800
|
}),
|
56802
|
-
getVerifiableCredentialFromIdx: (_wallet,
|
56801
|
+
getVerifiableCredentialFromIdx: (_wallet, id) => __async(void 0, null, function* () {
|
56803
56802
|
var _a;
|
56804
56803
|
const credentialList = yield getCredentialsListFromIdx();
|
56805
|
-
const credential = (_a = credentialList == null ? void 0 : credentialList.credentials) == null ? void 0 : _a.find((cred) => (cred == null ? void 0 : cred.
|
56806
|
-
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;
|
56807
56806
|
}),
|
56808
|
-
getVerifiableCredentialsFromIdx: () => __async(void 0, null, function* () {
|
56807
|
+
getVerifiableCredentialsFromIdx: (_wallet) => __async(void 0, null, function* () {
|
56809
56808
|
var _a, _b;
|
56810
56809
|
const credentialList = yield getCredentialsListFromIdx();
|
56811
|
-
const
|
56812
|
-
return Promise.all(
|
56813
|
-
return
|
56814
|
-
})));
|
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);
|
56815
56814
|
}),
|
56816
56815
|
addVerifiableCredentialInIdx: (_wallet, idxCredential) => __async(void 0, null, function* () {
|
56817
|
-
|
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));
|
56831
|
+
}),
|
56832
|
+
removeVerifiableCredentialInIdx: (_wallet, id) => __async(void 0, null, function* () {
|
56833
|
+
return removeCredentialFromIdx(id);
|
56818
56834
|
}),
|
56819
|
-
|
56820
|
-
|
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));
|
56821
56846
|
})
|
56822
56847
|
}
|
56823
56848
|
};
|
@@ -60308,6 +60333,15 @@ var defaultEthereumArgs = {
|
|
60308
60333
|
network: "mainnet"
|
60309
60334
|
};
|
60310
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
|
+
|
60311
60345
|
// src/wallet/initializers/walletFromKey.ts
|
60312
60346
|
var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, ..._1], function* (key2, {
|
60313
60347
|
ceramicIdx = defaultCeramicIDXArgs,
|
@@ -60319,7 +60353,8 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
|
|
60319
60353
|
const didkeyWallet = yield didkitWallet.addPlugin(yield getDidKeyPlugin(didkitWallet, key2));
|
60320
60354
|
const didkeyAndVCWallet = yield didkeyWallet.addPlugin(getVCPlugin(didkeyWallet));
|
60321
60355
|
const templateWallet = yield didkeyAndVCWallet.addPlugin(getVCTemplatesPlugin());
|
60322
|
-
const
|
60356
|
+
const resolutionWallet = yield templateWallet.addPlugin(VCResolutionPlugin);
|
60357
|
+
const idxWallet = yield resolutionWallet.addPlugin(yield getIDXPlugin(resolutionWallet, ceramicIdx));
|
60323
60358
|
const expirationWallet = yield idxWallet.addPlugin(ExpirationPlugin(idxWallet));
|
60324
60359
|
const ethWallet = yield expirationWallet.addPlugin(getEthereumPlugin(expirationWallet, ethereumConfig));
|
60325
60360
|
const vpqrWallet = yield ethWallet.addPlugin(getVpqrPlugin(ethWallet));
|
@@ -60348,6 +60383,7 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
|
|
60348
60383
|
}),
|
60349
60384
|
resolveDid: wallet.pluginMethods.resolveDid,
|
60350
60385
|
readFromCeramic: wallet.pluginMethods.readContentFromCeramic,
|
60386
|
+
resolveCredential: wallet.pluginMethods.resolveCredential,
|
60351
60387
|
getTestVc: wallet.pluginMethods.getTestVc,
|
60352
60388
|
getTestVp: wallet.pluginMethods.getTestVp,
|
60353
60389
|
vpFromQrCode: wallet.pluginMethods.vpFromQrCode,
|