@learncard/core 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -26905,24 +26905,10 @@ var require_query_string = __commonJS({
26905
26905
  // src/index.ts
26906
26906
  var src_exports2 = {};
26907
26907
  __export(src_exports2, {
26908
- createWallet: () => createWallet,
26909
26908
  walletFromKey: () => walletFromKey
26910
26909
  });
26911
26910
  module.exports = __toCommonJS(src_exports2);
26912
26911
 
26913
- // ../../node_modules/.pnpm/hex-lite@1.5.0/node_modules/hex-lite/dist/hex-lite.mjs
26914
- function toUint8Array(str) {
26915
- var s = 0, sl = str.length, bytes = [];
26916
- if (sl % 2) {
26917
- throw new Error("invalid hex:" + str);
26918
- }
26919
- for (; s < sl; s += 2) {
26920
- bytes.push(parseInt(str.substr(s, 2), 16));
26921
- }
26922
- return new Uint8Array(bytes);
26923
- }
26924
- __name(toUint8Array, "toUint8Array");
26925
-
26926
26912
  // src/didkit/pkg/didkit_wasm.js
26927
26913
  var wasm;
26928
26914
  var cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
@@ -36023,7 +36009,6 @@ if (isNodejs()) {
36023
36009
  } else {
36024
36010
  crypto3 = window.crypto;
36025
36011
  }
36026
- var crypto_default = crypto3;
36027
36012
 
36028
36013
  // src/wallet/base/wallet.ts
36029
36014
  var addPluginToWallet = /* @__PURE__ */ __name((wallet, plugin) => __async(void 0, null, function* () {
@@ -36042,11 +36027,10 @@ var removeFromWallet = /* @__PURE__ */ __name((wallet, contentId) => __async(voi
36042
36027
  var bindMethods = /* @__PURE__ */ __name((wallet, pluginMethods) => Object.fromEntries(Object.entries(pluginMethods).map(([key2, method]) => [key2, method.bind(wallet, wallet)])), "bindMethods");
36043
36028
  var generateWallet = /* @__PURE__ */ __name((..._0) => __async(void 0, [..._0], function* (contents = [], _wallet = {}) {
36044
36029
  const { plugins = [] } = _wallet;
36045
- const { pluginMethods, pluginConstants } = plugins.reduce(({ pluginMethods: pluginMethods2, pluginConstants: pluginConstants2 }, plugin) => {
36046
- const newPluginMethods = __spreadValues(__spreadValues({}, pluginMethods2), plugin.pluginMethods);
36047
- const newPluginConstants = __spreadValues(__spreadValues({}, pluginConstants2), plugin.pluginConstants);
36048
- return { pluginMethods: newPluginMethods, pluginConstants: newPluginConstants };
36049
- }, { pluginMethods: {}, pluginConstants: {} });
36030
+ const pluginMethods = plugins.reduce((cumulativePluginMethods, plugin) => {
36031
+ const newPluginMethods = __spreadValues(__spreadValues({}, cumulativePluginMethods), plugin.pluginMethods);
36032
+ return newPluginMethods;
36033
+ }, {});
36050
36034
  const wallet = {
36051
36035
  contents: [...contents],
36052
36036
  add: function(content) {
@@ -36058,7 +36042,6 @@ var generateWallet = /* @__PURE__ */ __name((..._0) => __async(void 0, [..._0],
36058
36042
  status: "UNLOCKED" /* Unlocked */,
36059
36043
  plugins,
36060
36044
  pluginMethods,
36061
- pluginConstants,
36062
36045
  addPlugin: function(plugin) {
36063
36046
  return addPluginToWallet(this, plugin);
36064
36047
  }
@@ -43333,6 +43316,19 @@ var DID = class {
43333
43316
  };
43334
43317
  __name(DID, "DID");
43335
43318
 
43319
+ // ../../node_modules/.pnpm/hex-lite@1.5.0/node_modules/hex-lite/dist/hex-lite.mjs
43320
+ function toUint8Array(str) {
43321
+ var s = 0, sl = str.length, bytes = [];
43322
+ if (sl % 2) {
43323
+ throw new Error("invalid hex:" + str);
43324
+ }
43325
+ for (; s < sl; s += 2) {
43326
+ bytes.push(parseInt(str.substr(s, 2), 16));
43327
+ }
43328
+ return new Uint8Array(bytes);
43329
+ }
43330
+ __name(toUint8Array, "toUint8Array");
43331
+
43336
43332
  // src/wallet/plugins/idx/idx.ts
43337
43333
  var import_key_did_resolver = __toESM(require_lib());
43338
43334
 
@@ -48357,13 +48353,11 @@ __name(CeramicClient, "CeramicClient");
48357
48353
 
48358
48354
  // src/wallet/plugins/idx/idx.ts
48359
48355
  var getCeramicClientFromWalletSuite = /* @__PURE__ */ __name((wallet, ceramicEndpoint) => __async(void 0, null, function* () {
48360
- var _a2, _b;
48361
48356
  const client = new CeramicClient(ceramicEndpoint);
48362
48357
  const resolver = __spreadValues({}, import_key_did_resolver.default.getResolver());
48363
48358
  const did = new DID({ resolver });
48364
48359
  client.did = did;
48365
- const contents = JSON.parse(JSON.stringify(wallet.contents));
48366
- const key2 = (_b = (_a2 = contents == null ? void 0 : contents.find((c) => (c == null ? void 0 : c.name) === "DID Key Secret")) == null ? void 0 : _a2.value) != null ? _b : "";
48360
+ const key2 = wallet.pluginMethods.getKey();
48367
48361
  const ceramicProvider = new Ed25519Provider(toUint8Array(key2));
48368
48362
  client.did.setProvider(ceramicProvider);
48369
48363
  yield client.did.authenticate();
@@ -48433,65 +48427,22 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
48433
48427
  addVerifiableCredentialInIdx: (_02, _12) => __async(void 0, [_02, _12], function* (_wallet, { title, id }) {
48434
48428
  return addCredentialStreamIdToIndex({ title, id });
48435
48429
  })
48436
- },
48437
- pluginConstants: {}
48430
+ }
48438
48431
  };
48439
48432
  }), "getIDXPlugin");
48440
48433
 
48441
- // src/wallet/plugins/didkey/generateContentFromSeed.ts
48442
- var seedToId = /* @__PURE__ */ __name((seed) => __async(void 0, null, function* () {
48443
- const buffer2 = yield crypto_default.subtle.digest("SHA-256", seed);
48444
- return `urn:digest:${Buffer.from(new Uint8Array(buffer2)).toString("hex")}`;
48445
- }), "seedToId");
48446
- var generateContentFromSeed = /* @__PURE__ */ __name((seed) => __async(void 0, null, function* () {
48447
- const privateKeyJwk = JSON.parse(generateEd25519KeyFromBytes(seed));
48448
- const controller = keyToDID("key", JSON.stringify(privateKeyJwk));
48449
- const _a2 = privateKeyJwk, { d } = _a2, publicKeyJwk = __objRest(_a2, ["d"]);
48450
- const signingKey = {
48451
- controller,
48452
- id: `${controller}#${controller.split(":").at(-1)}`,
48453
- privateKeyJwk,
48454
- publicKeyJwk,
48455
- type: "JsonWebKey2020"
48456
- };
48457
- const seedId = yield seedToId(seed);
48458
- const secret = {
48459
- "@context": ["http://w3id.org/wallet/v1"],
48460
- id: seedId,
48461
- name: "DID Key Secret",
48462
- image: "https://via.placeholder.com/150",
48463
- description: "Used to generate a DID with a signing and encryption key.",
48464
- tags: ["inception"],
48465
- type: "Entropy",
48466
- value: Buffer.from(seed).toString("hex")
48467
- };
48468
- const key0 = __spreadProps(__spreadValues({}, signingKey), {
48469
- "@context": ["http://w3id.org/wallet/v1"],
48470
- name: "Signing Key",
48471
- image: "https://via.placeholder.com/150",
48472
- description: "Used to produce digital signatures.",
48473
- tags: ["inception"],
48474
- generatedFrom: [secret.id]
48475
- });
48476
- return [secret, key0];
48477
- }), "generateContentFromSeed");
48478
-
48479
48434
  // src/wallet/plugins/didkey/index.ts
48480
- var DidKeyPlugin = {
48481
- pluginMethods: {
48482
- getSubjectDid: (wallet) => {
48483
- var _a2, _b;
48484
- return (_b = (_a2 = wallet.contents.find((content) => content.name === "Signing Key")) == null ? void 0 : _a2.controller) != null ? _b : "";
48485
- },
48486
- getSubjectKeypair: (wallet) => {
48487
- var _a2;
48488
- return (_a2 = wallet.contents.find((content) => content.name === "Signing Key")) == null ? void 0 : _a2.privateKeyJwk;
48435
+ var getDidKeyPlugin = /* @__PURE__ */ __name((key2) => __async(void 0, null, function* () {
48436
+ const keypair = JSON.parse(generateEd25519KeyFromBytes(toUint8Array(key2.padStart(64, "0"))));
48437
+ const did = keyToDID("key", JSON.stringify(keypair));
48438
+ return {
48439
+ pluginMethods: {
48440
+ getSubjectDid: () => did,
48441
+ getSubjectKeypair: () => keypair,
48442
+ getKey: () => key2
48489
48443
  }
48490
- },
48491
- pluginConstants: {
48492
- generateContentFromSeed
48493
- }
48494
- };
48444
+ };
48445
+ }), "getDidKeyPlugin");
48495
48446
 
48496
48447
  // src/wallet/plugins/expiration/index.ts
48497
48448
  var ExpirationPlugin = /* @__PURE__ */ __name((wallet) => ({
@@ -48506,8 +48457,7 @@ var ExpirationPlugin = /* @__PURE__ */ __name((wallet) => ({
48506
48457
  }
48507
48458
  return verificationCheck;
48508
48459
  })
48509
- },
48510
- pluginConstants: {}
48460
+ }
48511
48461
  }), "ExpirationPlugin");
48512
48462
 
48513
48463
  // src/wallet/plugins/vc/issueCredential.ts
@@ -48579,8 +48529,7 @@ var getVCPlugin = /* @__PURE__ */ __name((wallet) => __async(void 0, null, funct
48579
48529
  credentialSubject: { id: subject }
48580
48530
  };
48581
48531
  }
48582
- }),
48583
- pluginConstants: {}
48532
+ })
48584
48533
  };
48585
48534
  }), "getVCPlugin");
48586
48535
 
@@ -48640,9 +48589,13 @@ var defaultCeramicIDXArgs = {
48640
48589
  };
48641
48590
 
48642
48591
  // src/wallet/init.ts
48643
- var createWallet = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, ..._1], function* (defaultContents, { ceramicIdx = defaultCeramicIDXArgs, didkit } = {}) {
48592
+ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, ..._1], function* (key2, {
48593
+ ceramicIdx = defaultCeramicIDXArgs,
48594
+ didkit,
48595
+ defaultContents = []
48596
+ } = {}) {
48644
48597
  yield didkit_default(didkit);
48645
- const didkeyWallet = yield (yield generateWallet(defaultContents)).addPlugin(DidKeyPlugin);
48598
+ const didkeyWallet = yield (yield generateWallet(defaultContents)).addPlugin(yield getDidKeyPlugin(key2));
48646
48599
  const didkeyAndVCWallet = yield didkeyWallet.addPlugin(yield getVCPlugin(didkeyWallet));
48647
48600
  const idxWallet = yield didkeyAndVCWallet.addPlugin(yield getIDXPlugin(didkeyAndVCWallet, ceramicIdx));
48648
48601
  const wallet = yield idxWallet.addPlugin(ExpirationPlugin(idxWallet));
@@ -48667,11 +48620,6 @@ var createWallet = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, ..
48667
48620
  readFromCeramic: wallet.pluginMethods.readContentFromCeramic,
48668
48621
  getTestVc: wallet.pluginMethods.getTestVc
48669
48622
  };
48670
- }), "createWallet");
48671
- var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, ..._1], function* (key2, { ceramicIdx = defaultCeramicIDXArgs, didkit } = {}) {
48672
- yield didkit_default(didkit);
48673
- const didDocuments = yield DidKeyPlugin.pluginConstants.generateContentFromSeed(toUint8Array(key2.padStart(64, "0")));
48674
- return createWallet(didDocuments, { ceramicIdx, didkit });
48675
48623
  }), "walletFromKey");
48676
48624
  /*!
48677
48625
  * Copyright (c) 2014, GMO GlobalSign