@learncard/core 1.0.1 → 1.1.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
@@ -69,28 +69,10 @@ export declare type UnsignedVP = {
69
69
  export declare type VP = UnsignedVP & {
70
70
  proof: Proof;
71
71
  };
72
- export declare type JWK = {
73
- id: string;
74
- type: string | string[];
75
- controller?: string;
76
- publicKeyJwk?: any;
77
- privateKeyJwk?: any;
78
- "@context": string[];
79
- name: string;
80
- image: string;
81
- description: string;
82
- tags: string[];
83
- value?: string;
84
- generatedFrom?: [
85
- string
86
- ];
87
- };
88
72
  export declare type DidKeyPluginMethods = {
89
73
  getSubjectDid: () => string;
90
74
  getSubjectKeypair: () => Record<string, string>;
91
- };
92
- export declare type DidKeyPluginConstants = {
93
- generateContentFromSeed: (seed: Uint8Array) => Promise<JWK[]>;
75
+ getKey: () => string;
94
76
  };
95
77
  export declare type IDXPluginMethods = {
96
78
  getCredentialsListFromIndex: (alias?: string) => Promise<CredentialsList>;
@@ -126,36 +108,34 @@ export declare type VCPluginMethods = {
126
108
  getSubjectKeypair: () => Record<string, string>;
127
109
  };
128
110
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
129
- export declare type Plugin<Name extends string, PublicMethods extends Record<string, (...args: any[]) => any> = Record<never, never>, PublicConstants extends Record<string, any> = Record<never, never>> = {
111
+ export declare type Plugin<Name extends string, PublicMethods extends Record<string, (...args: any[]) => any> = Record<never, never>> = {
130
112
  name?: Name;
131
113
  pluginMethods: {
132
- [Key in keyof PublicMethods]: <T extends UnlockedWallet<any, PublicMethods, PublicConstants>>(wallet: T, ...args: Parameters<PublicMethods[Key]>) => ReturnType<PublicMethods[Key]>;
114
+ [Key in keyof PublicMethods]: <T extends UnlockedWallet<any, PublicMethods>>(wallet: T, ...args: Parameters<PublicMethods[Key]>) => ReturnType<PublicMethods[Key]>;
133
115
  };
134
- pluginConstants: PublicConstants;
135
116
  };
136
- export declare type PublicFieldsObj<PluginMethods extends Record<string, (...args: any[]) => any> = Record<never, never>, PluginConstants extends Record<string, any> = Record<never, never>> = {
117
+ export declare type PublicFieldsObj<PluginMethods extends Record<string, (...args: any[]) => any> = Record<never, never>> = {
137
118
  pluginMethods: PluginMethods;
138
- pluginConstants: PluginConstants;
139
119
  };
140
120
  declare enum WalletStatus {
141
121
  Locked = "LOCKED",
142
122
  Unlocked = "UNLOCKED"
143
123
  }
144
- export declare type BaseWallet<PluginNames extends string = "", PluginMethods extends Record<string, (...args: any[]) => any> = Record<never, never>, PluginConstants extends Record<string, any> = Record<never, never>> = PublicFieldsObj<PluginMethods, PluginConstants> & {
124
+ export declare type BaseWallet<PluginNames extends string = "", PluginMethods extends Record<string, (...args: any[]) => any> = Record<never, never>> = PublicFieldsObj<PluginMethods> & {
145
125
  contents: any[];
146
- plugins: Plugin<PluginNames, Record<string, (...args: any[]) => any>, Record<string, any>>[];
126
+ plugins: Plugin<PluginNames, Record<string, (...args: any[]) => any>>[];
147
127
  };
148
- export declare type LockedWallet<PluginNames extends string = "", PluginMethods extends Record<string, (...args: any[]) => any> = Record<never, never>, PluginConstants extends Record<string, any> = Record<never, never>> = BaseWallet<PluginNames, PluginMethods, PluginConstants> & {
128
+ export declare type LockedWallet<PluginNames extends string = "", PluginMethods extends Record<string, (...args: any[]) => any> = Record<never, never>> = BaseWallet<PluginNames, PluginMethods> & {
149
129
  status: WalletStatus.Locked;
150
130
  };
151
- export declare type UnlockedWallet<PluginNames extends string = "", PluginMethods extends Record<string, (...args: any[]) => any> = Record<never, never>, PluginConstants extends Record<string, any> = Record<never, never>> = BaseWallet<PluginNames, PluginMethods, PluginConstants> & {
131
+ export declare type UnlockedWallet<PluginNames extends string = "", PluginMethods extends Record<string, (...args: any[]) => any> = Record<never, never>> = BaseWallet<PluginNames, PluginMethods> & {
152
132
  status: WalletStatus.Unlocked;
153
- add: (content: any) => Promise<UnlockedWallet<PluginNames, PluginMethods, PluginConstants>>;
154
- remove: (contentId: string) => Promise<UnlockedWallet<PluginNames, PluginMethods, PluginConstants>>;
155
- addPlugin: <Name extends string, Methods extends Record<string, (...args: any[]) => any> = Record<never, never>, Constants extends Record<string, any> = Record<never, never>>(plugin: Plugin<Name, Methods, Constants>) => Promise<UnlockedWallet<"" extends PluginNames ? Name : PluginNames | Name, Record<never, never> extends PluginMethods ? Methods : PluginMethods & Methods, Record<never, never> extends PluginConstants ? Constants : PluginConstants & Constants>>;
133
+ add: (content: any) => Promise<UnlockedWallet<PluginNames, PluginMethods>>;
134
+ remove: (contentId: string) => Promise<UnlockedWallet<PluginNames, PluginMethods>>;
135
+ addPlugin: <Name extends string, Methods extends Record<string, (...args: any[]) => any> = Record<never, never>>(plugin: Plugin<Name, Methods>) => Promise<UnlockedWallet<"" extends PluginNames ? Name : PluginNames | Name, Record<never, never> extends PluginMethods ? Methods : PluginMethods & Methods>>;
156
136
  };
157
- export declare type Wallet<PluginNames extends string = "", PluginMethods extends Record<string, (...args: any[]) => any> = Record<never, never>, PluginConstants extends Record<string, any> = Record<never, never>> = LockedWallet<PluginNames, PluginMethods, PluginConstants> | UnlockedWallet<PluginNames, PluginMethods, PluginConstants>;
158
- export declare type LearnCardRawWallet = UnlockedWallet<"DID Key" | "VC" | "IDX" | "Expiration", DidKeyPluginMethods & VCPluginMethods & IDXPluginMethods, DidKeyPluginConstants>;
137
+ export declare type Wallet<PluginNames extends string = "", PluginMethods extends Record<string, (...args: any[]) => any> = Record<never, never>> = LockedWallet<PluginNames, PluginMethods> | UnlockedWallet<PluginNames, PluginMethods>;
138
+ export declare type LearnCardRawWallet = UnlockedWallet<"DID Key" | "VC" | "IDX" | "Expiration", DidKeyPluginMethods & VCPluginMethods & IDXPluginMethods>;
159
139
  export declare type LearnCardWallet = {
160
140
  /** Raw IoE wallet instance. You shouldn't need to drop down to this level! */
161
141
  _wallet: LearnCardRawWallet;
@@ -222,11 +202,11 @@ export declare type CeramicIDXArgs = {
222
202
  export declare type LearnCardConfig = {
223
203
  ceramicIdx: CeramicIDXArgs;
224
204
  didkit: InitInput | Promise<InitInput>;
205
+ defaultContents: any[];
225
206
  };
226
- export declare const createWallet: (defaultContents: any[], { ceramicIdx, didkit }?: Partial<LearnCardConfig>) => Promise<LearnCardWallet>;
227
- /** Generates did documents from key and returns default wallet */
228
- export declare const walletFromKey: (key: string, { ceramicIdx, didkit }?: Partial<LearnCardConfig>) => Promise<LearnCardWallet>;
229
- export { createWallet, walletFromKey } from "@wallet/init";
207
+ /** Generates a LearnCard Wallet from a 64 character seed string */
208
+ export declare const walletFromKey: (key: string, { ceramicIdx, didkit, defaultContents, }?: Partial<LearnCardConfig>) => Promise<LearnCardWallet>;
209
+ export { walletFromKey } from "@wallet/init";
230
210
  export { Wallet, UnlockedWallet, LockedWallet, Plugin } from "types/wallet";
231
211
 
232
212
  export {};
package/dist/core.esm.js CHANGED
@@ -26909,19 +26909,6 @@ var require_query_string = __commonJS({
26909
26909
  }
26910
26910
  });
26911
26911
 
26912
- // ../../node_modules/.pnpm/hex-lite@1.5.0/node_modules/hex-lite/dist/hex-lite.mjs
26913
- function toUint8Array(str) {
26914
- var s = 0, sl = str.length, bytes = [];
26915
- if (sl % 2) {
26916
- throw new Error("invalid hex:" + str);
26917
- }
26918
- for (; s < sl; s += 2) {
26919
- bytes.push(parseInt(str.substr(s, 2), 16));
26920
- }
26921
- return new Uint8Array(bytes);
26922
- }
26923
- __name(toUint8Array, "toUint8Array");
26924
-
26925
26912
  // src/didkit/pkg/didkit_wasm.js
26926
26913
  var wasm;
26927
26914
  var cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
@@ -36022,7 +36009,6 @@ if (isNodejs()) {
36022
36009
  } else {
36023
36010
  crypto3 = window.crypto;
36024
36011
  }
36025
- var crypto_default = crypto3;
36026
36012
 
36027
36013
  // src/wallet/base/wallet.ts
36028
36014
  var addPluginToWallet = /* @__PURE__ */ __name((wallet, plugin) => __async(void 0, null, function* () {
@@ -36041,11 +36027,10 @@ var removeFromWallet = /* @__PURE__ */ __name((wallet, contentId) => __async(voi
36041
36027
  var bindMethods = /* @__PURE__ */ __name((wallet, pluginMethods) => Object.fromEntries(Object.entries(pluginMethods).map(([key2, method]) => [key2, method.bind(wallet, wallet)])), "bindMethods");
36042
36028
  var generateWallet = /* @__PURE__ */ __name((..._0) => __async(void 0, [..._0], function* (contents = [], _wallet = {}) {
36043
36029
  const { plugins = [] } = _wallet;
36044
- const { pluginMethods, pluginConstants } = plugins.reduce(({ pluginMethods: pluginMethods2, pluginConstants: pluginConstants2 }, plugin) => {
36045
- const newPluginMethods = __spreadValues(__spreadValues({}, pluginMethods2), plugin.pluginMethods);
36046
- const newPluginConstants = __spreadValues(__spreadValues({}, pluginConstants2), plugin.pluginConstants);
36047
- return { pluginMethods: newPluginMethods, pluginConstants: newPluginConstants };
36048
- }, { pluginMethods: {}, pluginConstants: {} });
36030
+ const pluginMethods = plugins.reduce((cumulativePluginMethods, plugin) => {
36031
+ const newPluginMethods = __spreadValues(__spreadValues({}, cumulativePluginMethods), plugin.pluginMethods);
36032
+ return newPluginMethods;
36033
+ }, {});
36049
36034
  const wallet = {
36050
36035
  contents: [...contents],
36051
36036
  add: function(content) {
@@ -36057,7 +36042,6 @@ var generateWallet = /* @__PURE__ */ __name((..._0) => __async(void 0, [..._0],
36057
36042
  status: "UNLOCKED" /* Unlocked */,
36058
36043
  plugins,
36059
36044
  pluginMethods,
36060
- pluginConstants,
36061
36045
  addPlugin: function(plugin) {
36062
36046
  return addPluginToWallet(this, plugin);
36063
36047
  }
@@ -43332,6 +43316,19 @@ var DID = class {
43332
43316
  };
43333
43317
  __name(DID, "DID");
43334
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
+
43335
43332
  // src/wallet/plugins/idx/idx.ts
43336
43333
  var import_key_did_resolver = __toESM(require_lib());
43337
43334
 
@@ -48356,13 +48353,11 @@ __name(CeramicClient, "CeramicClient");
48356
48353
 
48357
48354
  // src/wallet/plugins/idx/idx.ts
48358
48355
  var getCeramicClientFromWalletSuite = /* @__PURE__ */ __name((wallet, ceramicEndpoint) => __async(void 0, null, function* () {
48359
- var _a2, _b;
48360
48356
  const client = new CeramicClient(ceramicEndpoint);
48361
48357
  const resolver = __spreadValues({}, import_key_did_resolver.default.getResolver());
48362
48358
  const did = new DID({ resolver });
48363
48359
  client.did = did;
48364
- const contents = JSON.parse(JSON.stringify(wallet.contents));
48365
- 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();
48366
48361
  const ceramicProvider = new Ed25519Provider(toUint8Array(key2));
48367
48362
  client.did.setProvider(ceramicProvider);
48368
48363
  yield client.did.authenticate();
@@ -48432,65 +48427,22 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
48432
48427
  addVerifiableCredentialInIdx: (_02, _12) => __async(void 0, [_02, _12], function* (_wallet, { title, id }) {
48433
48428
  return addCredentialStreamIdToIndex({ title, id });
48434
48429
  })
48435
- },
48436
- pluginConstants: {}
48430
+ }
48437
48431
  };
48438
48432
  }), "getIDXPlugin");
48439
48433
 
48440
- // src/wallet/plugins/didkey/generateContentFromSeed.ts
48441
- var seedToId = /* @__PURE__ */ __name((seed) => __async(void 0, null, function* () {
48442
- const buffer2 = yield crypto_default.subtle.digest("SHA-256", seed);
48443
- return `urn:digest:${Buffer.from(new Uint8Array(buffer2)).toString("hex")}`;
48444
- }), "seedToId");
48445
- var generateContentFromSeed = /* @__PURE__ */ __name((seed) => __async(void 0, null, function* () {
48446
- const privateKeyJwk = JSON.parse(generateEd25519KeyFromBytes(seed));
48447
- const controller = keyToDID("key", JSON.stringify(privateKeyJwk));
48448
- const _a2 = privateKeyJwk, { d } = _a2, publicKeyJwk = __objRest(_a2, ["d"]);
48449
- const signingKey = {
48450
- controller,
48451
- id: `${controller}#${controller.split(":").at(-1)}`,
48452
- privateKeyJwk,
48453
- publicKeyJwk,
48454
- type: "JsonWebKey2020"
48455
- };
48456
- const seedId = yield seedToId(seed);
48457
- const secret = {
48458
- "@context": ["http://w3id.org/wallet/v1"],
48459
- id: seedId,
48460
- name: "DID Key Secret",
48461
- image: "https://via.placeholder.com/150",
48462
- description: "Used to generate a DID with a signing and encryption key.",
48463
- tags: ["inception"],
48464
- type: "Entropy",
48465
- value: Buffer.from(seed).toString("hex")
48466
- };
48467
- const key0 = __spreadProps(__spreadValues({}, signingKey), {
48468
- "@context": ["http://w3id.org/wallet/v1"],
48469
- name: "Signing Key",
48470
- image: "https://via.placeholder.com/150",
48471
- description: "Used to produce digital signatures.",
48472
- tags: ["inception"],
48473
- generatedFrom: [secret.id]
48474
- });
48475
- return [secret, key0];
48476
- }), "generateContentFromSeed");
48477
-
48478
48434
  // src/wallet/plugins/didkey/index.ts
48479
- var DidKeyPlugin = {
48480
- pluginMethods: {
48481
- getSubjectDid: (wallet) => {
48482
- var _a2, _b;
48483
- return (_b = (_a2 = wallet.contents.find((content) => content.name === "Signing Key")) == null ? void 0 : _a2.controller) != null ? _b : "";
48484
- },
48485
- getSubjectKeypair: (wallet) => {
48486
- var _a2;
48487
- 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
48488
48443
  }
48489
- },
48490
- pluginConstants: {
48491
- generateContentFromSeed
48492
- }
48493
- };
48444
+ };
48445
+ }), "getDidKeyPlugin");
48494
48446
 
48495
48447
  // src/wallet/plugins/expiration/index.ts
48496
48448
  var ExpirationPlugin = /* @__PURE__ */ __name((wallet) => ({
@@ -48505,8 +48457,7 @@ var ExpirationPlugin = /* @__PURE__ */ __name((wallet) => ({
48505
48457
  }
48506
48458
  return verificationCheck;
48507
48459
  })
48508
- },
48509
- pluginConstants: {}
48460
+ }
48510
48461
  }), "ExpirationPlugin");
48511
48462
 
48512
48463
  // src/wallet/plugins/vc/issueCredential.ts
@@ -48578,8 +48529,7 @@ var getVCPlugin = /* @__PURE__ */ __name((wallet) => __async(void 0, null, funct
48578
48529
  credentialSubject: { id: subject }
48579
48530
  };
48580
48531
  }
48581
- }),
48582
- pluginConstants: {}
48532
+ })
48583
48533
  };
48584
48534
  }), "getVCPlugin");
48585
48535
 
@@ -48639,9 +48589,13 @@ var defaultCeramicIDXArgs = {
48639
48589
  };
48640
48590
 
48641
48591
  // src/wallet/init.ts
48642
- 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
+ } = {}) {
48643
48597
  yield didkit_default(didkit);
48644
- const didkeyWallet = yield (yield generateWallet(defaultContents)).addPlugin(DidKeyPlugin);
48598
+ const didkeyWallet = yield (yield generateWallet(defaultContents)).addPlugin(yield getDidKeyPlugin(key2));
48645
48599
  const didkeyAndVCWallet = yield didkeyWallet.addPlugin(yield getVCPlugin(didkeyWallet));
48646
48600
  const idxWallet = yield didkeyAndVCWallet.addPlugin(yield getIDXPlugin(didkeyAndVCWallet, ceramicIdx));
48647
48601
  const wallet = yield idxWallet.addPlugin(ExpirationPlugin(idxWallet));
@@ -48666,14 +48620,8 @@ var createWallet = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, ..
48666
48620
  readFromCeramic: wallet.pluginMethods.readContentFromCeramic,
48667
48621
  getTestVc: wallet.pluginMethods.getTestVc
48668
48622
  };
48669
- }), "createWallet");
48670
- var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, ..._1], function* (key2, { ceramicIdx = defaultCeramicIDXArgs, didkit } = {}) {
48671
- yield didkit_default(didkit);
48672
- const didDocuments = yield DidKeyPlugin.pluginConstants.generateContentFromSeed(toUint8Array(key2.padStart(64, "0")));
48673
- return createWallet(didDocuments, { ceramicIdx, didkit });
48674
48623
  }), "walletFromKey");
48675
48624
  export {
48676
- createWallet,
48677
48625
  walletFromKey
48678
48626
  };
48679
48627
  /*!