@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.
package/dist/core.d.ts CHANGED
@@ -4590,23 +4590,26 @@ declare const VerificationItemValidator: z.ZodObject<{
4590
4590
  check: string;
4591
4591
  }>;
4592
4592
  export declare type VerificationItem = z.infer<typeof VerificationItemValidator>;
4593
- export declare type DidMethod = "key" | "tz" | "pkh:tz" | "pkh:tezos" | "pkh:sol" | "pkh:solana";
4593
+ export declare type DidMethod = "key" | "tz" | "ethr" | `pkh:${"tz" | "tezos" | "sol" | "solana" | "eth" | "celo" | "poly" | "btc" | "doge" | "eip155" | "bip122"}` | `pkh:eip155:${string}` | `pkh:bip122:${string}`;
4594
4594
  export declare type KeyPair = {
4595
4595
  kty: string;
4596
4596
  crv: string;
4597
4597
  x: string;
4598
+ y?: string;
4598
4599
  d: string;
4599
4600
  };
4600
4601
  export declare type ProofOptions = {
4601
4602
  verificationMethod: string;
4602
4603
  proofPurpose: string;
4603
4604
  };
4604
- export declare type DidKeyPluginMethods<T extends string> = {
4605
- getSubjectDid: (type: T) => string;
4606
- getSubjectKeypair: () => {
4605
+ export declare type Algorithm = "ed25519" | "secp256k1";
4606
+ export declare type DidKeyPluginMethods<DidMethod extends string> = {
4607
+ getSubjectDid: (type: DidMethod) => string;
4608
+ getSubjectKeypair: (type?: Algorithm) => {
4607
4609
  kty: string;
4608
4610
  crv: string;
4609
4611
  x: string;
4612
+ y?: string;
4610
4613
  d: string;
4611
4614
  };
4612
4615
  getKey: () => string;
@@ -4681,10 +4684,11 @@ export declare type LearnCardWallet = {
4681
4684
  /** Wallet holder's did */
4682
4685
  did: (type?: DidMethod) => string;
4683
4686
  /** Wallet holder's ed25519 key pair */
4684
- keypair: {
4687
+ keypair: (type?: Algorithm) => {
4685
4688
  kty: string;
4686
4689
  crv: string;
4687
4690
  x: string;
4691
+ y?: string;
4688
4692
  d: string;
4689
4693
  };
4690
4694
  /** Signs an unsigned Verifiable Credential, returning the signed VC */
package/dist/core.esm.js CHANGED
@@ -42570,8 +42570,33 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
42570
42570
  };
42571
42571
  }), "getIDXPlugin");
42572
42572
 
42573
- // src/wallet/plugins/didkey/index.ts
42573
+ // src/wallet/plugins/didkey/helpers.ts
42574
+ var ED25519_METHODS = ["key", "tz", "pkh:tz", "pkh:tezos", "pkh:sol", "pkh:solana"];
42575
+ var SECP256K1_METHODS = [
42576
+ "key",
42577
+ "tz",
42578
+ "ethr",
42579
+ "pkh:tz",
42580
+ "pkh:tezos",
42581
+ "pkh:eth",
42582
+ "pkh:celo",
42583
+ "pkh:poly",
42584
+ "pkh:btc",
42585
+ "pkh:doge",
42586
+ "pkh:eip155",
42587
+ "pkh:bip122"
42588
+ ];
42574
42589
  var isHex = /* @__PURE__ */ __name((str) => /^[0-9a-f]+$/i.test(str), "isHex");
42590
+ var getAlgorithmForDidMethod = /* @__PURE__ */ __name((didMethod) => {
42591
+ if (ED25519_METHODS.includes(didMethod))
42592
+ return "ed25519";
42593
+ if (SECP256K1_METHODS.includes(didMethod) || didMethod.startsWith("pkh:eip155:") || didMethod.startsWith("pkh:bip122:")) {
42594
+ return "secp256k1";
42595
+ }
42596
+ throw new Error("Unspported Did Method");
42597
+ }, "getAlgorithmForDidMethod");
42598
+
42599
+ // src/wallet/plugins/didkey/index.ts
42575
42600
  var getDidKeyPlugin = /* @__PURE__ */ __name((wallet, key2) => __async(void 0, null, function* () {
42576
42601
  if (key2.length === 0)
42577
42602
  throw new Error("Please don't use an empty string for a key!");
@@ -42579,12 +42604,28 @@ var getDidKeyPlugin = /* @__PURE__ */ __name((wallet, key2) => __async(void 0, n
42579
42604
  throw new Error("Key must be a hexadecimal string!");
42580
42605
  if (key2.length > 64)
42581
42606
  throw new Error("Key must be less than 64 characters");
42582
- const keypair = wallet.pluginMethods.generateEd25519KeyFromBytes(toUint8Array(key2.padStart(64, "0")));
42607
+ const seed = key2.padStart(64, "0");
42608
+ const seedBytes = toUint8Array(seed);
42609
+ const memoizedDids = {};
42610
+ const keyPairs = {
42611
+ ed25519: wallet.pluginMethods.generateEd25519KeyFromBytes(seedBytes),
42612
+ secp256k1: wallet.pluginMethods.generateSecp256k1KeyFromBytes(seedBytes)
42613
+ };
42583
42614
  return {
42584
42615
  pluginMethods: {
42585
- getSubjectDid: (_wallet, type) => wallet.pluginMethods.keyToDid(type, keypair),
42586
- getSubjectKeypair: () => keypair,
42587
- getKey: () => key2.padStart(64, "0")
42616
+ getSubjectDid: (_wallet, type) => {
42617
+ if (!memoizedDids[type]) {
42618
+ const algorithm = getAlgorithmForDidMethod(type);
42619
+ memoizedDids[type] = wallet.pluginMethods.keyToDid(type, keyPairs[algorithm]);
42620
+ }
42621
+ return memoizedDids[type];
42622
+ },
42623
+ getSubjectKeypair: (_wallet, type = "ed25519") => {
42624
+ if (!keyPairs[type])
42625
+ throw new Error("Unsupported algorithm");
42626
+ return keyPairs[type];
42627
+ },
42628
+ getKey: () => seed
42588
42629
  }
42589
42630
  };
42590
42631
  }), "getDidKeyPlugin");
@@ -47569,6 +47610,30 @@ function generateEd25519KeyFromBytes(bytes) {
47569
47610
  }
47570
47611
  }
47571
47612
  __name(generateEd25519KeyFromBytes, "generateEd25519KeyFromBytes");
47613
+ function generateSecp256k1KeyFromBytes(bytes) {
47614
+ try {
47615
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
47616
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
47617
+ const len0 = WASM_VECTOR_LEN;
47618
+ wasm.generateSecp256k1KeyFromBytes(retptr, ptr0, len0);
47619
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
47620
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
47621
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
47622
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
47623
+ var ptr1 = r0;
47624
+ var len1 = r1;
47625
+ if (r3) {
47626
+ ptr1 = 0;
47627
+ len1 = 0;
47628
+ throw takeObject(r2);
47629
+ }
47630
+ return getStringFromWasm0(ptr1, len1);
47631
+ } finally {
47632
+ wasm.__wbindgen_add_to_stack_pointer(16);
47633
+ wasm.__wbindgen_free(ptr1, len1);
47634
+ }
47635
+ }
47636
+ __name(generateSecp256k1KeyFromBytes, "generateSecp256k1KeyFromBytes");
47572
47637
  function keyToDID(method_pattern, jwk) {
47573
47638
  try {
47574
47639
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
@@ -47656,10 +47721,10 @@ function getArrayU8FromWasm0(ptr, len) {
47656
47721
  return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
47657
47722
  }
47658
47723
  __name(getArrayU8FromWasm0, "getArrayU8FromWasm0");
47659
- function __wbg_adapter_108(arg0, arg1, arg2, arg3) {
47724
+ function __wbg_adapter_110(arg0, arg1, arg2, arg3) {
47660
47725
  wasm.wasm_bindgen__convert__closures__invoke2_mut__h3ecfeb7a01c1be81(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
47661
47726
  }
47662
- __name(__wbg_adapter_108, "__wbg_adapter_108");
47727
+ __name(__wbg_adapter_110, "__wbg_adapter_110");
47663
47728
  function load(module, imports) {
47664
47729
  return __async(this, null, function* () {
47665
47730
  if (typeof Response === "function" && module instanceof Response) {
@@ -47879,7 +47944,7 @@ function init2(input) {
47879
47944
  const a = state0.a;
47880
47945
  state0.a = 0;
47881
47946
  try {
47882
- return __wbg_adapter_108(a, state0.b, arg02, arg12);
47947
+ return __wbg_adapter_110(a, state0.b, arg02, arg12);
47883
47948
  } finally {
47884
47949
  state0.a = a;
47885
47950
  }
@@ -47985,8 +48050,8 @@ function init2(input) {
47985
48050
  const ret = wasm.memory;
47986
48051
  return addHeapObject(ret);
47987
48052
  };
47988
- imports.wbg.__wbindgen_closure_wrapper10902 = function(arg0, arg1, arg2) {
47989
- const ret = makeMutClosure(arg0, arg1, 3717, __wbg_adapter_24);
48053
+ imports.wbg.__wbindgen_closure_wrapper10913 = function(arg0, arg1, arg2) {
48054
+ const ret = makeMutClosure(arg0, arg1, 3725, __wbg_adapter_24);
47990
48055
  return addHeapObject(ret);
47991
48056
  };
47992
48057
  if (typeof input === "string" || typeof Request === "function" && input instanceof Request || typeof URL === "function" && input instanceof URL) {
@@ -48003,7 +48068,7 @@ var didkit_wasm_default = init2;
48003
48068
 
48004
48069
  // src/didkit/index.ts
48005
48070
  var initialized = false;
48006
- var init3 = /* @__PURE__ */ __name((arg = "https://cdn.filestackcontent.com/jXExSjNXSerFVDMIYOgy") => __async(void 0, null, function* () {
48071
+ var init3 = /* @__PURE__ */ __name((arg = "https://cdn.filestackcontent.com/dlXanMvQCGDR76JXcBkA") => __async(void 0, null, function* () {
48007
48072
  if (initialized)
48008
48073
  return;
48009
48074
  initialized = true;
@@ -48018,6 +48083,7 @@ var getDidKitPlugin = /* @__PURE__ */ __name((input) => __async(void 0, null, fu
48018
48083
  return {
48019
48084
  pluginMethods: {
48020
48085
  generateEd25519KeyFromBytes: (_wallet, bytes) => JSON.parse(generateEd25519KeyFromBytes(bytes)),
48086
+ generateSecp256k1KeyFromBytes: (_wallet, bytes) => JSON.parse(generateSecp256k1KeyFromBytes(bytes)),
48021
48087
  keyToDid: (_wallet, type, keypair) => {
48022
48088
  const memoizedDid = memoizedDids[type];
48023
48089
  if (!memoizedDid) {
@@ -48060,9 +48126,7 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
48060
48126
  return {
48061
48127
  _wallet: wallet,
48062
48128
  did: (type = "key") => wallet.pluginMethods.getSubjectDid(type),
48063
- get keypair() {
48064
- return wallet.pluginMethods.getSubjectKeypair();
48065
- },
48129
+ keypair: (type = "ed25519") => wallet.pluginMethods.getSubjectKeypair(type),
48066
48130
  issueCredential: wallet.pluginMethods.issueCredential,
48067
48131
  verifyCredential: verifyCredential2(wallet),
48068
48132
  issuePresentation: wallet.pluginMethods.issuePresentation,
@@ -48098,3 +48162,4 @@ export {
48098
48162
  * @copyright Chen, Yi-Cyuan 2015-2018
48099
48163
  * @license MIT
48100
48164
  */
48165
+ //# sourceMappingURL=core.esm.js.map