@learncard/core 1.3.1 → 1.4.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.
@@ -42568,8 +42568,33 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
42568
42568
  };
42569
42569
  }), "getIDXPlugin");
42570
42570
 
42571
- // src/wallet/plugins/didkey/index.ts
42571
+ // src/wallet/plugins/didkey/helpers.ts
42572
+ var ED25519_METHODS = ["key", "tz", "pkh:tz", "pkh:tezos", "pkh:sol", "pkh:solana"];
42573
+ var SECP256K1_METHODS = [
42574
+ "key",
42575
+ "tz",
42576
+ "ethr",
42577
+ "pkh:tz",
42578
+ "pkh:tezos",
42579
+ "pkh:eth",
42580
+ "pkh:celo",
42581
+ "pkh:poly",
42582
+ "pkh:btc",
42583
+ "pkh:doge",
42584
+ "pkh:eip155",
42585
+ "pkh:bip122"
42586
+ ];
42572
42587
  var isHex = /* @__PURE__ */ __name((str) => /^[0-9a-f]+$/i.test(str), "isHex");
42588
+ var getAlgorithmForDidMethod = /* @__PURE__ */ __name((didMethod) => {
42589
+ if (ED25519_METHODS.includes(didMethod))
42590
+ return "ed25519";
42591
+ if (SECP256K1_METHODS.includes(didMethod) || didMethod.startsWith("pkh:eip155:") || didMethod.startsWith("pkh:bip122:")) {
42592
+ return "secp256k1";
42593
+ }
42594
+ throw new Error("Unspported Did Method");
42595
+ }, "getAlgorithmForDidMethod");
42596
+
42597
+ // src/wallet/plugins/didkey/index.ts
42573
42598
  var getDidKeyPlugin = /* @__PURE__ */ __name((wallet, key2) => __async(void 0, null, function* () {
42574
42599
  if (key2.length === 0)
42575
42600
  throw new Error("Please don't use an empty string for a key!");
@@ -42577,12 +42602,28 @@ var getDidKeyPlugin = /* @__PURE__ */ __name((wallet, key2) => __async(void 0, n
42577
42602
  throw new Error("Key must be a hexadecimal string!");
42578
42603
  if (key2.length > 64)
42579
42604
  throw new Error("Key must be less than 64 characters");
42580
- const keypair = wallet.pluginMethods.generateEd25519KeyFromBytes(toUint8Array(key2.padStart(64, "0")));
42605
+ const seed = key2.padStart(64, "0");
42606
+ const seedBytes = toUint8Array(seed);
42607
+ const memoizedDids = {};
42608
+ const keyPairs = {
42609
+ ed25519: wallet.pluginMethods.generateEd25519KeyFromBytes(seedBytes),
42610
+ secp256k1: wallet.pluginMethods.generateSecp256k1KeyFromBytes(seedBytes)
42611
+ };
42581
42612
  return {
42582
42613
  pluginMethods: {
42583
- getSubjectDid: (_wallet, type) => wallet.pluginMethods.keyToDid(type, keypair),
42584
- getSubjectKeypair: () => keypair,
42585
- getKey: () => key2.padStart(64, "0")
42614
+ getSubjectDid: (_wallet, type) => {
42615
+ if (!memoizedDids[type]) {
42616
+ const algorithm = getAlgorithmForDidMethod(type);
42617
+ memoizedDids[type] = wallet.pluginMethods.keyToDid(type, keyPairs[algorithm]);
42618
+ }
42619
+ return memoizedDids[type];
42620
+ },
42621
+ getSubjectKeypair: (_wallet, type = "ed25519") => {
42622
+ if (!keyPairs[type])
42623
+ throw new Error("Unsupported algorithm");
42624
+ return keyPairs[type];
42625
+ },
42626
+ getKey: () => seed
42586
42627
  }
42587
42628
  };
42588
42629
  }), "getDidKeyPlugin");
@@ -47567,6 +47608,30 @@ function generateEd25519KeyFromBytes(bytes) {
47567
47608
  }
47568
47609
  }
47569
47610
  __name(generateEd25519KeyFromBytes, "generateEd25519KeyFromBytes");
47611
+ function generateSecp256k1KeyFromBytes(bytes) {
47612
+ try {
47613
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
47614
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
47615
+ const len0 = WASM_VECTOR_LEN;
47616
+ wasm.generateSecp256k1KeyFromBytes(retptr, ptr0, len0);
47617
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
47618
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
47619
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
47620
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
47621
+ var ptr1 = r0;
47622
+ var len1 = r1;
47623
+ if (r3) {
47624
+ ptr1 = 0;
47625
+ len1 = 0;
47626
+ throw takeObject(r2);
47627
+ }
47628
+ return getStringFromWasm0(ptr1, len1);
47629
+ } finally {
47630
+ wasm.__wbindgen_add_to_stack_pointer(16);
47631
+ wasm.__wbindgen_free(ptr1, len1);
47632
+ }
47633
+ }
47634
+ __name(generateSecp256k1KeyFromBytes, "generateSecp256k1KeyFromBytes");
47570
47635
  function keyToDID(method_pattern, jwk) {
47571
47636
  try {
47572
47637
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
@@ -47654,10 +47719,10 @@ function getArrayU8FromWasm0(ptr, len) {
47654
47719
  return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
47655
47720
  }
47656
47721
  __name(getArrayU8FromWasm0, "getArrayU8FromWasm0");
47657
- function __wbg_adapter_108(arg0, arg1, arg2, arg3) {
47722
+ function __wbg_adapter_110(arg0, arg1, arg2, arg3) {
47658
47723
  wasm.wasm_bindgen__convert__closures__invoke2_mut__h3ecfeb7a01c1be81(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
47659
47724
  }
47660
- __name(__wbg_adapter_108, "__wbg_adapter_108");
47725
+ __name(__wbg_adapter_110, "__wbg_adapter_110");
47661
47726
  function load(module2, imports) {
47662
47727
  return __async(this, null, function* () {
47663
47728
  if (typeof Response === "function" && module2 instanceof Response) {
@@ -47877,7 +47942,7 @@ function init2(input) {
47877
47942
  const a = state0.a;
47878
47943
  state0.a = 0;
47879
47944
  try {
47880
- return __wbg_adapter_108(a, state0.b, arg02, arg12);
47945
+ return __wbg_adapter_110(a, state0.b, arg02, arg12);
47881
47946
  } finally {
47882
47947
  state0.a = a;
47883
47948
  }
@@ -47983,8 +48048,8 @@ function init2(input) {
47983
48048
  const ret = wasm.memory;
47984
48049
  return addHeapObject(ret);
47985
48050
  };
47986
- imports.wbg.__wbindgen_closure_wrapper10902 = function(arg0, arg1, arg2) {
47987
- const ret = makeMutClosure(arg0, arg1, 3717, __wbg_adapter_24);
48051
+ imports.wbg.__wbindgen_closure_wrapper10913 = function(arg0, arg1, arg2) {
48052
+ const ret = makeMutClosure(arg0, arg1, 3725, __wbg_adapter_24);
47988
48053
  return addHeapObject(ret);
47989
48054
  };
47990
48055
  if (typeof input === "string" || typeof Request === "function" && input instanceof Request || typeof URL === "function" && input instanceof URL) {
@@ -48001,7 +48066,7 @@ var didkit_wasm_default = init2;
48001
48066
 
48002
48067
  // src/didkit/index.ts
48003
48068
  var initialized = false;
48004
- var init3 = /* @__PURE__ */ __name((arg = "https://cdn.filestackcontent.com/jXExSjNXSerFVDMIYOgy") => __async(void 0, null, function* () {
48069
+ var init3 = /* @__PURE__ */ __name((arg = "https://cdn.filestackcontent.com/dlXanMvQCGDR76JXcBkA") => __async(void 0, null, function* () {
48005
48070
  if (initialized)
48006
48071
  return;
48007
48072
  initialized = true;
@@ -48016,6 +48081,7 @@ var getDidKitPlugin = /* @__PURE__ */ __name((input) => __async(void 0, null, fu
48016
48081
  return {
48017
48082
  pluginMethods: {
48018
48083
  generateEd25519KeyFromBytes: (_wallet, bytes) => JSON.parse(generateEd25519KeyFromBytes(bytes)),
48084
+ generateSecp256k1KeyFromBytes: (_wallet, bytes) => JSON.parse(generateSecp256k1KeyFromBytes(bytes)),
48019
48085
  keyToDid: (_wallet, type, keypair) => {
48020
48086
  const memoizedDid = memoizedDids[type];
48021
48087
  if (!memoizedDid) {
@@ -48058,9 +48124,7 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
48058
48124
  return {
48059
48125
  _wallet: wallet,
48060
48126
  did: (type = "key") => wallet.pluginMethods.getSubjectDid(type),
48061
- get keypair() {
48062
- return wallet.pluginMethods.getSubjectKeypair();
48063
- },
48127
+ keypair: (type = "ed25519") => wallet.pluginMethods.getSubjectKeypair(type),
48064
48128
  issueCredential: wallet.pluginMethods.issueCredential,
48065
48129
  verifyCredential: verifyCredential2(wallet),
48066
48130
  issuePresentation: wallet.pluginMethods.issuePresentation,
@@ -48093,3 +48157,4 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
48093
48157
  * @copyright Chen, Yi-Cyuan 2015-2018
48094
48158
  * @license MIT
48095
48159
  */
48160
+ //# sourceMappingURL=core.cjs.development.js.map