@learncard/didkey-plugin 1.1.8 → 1.1.12
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/didkey-plugin.cjs.development.js +3 -1
- package/dist/didkey-plugin.cjs.development.js.map +2 -2
- package/dist/didkey-plugin.cjs.production.min.js +1 -1
- package/dist/didkey-plugin.cjs.production.min.js.map +3 -3
- package/dist/didkey-plugin.esm.js +3 -1
- package/dist/didkey-plugin.esm.js.map +2 -2
- package/dist/index.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -66,11 +66,13 @@ var getAlgorithmForDidMethod = /* @__PURE__ */ __name((didMethod) => {
|
|
|
66
66
|
}, "getAlgorithmForDidMethod");
|
|
67
67
|
|
|
68
68
|
// src/index.ts
|
|
69
|
+
var _shortSeedWarned = false;
|
|
69
70
|
var getDidKeyPlugin = /* @__PURE__ */ __name(async (learnCard, key, defaultDidMethod) => {
|
|
70
71
|
if (key.length === 0) throw new Error("Please don't use an empty string for a key!");
|
|
71
72
|
if (!(0, import_helpers.isHex)(key)) throw new Error("Key must be a hexadecimal string!");
|
|
72
73
|
if (key.length > 64) throw new Error("Key must be less than 64 characters");
|
|
73
|
-
if (key.length < 64) {
|
|
74
|
+
if (key.length < 64 && !_shortSeedWarned) {
|
|
75
|
+
_shortSeedWarned = true;
|
|
74
76
|
console.warn(
|
|
75
77
|
"Warning: A LearnCard has been initialized with a seed that is less than 32 bytes, and will be padded with zeroes"
|
|
76
78
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts", "../../../../node_modules/.pnpm/hex-lite@1.5.0/node_modules/hex-lite/dist/hex-lite.mjs", "../src/helpers.ts"],
|
|
4
|
-
"sourcesContent": ["import { toUint8Array } from 'hex-lite';\nimport { isHex } from '@learncard/helpers';\nimport { JWKWithPrivateKey } from '@learncard/types';\nimport { LearnCard } from '@learncard/core';\n\nimport { getAlgorithmForDidMethod } from './helpers';\n\nimport { DidKeyPlugin, DependentMethods, Algorithm } from './types';\n\nexport * from './types';\n\n/**\n *\n * @group Plugins\n */\nexport const getDidKeyPlugin = async <DidMethod extends string>(\n learnCard: LearnCard<any, any, DependentMethods<DidMethod>>,\n key: string,\n defaultDidMethod: DidMethod\n): Promise<DidKeyPlugin<DidMethod>> => {\n if (key.length === 0) throw new Error(\"Please don't use an empty string for a key!\");\n if (!isHex(key)) throw new Error('Key must be a hexadecimal string!');\n if (key.length > 64) throw new Error('Key must be less than 64 characters');\n\n if (key.length < 64) {\n console.warn(\n 'Warning: A LearnCard has been initialized with a seed that is less than 32 bytes, and will be padded with zeroes'\n );\n console.warn(\n 'Please instantiate LearnCards using 32 bytes that have been randomly generated in a cryptographically secure fashion!'\n );\n console.warn(\n 'See https://app.gitbook.com/o/6uDv1QDlxaaZC7i8EaGb/s/FXvEJ9j3Vf3FW5Nc557n/learn-card-packages/learncard-core/instantiation#key-generation for details'\n );\n }\n\n const seed = key.padStart(64, '0');\n const seedBytes = toUint8Array(seed);\n\n const memoizedDids: Partial<Record<DidMethod, string>> = {};\n const keyPairs: Record<Algorithm, JWKWithPrivateKey> = {\n ed25519: learnCard.invoke.generateEd25519KeyFromBytes(seedBytes),\n secp256k1: learnCard.invoke.generateSecp256k1KeyFromBytes(seedBytes),\n };\n\n const did = (method = defaultDidMethod) => {\n if (!memoizedDids[method]) {\n const algorithm = getAlgorithmForDidMethod(method);\n memoizedDids[method] = learnCard.invoke.keyToDid(method, keyPairs[algorithm]);\n }\n\n return memoizedDids[method]!;\n };\n\n const keypair = (algorithm: Algorithm = 'ed25519') => {\n if (!keyPairs[algorithm]) throw new Error('Unsupported algorithm');\n\n return keyPairs[algorithm];\n };\n\n return {\n name: 'DID Key',\n displayName: 'DID Key',\n description: 'Generates dids and JWKs using 32 Secure Random Bytes of Entropy',\n id: {\n did: (_learnCard, method) => did(method as any),\n keypair: (_learnCard, algorithm) => keypair(algorithm as any),\n },\n methods: {\n getSubjectDid: (_learnCard, method = defaultDidMethod) => did(method),\n getSubjectKeypair: (_learnCard, algorithm = 'ed25519') => keypair(algorithm),\n getKey: () => seed,\n },\n };\n};\n", "function fromUint8Array(uint8Array) {\n return uint8Array.reduce(function (ag, v) { return ag += ('00' + v.toString(16)).slice(-2); }, '');\n}\n\nfunction toUint8Array(str) {\n var s = 0, sl = str.length, bytes = [];\n if (sl % 2) \n { throw new Error('invalid hex:' + str); }\n for (; s < sl; s += 2) {\n bytes.push(parseInt(str.substr(s, 2), 16));\n }\n return new Uint8Array(bytes);\n}\n\nfunction fromBuffer(buffer) {\n return fromUint8Array(new Uint8Array(buffer));\n}\n\nfunction toBuffer(str) {\n return toUint8Array(str).buffer;\n}\n\nexport { fromUint8Array, toUint8Array, fromBuffer, toBuffer };\n//# sourceMappingURL=hex-lite.mjs.map\n", "import { Algorithm } from './types';\n\nexport const ED25519_METHODS = ['key', 'tz', 'pkh:tz', 'pkh:tezos', 'pkh:sol', 'pkh:solana'];\n\nexport const SECP256K1_METHODS = [\n 'key',\n 'tz',\n 'ethr',\n 'pkh:tz',\n 'pkh:tezos',\n 'pkh:eth',\n 'pkh:celo',\n 'pkh:poly',\n 'pkh:btc',\n 'pkh:doge',\n 'pkh:eip155',\n 'pkh:bip122',\n];\n\nexport const getAlgorithmForDidMethod = <DidMethod extends string>(\n didMethod: DidMethod\n): Algorithm => {\n if (ED25519_METHODS.includes(didMethod)) return 'ed25519';\n if (\n SECP256K1_METHODS.includes(didMethod) ||\n didMethod.startsWith('pkh:eip155:') ||\n didMethod.startsWith('pkh:bip122:')\n ) {\n return 'secp256k1';\n }\n\n throw new Error('Unspported Did Method');\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIA,SAAS,aAAa,KAAK;AACvB,MAAI,IAAI,GAAG,KAAK,IAAI,QAAQ,QAAQ,CAAC;AACrC,MAAI,KAAK,GACL;AAAE,UAAM,IAAI,MAAM,iBAAiB,GAAG;AAAA,EAAG;AAC7C,SAAO,IAAI,IAAI,KAAK,GAAG;AACnB,UAAM,KAAK,SAAS,IAAI,OAAO,GAAG,CAAC,GAAG,EAAE,CAAC;AAAA,EAC7C;AACA,SAAO,IAAI,WAAW,KAAK;AAC/B;AARS;;;ADHT,qBAAsB;;;AECf,IAAM,kBAAkB,CAAC,OAAO,MAAM,UAAU,aAAa,WAAW,YAAY;AAEpF,IAAM,oBAAoB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAEO,IAAM,2BAA2B,wBACpC,cACY;AACZ,MAAI,gBAAgB,SAAS,SAAS,EAAG,QAAO;AAChD,MACI,kBAAkB,SAAS,SAAS,KACpC,UAAU,WAAW,aAAa,KAClC,UAAU,WAAW,aAAa,GACpC;AACE,WAAO;AAAA,EACX;AAEA,QAAM,IAAI,MAAM,uBAAuB;AAC3C,GAbwC;;;
|
|
4
|
+
"sourcesContent": ["import { toUint8Array } from 'hex-lite';\nimport { isHex } from '@learncard/helpers';\nimport { JWKWithPrivateKey } from '@learncard/types';\nimport { LearnCard } from '@learncard/core';\n\nimport { getAlgorithmForDidMethod } from './helpers';\n\nimport { DidKeyPlugin, DependentMethods, Algorithm } from './types';\n\nexport * from './types';\n\nlet _shortSeedWarned = false;\n\n/**\n *\n * @group Plugins\n */\nexport const getDidKeyPlugin = async <DidMethod extends string>(\n learnCard: LearnCard<any, any, DependentMethods<DidMethod>>,\n key: string,\n defaultDidMethod: DidMethod\n): Promise<DidKeyPlugin<DidMethod>> => {\n if (key.length === 0) throw new Error(\"Please don't use an empty string for a key!\");\n if (!isHex(key)) throw new Error('Key must be a hexadecimal string!');\n if (key.length > 64) throw new Error('Key must be less than 64 characters');\n\n if (key.length < 64 && !_shortSeedWarned) {\n _shortSeedWarned = true;\n\n console.warn(\n 'Warning: A LearnCard has been initialized with a seed that is less than 32 bytes, and will be padded with zeroes'\n );\n console.warn(\n 'Please instantiate LearnCards using 32 bytes that have been randomly generated in a cryptographically secure fashion!'\n );\n console.warn(\n 'See https://app.gitbook.com/o/6uDv1QDlxaaZC7i8EaGb/s/FXvEJ9j3Vf3FW5Nc557n/learn-card-packages/learncard-core/instantiation#key-generation for details'\n );\n }\n\n const seed = key.padStart(64, '0');\n const seedBytes = toUint8Array(seed);\n\n const memoizedDids: Partial<Record<DidMethod, string>> = {};\n const keyPairs: Record<Algorithm, JWKWithPrivateKey> = {\n ed25519: learnCard.invoke.generateEd25519KeyFromBytes(seedBytes),\n secp256k1: learnCard.invoke.generateSecp256k1KeyFromBytes(seedBytes),\n };\n\n const did = (method = defaultDidMethod) => {\n if (!memoizedDids[method]) {\n const algorithm = getAlgorithmForDidMethod(method);\n memoizedDids[method] = learnCard.invoke.keyToDid(method, keyPairs[algorithm]);\n }\n\n return memoizedDids[method]!;\n };\n\n const keypair = (algorithm: Algorithm = 'ed25519') => {\n if (!keyPairs[algorithm]) throw new Error('Unsupported algorithm');\n\n return keyPairs[algorithm];\n };\n\n return {\n name: 'DID Key',\n displayName: 'DID Key',\n description: 'Generates dids and JWKs using 32 Secure Random Bytes of Entropy',\n id: {\n did: (_learnCard, method) => did(method as any),\n keypair: (_learnCard, algorithm) => keypair(algorithm as any),\n },\n methods: {\n getSubjectDid: (_learnCard, method = defaultDidMethod) => did(method),\n getSubjectKeypair: (_learnCard, algorithm = 'ed25519') => keypair(algorithm),\n getKey: () => seed,\n },\n };\n};\n", "function fromUint8Array(uint8Array) {\n return uint8Array.reduce(function (ag, v) { return ag += ('00' + v.toString(16)).slice(-2); }, '');\n}\n\nfunction toUint8Array(str) {\n var s = 0, sl = str.length, bytes = [];\n if (sl % 2) \n { throw new Error('invalid hex:' + str); }\n for (; s < sl; s += 2) {\n bytes.push(parseInt(str.substr(s, 2), 16));\n }\n return new Uint8Array(bytes);\n}\n\nfunction fromBuffer(buffer) {\n return fromUint8Array(new Uint8Array(buffer));\n}\n\nfunction toBuffer(str) {\n return toUint8Array(str).buffer;\n}\n\nexport { fromUint8Array, toUint8Array, fromBuffer, toBuffer };\n//# sourceMappingURL=hex-lite.mjs.map\n", "import { Algorithm } from './types';\n\nexport const ED25519_METHODS = ['key', 'tz', 'pkh:tz', 'pkh:tezos', 'pkh:sol', 'pkh:solana'];\n\nexport const SECP256K1_METHODS = [\n 'key',\n 'tz',\n 'ethr',\n 'pkh:tz',\n 'pkh:tezos',\n 'pkh:eth',\n 'pkh:celo',\n 'pkh:poly',\n 'pkh:btc',\n 'pkh:doge',\n 'pkh:eip155',\n 'pkh:bip122',\n];\n\nexport const getAlgorithmForDidMethod = <DidMethod extends string>(\n didMethod: DidMethod\n): Algorithm => {\n if (ED25519_METHODS.includes(didMethod)) return 'ed25519';\n if (\n SECP256K1_METHODS.includes(didMethod) ||\n didMethod.startsWith('pkh:eip155:') ||\n didMethod.startsWith('pkh:bip122:')\n ) {\n return 'secp256k1';\n }\n\n throw new Error('Unspported Did Method');\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIA,SAAS,aAAa,KAAK;AACvB,MAAI,IAAI,GAAG,KAAK,IAAI,QAAQ,QAAQ,CAAC;AACrC,MAAI,KAAK,GACL;AAAE,UAAM,IAAI,MAAM,iBAAiB,GAAG;AAAA,EAAG;AAC7C,SAAO,IAAI,IAAI,KAAK,GAAG;AACnB,UAAM,KAAK,SAAS,IAAI,OAAO,GAAG,CAAC,GAAG,EAAE,CAAC;AAAA,EAC7C;AACA,SAAO,IAAI,WAAW,KAAK;AAC/B;AARS;;;ADHT,qBAAsB;;;AECf,IAAM,kBAAkB,CAAC,OAAO,MAAM,UAAU,aAAa,WAAW,YAAY;AAEpF,IAAM,oBAAoB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;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Ac;AAClD,QAAI,CAAC,SAAS,SAAS,EAAG,OAAM,IAAI,MAAM,uBAAuB;AAEjE,WAAO,SAAS,SAAS;AAAA,EAC7B,GAJgB;AAMhB,SAAO;AAAA,IACH,MAAM;AAAA,IACN,aAAa;AAAA,IACb,aAAa;AAAA,IACb,IAAI;AAAA,MACA,KAAK,wBAAC,YAAY,WAAW,IAAI,MAAa,GAAzC;AAAA,MACL,SAAS,wBAAC,YAAY,cAAc,QAAQ,SAAgB,GAAnD;AAAA,IACb;AAAA,IACA,SAAS;AAAA,MACL,eAAe,wBAAC,YAAY,SAAS,qBAAqB,IAAI,MAAM,GAArD;AAAA,MACf,mBAAmB,wBAAC,YAAY,YAAY,cAAc,QAAQ,SAAS,GAAxD;AAAA,MACnB,QAAQ,6BAAM,MAAN;AAAA,IACZ;AAAA,EACJ;AACJ,GA7D+B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var d=Object.defineProperty;var
|
|
1
|
+
"use strict";var d=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var t=(e,r)=>d(e,"name",{value:r,configurable:!0});var w=(e,r)=>{for(var o in r)d(e,o,{get:r[o],enumerable:!0})},b=(e,r,o,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of k(r))!D.call(e,s)&&s!==o&&d(e,s,{get:()=>r[s],enumerable:!(a=m(r,s))||a.enumerable});return e};var K=e=>b(d({},"__esModule",{value:!0}),e);var P={};w(P,{getDidKeyPlugin:()=>x});module.exports=K(P);function y(e){var r=0,o=e.length,a=[];if(o%2)throw new Error("invalid hex:"+e);for(;r<o;r+=2)a.push(parseInt(e.substr(r,2),16));return new Uint8Array(a)}t(y,"toUint8Array");var f=require("@learncard/helpers");var E=["key","tz","pkh:tz","pkh:tezos","pkh:sol","pkh:solana"],A=["key","tz","ethr","pkh:tz","pkh:tezos","pkh:eth","pkh:celo","pkh:poly","pkh:btc","pkh:doge","pkh:eip155","pkh:bip122"],g=t(e=>{if(E.includes(e))return"ed25519";if(A.includes(e)||e.startsWith("pkh:eip155:")||e.startsWith("pkh:bip122:"))return"secp256k1";throw new Error("Unspported Did Method")},"getAlgorithmForDidMethod");var u=!1,x=t(async(e,r,o)=>{if(r.length===0)throw new Error("Please don't use an empty string for a key!");if(!(0,f.isHex)(r))throw new Error("Key must be a hexadecimal string!");if(r.length>64)throw new Error("Key must be less than 64 characters");r.length<64&&!u&&(u=!0,console.warn("Warning: A LearnCard has been initialized with a seed that is less than 32 bytes, and will be padded with zeroes"),console.warn("Please instantiate LearnCards using 32 bytes that have been randomly generated in a cryptographically secure fashion!"),console.warn("See https://app.gitbook.com/o/6uDv1QDlxaaZC7i8EaGb/s/FXvEJ9j3Vf3FW5Nc557n/learn-card-packages/learncard-core/instantiation#key-generation for details"));let a=r.padStart(64,"0"),s=y(a),h={},p={ed25519:e.invoke.generateEd25519KeyFromBytes(s),secp256k1:e.invoke.generateSecp256k1KeyFromBytes(s)},c=t((n=o)=>{if(!h[n]){let i=g(n);h[n]=e.invoke.keyToDid(n,p[i])}return h[n]},"did"),l=t((n="ed25519")=>{if(!p[n])throw new Error("Unsupported algorithm");return p[n]},"keypair");return{name:"DID Key",displayName:"DID Key",description:"Generates dids and JWKs using 32 Secure Random Bytes of Entropy",id:{did:t((n,i)=>c(i),"did"),keypair:t((n,i)=>l(i),"keypair")},methods:{getSubjectDid:t((n,i=o)=>c(i),"getSubjectDid"),getSubjectKeypair:t((n,i="ed25519")=>l(i),"getSubjectKeypair"),getKey:t(()=>a,"getKey")}}},"getDidKeyPlugin");
|
|
2
2
|
//# sourceMappingURL=didkey-plugin.cjs.production.min.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts", "../../../../node_modules/.pnpm/hex-lite@1.5.0/node_modules/hex-lite/dist/hex-lite.mjs", "../src/helpers.ts"],
|
|
4
|
-
"sourcesContent": ["import { toUint8Array } from 'hex-lite';\nimport { isHex } from '@learncard/helpers';\nimport { JWKWithPrivateKey } from '@learncard/types';\nimport { LearnCard } from '@learncard/core';\n\nimport { getAlgorithmForDidMethod } from './helpers';\n\nimport { DidKeyPlugin, DependentMethods, Algorithm } from './types';\n\nexport * from './types';\n\n/**\n *\n * @group Plugins\n */\nexport const getDidKeyPlugin = async <DidMethod extends string>(\n learnCard: LearnCard<any, any, DependentMethods<DidMethod>>,\n key: string,\n defaultDidMethod: DidMethod\n): Promise<DidKeyPlugin<DidMethod>> => {\n if (key.length === 0) throw new Error(\"Please don't use an empty string for a key!\");\n if (!isHex(key)) throw new Error('Key must be a hexadecimal string!');\n if (key.length > 64) throw new Error('Key must be less than 64 characters');\n\n if (key.length < 64) {\n console.warn(\n 'Warning: A LearnCard has been initialized with a seed that is less than 32 bytes, and will be padded with zeroes'\n );\n console.warn(\n 'Please instantiate LearnCards using 32 bytes that have been randomly generated in a cryptographically secure fashion!'\n );\n console.warn(\n 'See https://app.gitbook.com/o/6uDv1QDlxaaZC7i8EaGb/s/FXvEJ9j3Vf3FW5Nc557n/learn-card-packages/learncard-core/instantiation#key-generation for details'\n );\n }\n\n const seed = key.padStart(64, '0');\n const seedBytes = toUint8Array(seed);\n\n const memoizedDids: Partial<Record<DidMethod, string>> = {};\n const keyPairs: Record<Algorithm, JWKWithPrivateKey> = {\n ed25519: learnCard.invoke.generateEd25519KeyFromBytes(seedBytes),\n secp256k1: learnCard.invoke.generateSecp256k1KeyFromBytes(seedBytes),\n };\n\n const did = (method = defaultDidMethod) => {\n if (!memoizedDids[method]) {\n const algorithm = getAlgorithmForDidMethod(method);\n memoizedDids[method] = learnCard.invoke.keyToDid(method, keyPairs[algorithm]);\n }\n\n return memoizedDids[method]!;\n };\n\n const keypair = (algorithm: Algorithm = 'ed25519') => {\n if (!keyPairs[algorithm]) throw new Error('Unsupported algorithm');\n\n return keyPairs[algorithm];\n };\n\n return {\n name: 'DID Key',\n displayName: 'DID Key',\n description: 'Generates dids and JWKs using 32 Secure Random Bytes of Entropy',\n id: {\n did: (_learnCard, method) => did(method as any),\n keypair: (_learnCard, algorithm) => keypair(algorithm as any),\n },\n methods: {\n getSubjectDid: (_learnCard, method = defaultDidMethod) => did(method),\n getSubjectKeypair: (_learnCard, algorithm = 'ed25519') => keypair(algorithm),\n getKey: () => seed,\n },\n };\n};\n", "function fromUint8Array(uint8Array) {\n return uint8Array.reduce(function (ag, v) { return ag += ('00' + v.toString(16)).slice(-2); }, '');\n}\n\nfunction toUint8Array(str) {\n var s = 0, sl = str.length, bytes = [];\n if (sl % 2) \n { throw new Error('invalid hex:' + str); }\n for (; s < sl; s += 2) {\n bytes.push(parseInt(str.substr(s, 2), 16));\n }\n return new Uint8Array(bytes);\n}\n\nfunction fromBuffer(buffer) {\n return fromUint8Array(new Uint8Array(buffer));\n}\n\nfunction toBuffer(str) {\n return toUint8Array(str).buffer;\n}\n\nexport { fromUint8Array, toUint8Array, fromBuffer, toBuffer };\n//# sourceMappingURL=hex-lite.mjs.map\n", "import { Algorithm } from './types';\n\nexport const ED25519_METHODS = ['key', 'tz', 'pkh:tz', 'pkh:tezos', 'pkh:sol', 'pkh:solana'];\n\nexport const SECP256K1_METHODS = [\n 'key',\n 'tz',\n 'ethr',\n 'pkh:tz',\n 'pkh:tezos',\n 'pkh:eth',\n 'pkh:celo',\n 'pkh:poly',\n 'pkh:btc',\n 'pkh:doge',\n 'pkh:eip155',\n 'pkh:bip122',\n];\n\nexport const getAlgorithmForDidMethod = <DidMethod extends string>(\n didMethod: DidMethod\n): Algorithm => {\n if (ED25519_METHODS.includes(didMethod)) return 'ed25519';\n if (\n SECP256K1_METHODS.includes(didMethod) ||\n didMethod.startsWith('pkh:eip155:') ||\n didMethod.startsWith('pkh:bip122:')\n ) {\n return 'secp256k1';\n }\n\n throw new Error('Unspported Did Method');\n};\n"],
|
|
5
|
-
"mappings": "4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,IAAA,eAAAC,EAAAH,GCIA,SAASI,EAAaC,EAAK,CACvB,IAAIC,EAAI,EAAGC,EAAKF,EAAI,OAAQG,EAAQ,CAAC,EACrC,GAAID,EAAK,EACH,MAAM,IAAI,MAAM,eAAiBF,CAAG,EAC1C,KAAOC,EAAIC,EAAID,GAAK,EAChBE,EAAM,KAAK,SAASH,EAAI,OAAOC,EAAG,CAAC,EAAG,EAAE,CAAC,EAE7C,OAAO,IAAI,WAAWE,CAAK,CAC/B,CARSC,EAAAL,EAAA,gBDHT,IAAAM,EAAsB,8BECf,IAAMC,EAAkB,CAAC,MAAO,KAAM,SAAU,YAAa,UAAW,YAAY,EAE9EC,EAAoB,CAC7B,MACA,KACA,OACA,SACA,YACA,UACA,WACA,WACA,UACA,WACA,aACA,YACJ,EAEaC,EAA2BC,EACpCC,GACY,CACZ,GAAIJ,EAAgB,SAASI,CAAS,EAAG,MAAO,UAChD,GACIH,EAAkB,SAASG,CAAS,GACpCA,EAAU,WAAW,aAAa,GAClCA,EAAU,WAAW,aAAa,EAElC,MAAO,YAGX,MAAM,IAAI,MAAM,uBAAuB,CAC3C,EAbwC,
|
|
6
|
-
"names": ["index_exports", "__export", "getDidKeyPlugin", "__toCommonJS", "toUint8Array", "str", "s", "sl", "bytes", "__name", "import_helpers", "ED25519_METHODS", "SECP256K1_METHODS", "getAlgorithmForDidMethod", "__name", "didMethod", "getDidKeyPlugin", "__name", "learnCard", "key", "defaultDidMethod", "seed", "seedBytes", "toUint8Array", "memoizedDids", "keyPairs", "did", "method", "algorithm", "getAlgorithmForDidMethod", "keypair", "_learnCard"]
|
|
4
|
+
"sourcesContent": ["import { toUint8Array } from 'hex-lite';\nimport { isHex } from '@learncard/helpers';\nimport { JWKWithPrivateKey } from '@learncard/types';\nimport { LearnCard } from '@learncard/core';\n\nimport { getAlgorithmForDidMethod } from './helpers';\n\nimport { DidKeyPlugin, DependentMethods, Algorithm } from './types';\n\nexport * from './types';\n\nlet _shortSeedWarned = false;\n\n/**\n *\n * @group Plugins\n */\nexport const getDidKeyPlugin = async <DidMethod extends string>(\n learnCard: LearnCard<any, any, DependentMethods<DidMethod>>,\n key: string,\n defaultDidMethod: DidMethod\n): Promise<DidKeyPlugin<DidMethod>> => {\n if (key.length === 0) throw new Error(\"Please don't use an empty string for a key!\");\n if (!isHex(key)) throw new Error('Key must be a hexadecimal string!');\n if (key.length > 64) throw new Error('Key must be less than 64 characters');\n\n if (key.length < 64 && !_shortSeedWarned) {\n _shortSeedWarned = true;\n\n console.warn(\n 'Warning: A LearnCard has been initialized with a seed that is less than 32 bytes, and will be padded with zeroes'\n );\n console.warn(\n 'Please instantiate LearnCards using 32 bytes that have been randomly generated in a cryptographically secure fashion!'\n );\n console.warn(\n 'See https://app.gitbook.com/o/6uDv1QDlxaaZC7i8EaGb/s/FXvEJ9j3Vf3FW5Nc557n/learn-card-packages/learncard-core/instantiation#key-generation for details'\n );\n }\n\n const seed = key.padStart(64, '0');\n const seedBytes = toUint8Array(seed);\n\n const memoizedDids: Partial<Record<DidMethod, string>> = {};\n const keyPairs: Record<Algorithm, JWKWithPrivateKey> = {\n ed25519: learnCard.invoke.generateEd25519KeyFromBytes(seedBytes),\n secp256k1: learnCard.invoke.generateSecp256k1KeyFromBytes(seedBytes),\n };\n\n const did = (method = defaultDidMethod) => {\n if (!memoizedDids[method]) {\n const algorithm = getAlgorithmForDidMethod(method);\n memoizedDids[method] = learnCard.invoke.keyToDid(method, keyPairs[algorithm]);\n }\n\n return memoizedDids[method]!;\n };\n\n const keypair = (algorithm: Algorithm = 'ed25519') => {\n if (!keyPairs[algorithm]) throw new Error('Unsupported algorithm');\n\n return keyPairs[algorithm];\n };\n\n return {\n name: 'DID Key',\n displayName: 'DID Key',\n description: 'Generates dids and JWKs using 32 Secure Random Bytes of Entropy',\n id: {\n did: (_learnCard, method) => did(method as any),\n keypair: (_learnCard, algorithm) => keypair(algorithm as any),\n },\n methods: {\n getSubjectDid: (_learnCard, method = defaultDidMethod) => did(method),\n getSubjectKeypair: (_learnCard, algorithm = 'ed25519') => keypair(algorithm),\n getKey: () => seed,\n },\n };\n};\n", "function fromUint8Array(uint8Array) {\n return uint8Array.reduce(function (ag, v) { return ag += ('00' + v.toString(16)).slice(-2); }, '');\n}\n\nfunction toUint8Array(str) {\n var s = 0, sl = str.length, bytes = [];\n if (sl % 2) \n { throw new Error('invalid hex:' + str); }\n for (; s < sl; s += 2) {\n bytes.push(parseInt(str.substr(s, 2), 16));\n }\n return new Uint8Array(bytes);\n}\n\nfunction fromBuffer(buffer) {\n return fromUint8Array(new Uint8Array(buffer));\n}\n\nfunction toBuffer(str) {\n return toUint8Array(str).buffer;\n}\n\nexport { fromUint8Array, toUint8Array, fromBuffer, toBuffer };\n//# sourceMappingURL=hex-lite.mjs.map\n", "import { Algorithm } from './types';\n\nexport const ED25519_METHODS = ['key', 'tz', 'pkh:tz', 'pkh:tezos', 'pkh:sol', 'pkh:solana'];\n\nexport const SECP256K1_METHODS = [\n 'key',\n 'tz',\n 'ethr',\n 'pkh:tz',\n 'pkh:tezos',\n 'pkh:eth',\n 'pkh:celo',\n 'pkh:poly',\n 'pkh:btc',\n 'pkh:doge',\n 'pkh:eip155',\n 'pkh:bip122',\n];\n\nexport const getAlgorithmForDidMethod = <DidMethod extends string>(\n didMethod: DidMethod\n): Algorithm => {\n if (ED25519_METHODS.includes(didMethod)) return 'ed25519';\n if (\n SECP256K1_METHODS.includes(didMethod) ||\n didMethod.startsWith('pkh:eip155:') ||\n didMethod.startsWith('pkh:bip122:')\n ) {\n return 'secp256k1';\n }\n\n throw new Error('Unspported Did Method');\n};\n"],
|
|
5
|
+
"mappings": "4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,IAAA,eAAAC,EAAAH,GCIA,SAASI,EAAaC,EAAK,CACvB,IAAIC,EAAI,EAAGC,EAAKF,EAAI,OAAQG,EAAQ,CAAC,EACrC,GAAID,EAAK,EACH,MAAM,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,EAAYC,EAAyBF,CAAM,EACjDH,EAAaG,CAAM,EAAIT,EAAU,OAAO,SAASS,EAAQF,EAASG,CAAS,CAAC,CAChF,CAEA,OAAOJ,EAAaG,CAAM,CAC9B,EAPY,OASNG,EAAUb,EAAA,CAACW,EAAuB,YAAc,CAClD,GAAI,CAACH,EAASG,CAAS,EAAG,MAAM,IAAI,MAAM,uBAAuB,EAEjE,OAAOH,EAASG,CAAS,CAC7B,EAJgB,WAMhB,MAAO,CACH,KAAM,UACN,YAAa,UACb,YAAa,kEACb,GAAI,CACA,IAAKX,EAAA,CAACc,EAAYJ,IAAWD,EAAIC,CAAa,EAAzC,OACL,QAASV,EAAA,CAACc,EAAYH,IAAcE,EAAQF,CAAgB,EAAnD,UACb,EACA,QAAS,CACL,cAAeX,EAAA,CAACc,EAAYJ,EAASP,IAAqBM,EAAIC,CAAM,EAArD,iBACf,kBAAmBV,EAAA,CAACc,EAAYH,EAAY,YAAcE,EAAQF,CAAS,EAAxD,qBACnB,OAAQX,EAAA,IAAMI,EAAN,SACZ,CACJ,CACJ,EA7D+B",
|
|
6
|
+
"names": ["index_exports", "__export", "getDidKeyPlugin", "__toCommonJS", "toUint8Array", "str", "s", "sl", "bytes", "__name", "import_helpers", "ED25519_METHODS", "SECP256K1_METHODS", "getAlgorithmForDidMethod", "__name", "didMethod", "_shortSeedWarned", "getDidKeyPlugin", "__name", "learnCard", "key", "defaultDidMethod", "seed", "seedBytes", "toUint8Array", "memoizedDids", "keyPairs", "did", "method", "algorithm", "getAlgorithmForDidMethod", "keypair", "_learnCard"]
|
|
7
7
|
}
|
|
@@ -42,11 +42,13 @@ var getAlgorithmForDidMethod = /* @__PURE__ */ __name((didMethod) => {
|
|
|
42
42
|
}, "getAlgorithmForDidMethod");
|
|
43
43
|
|
|
44
44
|
// src/index.ts
|
|
45
|
+
var _shortSeedWarned = false;
|
|
45
46
|
var getDidKeyPlugin = /* @__PURE__ */ __name(async (learnCard, key, defaultDidMethod) => {
|
|
46
47
|
if (key.length === 0) throw new Error("Please don't use an empty string for a key!");
|
|
47
48
|
if (!isHex(key)) throw new Error("Key must be a hexadecimal string!");
|
|
48
49
|
if (key.length > 64) throw new Error("Key must be less than 64 characters");
|
|
49
|
-
if (key.length < 64) {
|
|
50
|
+
if (key.length < 64 && !_shortSeedWarned) {
|
|
51
|
+
_shortSeedWarned = true;
|
|
50
52
|
console.warn(
|
|
51
53
|
"Warning: A LearnCard has been initialized with a seed that is less than 32 bytes, and will be padded with zeroes"
|
|
52
54
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../node_modules/.pnpm/hex-lite@1.5.0/node_modules/hex-lite/dist/hex-lite.mjs", "../src/index.ts", "../src/helpers.ts"],
|
|
4
|
-
"sourcesContent": ["function fromUint8Array(uint8Array) {\n return uint8Array.reduce(function (ag, v) { return ag += ('00' + v.toString(16)).slice(-2); }, '');\n}\n\nfunction toUint8Array(str) {\n var s = 0, sl = str.length, bytes = [];\n if (sl % 2) \n { throw new Error('invalid hex:' + str); }\n for (; s < sl; s += 2) {\n bytes.push(parseInt(str.substr(s, 2), 16));\n }\n return new Uint8Array(bytes);\n}\n\nfunction fromBuffer(buffer) {\n return fromUint8Array(new Uint8Array(buffer));\n}\n\nfunction toBuffer(str) {\n return toUint8Array(str).buffer;\n}\n\nexport { fromUint8Array, toUint8Array, fromBuffer, toBuffer };\n//# sourceMappingURL=hex-lite.mjs.map\n", "import { toUint8Array } from 'hex-lite';\nimport { isHex } from '@learncard/helpers';\nimport { JWKWithPrivateKey } from '@learncard/types';\nimport { LearnCard } from '@learncard/core';\n\nimport { getAlgorithmForDidMethod } from './helpers';\n\nimport { DidKeyPlugin, DependentMethods, Algorithm } from './types';\n\nexport * from './types';\n\n/**\n *\n * @group Plugins\n */\nexport const getDidKeyPlugin = async <DidMethod extends string>(\n learnCard: LearnCard<any, any, DependentMethods<DidMethod>>,\n key: string,\n defaultDidMethod: DidMethod\n): Promise<DidKeyPlugin<DidMethod>> => {\n if (key.length === 0) throw new Error(\"Please don't use an empty string for a key!\");\n if (!isHex(key)) throw new Error('Key must be a hexadecimal string!');\n if (key.length > 64) throw new Error('Key must be less than 64 characters');\n\n if (key.length < 64) {\n console.warn(\n 'Warning: A LearnCard has been initialized with a seed that is less than 32 bytes, and will be padded with zeroes'\n );\n console.warn(\n 'Please instantiate LearnCards using 32 bytes that have been randomly generated in a cryptographically secure fashion!'\n );\n console.warn(\n 'See https://app.gitbook.com/o/6uDv1QDlxaaZC7i8EaGb/s/FXvEJ9j3Vf3FW5Nc557n/learn-card-packages/learncard-core/instantiation#key-generation for details'\n );\n }\n\n const seed = key.padStart(64, '0');\n const seedBytes = toUint8Array(seed);\n\n const memoizedDids: Partial<Record<DidMethod, string>> = {};\n const keyPairs: Record<Algorithm, JWKWithPrivateKey> = {\n ed25519: learnCard.invoke.generateEd25519KeyFromBytes(seedBytes),\n secp256k1: learnCard.invoke.generateSecp256k1KeyFromBytes(seedBytes),\n };\n\n const did = (method = defaultDidMethod) => {\n if (!memoizedDids[method]) {\n const algorithm = getAlgorithmForDidMethod(method);\n memoizedDids[method] = learnCard.invoke.keyToDid(method, keyPairs[algorithm]);\n }\n\n return memoizedDids[method]!;\n };\n\n const keypair = (algorithm: Algorithm = 'ed25519') => {\n if (!keyPairs[algorithm]) throw new Error('Unsupported algorithm');\n\n return keyPairs[algorithm];\n };\n\n return {\n name: 'DID Key',\n displayName: 'DID Key',\n description: 'Generates dids and JWKs using 32 Secure Random Bytes of Entropy',\n id: {\n did: (_learnCard, method) => did(method as any),\n keypair: (_learnCard, algorithm) => keypair(algorithm as any),\n },\n methods: {\n getSubjectDid: (_learnCard, method = defaultDidMethod) => did(method),\n getSubjectKeypair: (_learnCard, algorithm = 'ed25519') => keypair(algorithm),\n getKey: () => seed,\n },\n };\n};\n", "import { Algorithm } from './types';\n\nexport const ED25519_METHODS = ['key', 'tz', 'pkh:tz', 'pkh:tezos', 'pkh:sol', 'pkh:solana'];\n\nexport const SECP256K1_METHODS = [\n 'key',\n 'tz',\n 'ethr',\n 'pkh:tz',\n 'pkh:tezos',\n 'pkh:eth',\n 'pkh:celo',\n 'pkh:poly',\n 'pkh:btc',\n 'pkh:doge',\n 'pkh:eip155',\n 'pkh:bip122',\n];\n\nexport const getAlgorithmForDidMethod = <DidMethod extends string>(\n didMethod: DidMethod\n): Algorithm => {\n if (ED25519_METHODS.includes(didMethod)) return 'ed25519';\n if (\n SECP256K1_METHODS.includes(didMethod) ||\n didMethod.startsWith('pkh:eip155:') ||\n didMethod.startsWith('pkh:bip122:')\n ) {\n return 'secp256k1';\n }\n\n throw new Error('Unspported Did Method');\n};\n"],
|
|
5
|
-
"mappings": ";;;;AAIA,SAAS,aAAa,KAAK;AACvB,MAAI,IAAI,GAAG,KAAK,IAAI,QAAQ,QAAQ,CAAC;AACrC,MAAI,KAAK,GACL;AAAE,UAAM,IAAI,MAAM,iBAAiB,GAAG;AAAA,EAAG;AAC7C,SAAO,IAAI,IAAI,KAAK,GAAG;AACnB,UAAM,KAAK,SAAS,IAAI,OAAO,GAAG,CAAC,GAAG,EAAE,CAAC;AAAA,EAC7C;AACA,SAAO,IAAI,WAAW,KAAK;AAC/B;AARS;;;ACHT,SAAS,aAAa;;;ACCf,IAAM,kBAAkB,CAAC,OAAO,MAAM,UAAU,aAAa,WAAW,YAAY;AAEpF,IAAM,oBAAoB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAEO,IAAM,2BAA2B,wBACpC,cACY;AACZ,MAAI,gBAAgB,SAAS,SAAS,EAAG,QAAO;AAChD,MACI,kBAAkB,SAAS,SAAS,KACpC,UAAU,WAAW,aAAa,KAClC,UAAU,WAAW,aAAa,GACpC;AACE,WAAO;AAAA,EACX;AAEA,QAAM,IAAI,MAAM,uBAAuB;AAC3C,GAbwC;;;
|
|
4
|
+
"sourcesContent": ["function fromUint8Array(uint8Array) {\n return uint8Array.reduce(function (ag, v) { return ag += ('00' + v.toString(16)).slice(-2); }, '');\n}\n\nfunction toUint8Array(str) {\n var s = 0, sl = str.length, bytes = [];\n if (sl % 2) \n { throw new Error('invalid hex:' + str); }\n for (; s < sl; s += 2) {\n bytes.push(parseInt(str.substr(s, 2), 16));\n }\n return new Uint8Array(bytes);\n}\n\nfunction fromBuffer(buffer) {\n return fromUint8Array(new Uint8Array(buffer));\n}\n\nfunction toBuffer(str) {\n return toUint8Array(str).buffer;\n}\n\nexport { fromUint8Array, toUint8Array, fromBuffer, toBuffer };\n//# sourceMappingURL=hex-lite.mjs.map\n", "import { toUint8Array } from 'hex-lite';\nimport { isHex } from '@learncard/helpers';\nimport { JWKWithPrivateKey } from '@learncard/types';\nimport { LearnCard } from '@learncard/core';\n\nimport { getAlgorithmForDidMethod } from './helpers';\n\nimport { DidKeyPlugin, DependentMethods, Algorithm } from './types';\n\nexport * from './types';\n\nlet _shortSeedWarned = false;\n\n/**\n *\n * @group Plugins\n */\nexport const getDidKeyPlugin = async <DidMethod extends string>(\n learnCard: LearnCard<any, any, DependentMethods<DidMethod>>,\n key: string,\n defaultDidMethod: DidMethod\n): Promise<DidKeyPlugin<DidMethod>> => {\n if (key.length === 0) throw new Error(\"Please don't use an empty string for a key!\");\n if (!isHex(key)) throw new Error('Key must be a hexadecimal string!');\n if (key.length > 64) throw new Error('Key must be less than 64 characters');\n\n if (key.length < 64 && !_shortSeedWarned) {\n _shortSeedWarned = true;\n\n console.warn(\n 'Warning: A LearnCard has been initialized with a seed that is less than 32 bytes, and will be padded with zeroes'\n );\n console.warn(\n 'Please instantiate LearnCards using 32 bytes that have been randomly generated in a cryptographically secure fashion!'\n );\n console.warn(\n 'See https://app.gitbook.com/o/6uDv1QDlxaaZC7i8EaGb/s/FXvEJ9j3Vf3FW5Nc557n/learn-card-packages/learncard-core/instantiation#key-generation for details'\n );\n }\n\n const seed = key.padStart(64, '0');\n const seedBytes = toUint8Array(seed);\n\n const memoizedDids: Partial<Record<DidMethod, string>> = {};\n const keyPairs: Record<Algorithm, JWKWithPrivateKey> = {\n ed25519: learnCard.invoke.generateEd25519KeyFromBytes(seedBytes),\n secp256k1: learnCard.invoke.generateSecp256k1KeyFromBytes(seedBytes),\n };\n\n const did = (method = defaultDidMethod) => {\n if (!memoizedDids[method]) {\n const algorithm = getAlgorithmForDidMethod(method);\n memoizedDids[method] = learnCard.invoke.keyToDid(method, keyPairs[algorithm]);\n }\n\n return memoizedDids[method]!;\n };\n\n const keypair = (algorithm: Algorithm = 'ed25519') => {\n if (!keyPairs[algorithm]) throw new Error('Unsupported algorithm');\n\n return keyPairs[algorithm];\n };\n\n return {\n name: 'DID Key',\n displayName: 'DID Key',\n description: 'Generates dids and JWKs using 32 Secure Random Bytes of Entropy',\n id: {\n did: (_learnCard, method) => did(method as any),\n keypair: (_learnCard, algorithm) => keypair(algorithm as any),\n },\n methods: {\n getSubjectDid: (_learnCard, method = defaultDidMethod) => did(method),\n getSubjectKeypair: (_learnCard, algorithm = 'ed25519') => keypair(algorithm),\n getKey: () => seed,\n },\n };\n};\n", "import { Algorithm } from './types';\n\nexport const ED25519_METHODS = ['key', 'tz', 'pkh:tz', 'pkh:tezos', 'pkh:sol', 'pkh:solana'];\n\nexport const SECP256K1_METHODS = [\n 'key',\n 'tz',\n 'ethr',\n 'pkh:tz',\n 'pkh:tezos',\n 'pkh:eth',\n 'pkh:celo',\n 'pkh:poly',\n 'pkh:btc',\n 'pkh:doge',\n 'pkh:eip155',\n 'pkh:bip122',\n];\n\nexport const getAlgorithmForDidMethod = <DidMethod extends string>(\n didMethod: DidMethod\n): Algorithm => {\n if (ED25519_METHODS.includes(didMethod)) return 'ed25519';\n if (\n SECP256K1_METHODS.includes(didMethod) ||\n didMethod.startsWith('pkh:eip155:') ||\n didMethod.startsWith('pkh:bip122:')\n ) {\n return 'secp256k1';\n }\n\n thro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,EAAE,MAAM,iBAAiB,CAAC;AAI5C,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAa,MAAM,SAAS,CAAC;AAEpE,cAAc,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAa,MAAM,SAAS,CAAC;AAEpE,cAAc,SAAS,CAAC;AAIxB;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAU,SAAS,SAAS,MAAM,aAC/C,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC,OACtD,MAAM,oBACO,SAAS,KAC5B,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,CAyDjC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@learncard/didkey-plugin",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.12",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/didkey-plugin.esm.js",
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
"jest": "^29.3.0",
|
|
28
28
|
"shx": "^0.3.4",
|
|
29
29
|
"ts-jest": "^29.0.3",
|
|
30
|
-
"@learncard/types": "5.
|
|
30
|
+
"@learncard/types": "5.13.2"
|
|
31
31
|
},
|
|
32
32
|
"types": "./dist/index.d.ts",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"hex-lite": "^1.5.0",
|
|
35
|
-
"@learncard/helpers": "^1.2.
|
|
36
|
-
"@learncard/core": "9.4.
|
|
35
|
+
"@learncard/helpers": "^1.2.12",
|
|
36
|
+
"@learncard/core": "9.4.12"
|
|
37
37
|
},
|
|
38
38
|
"sideEffects": false,
|
|
39
39
|
"scripts": {
|