@learncard/didkey-plugin 1.1.24 → 1.1.26
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/README.md +12 -7
- package/dist/didkey-plugin.cjs.development.cjs +1 -1
- package/dist/didkey-plugin.cjs.development.cjs.map +1 -1
- package/dist/didkey-plugin.cjs.production.min.cjs.map +1 -1
- package/dist/didkey-plugin.esm.js +1 -1
- package/dist/didkey-plugin.esm.js.map +1 -1
- package/package.json +59 -57
- package/src/global.d.ts +6 -0
- package/src/helpers.ts +33 -0
- package/src/index.ts +79 -0
- package/src/types.ts +28 -0
package/README.md
CHANGED
|
@@ -9,25 +9,26 @@
|
|
|
9
9
|
The LearnCard Core is a pluggable, open-source, universal digital wallet to enable any individual or organization to seamlessly **issue, earn, store, share, and spend currency and credentials** built for the future of education and work.
|
|
10
10
|
|
|
11
11
|
## Documentation
|
|
12
|
+
|
|
12
13
|
All LearnCard documentation can be found at:
|
|
13
14
|
https://docs.learncard.com
|
|
14
15
|
|
|
15
16
|
## Install
|
|
16
17
|
|
|
17
18
|
```bash
|
|
18
|
-
|
|
19
|
+
bun add @learncard/core
|
|
19
20
|
```
|
|
20
21
|
|
|
21
22
|
## Usage
|
|
22
23
|
|
|
23
24
|
### Instantiation
|
|
24
25
|
|
|
25
|
-
Instantiate a wallet using `initLearnCard`. This method accepts a unique identifier string that is
|
|
26
|
+
Instantiate a wallet using `initLearnCard`. This method accepts a unique identifier string that is
|
|
26
27
|
up to 64 characters long. If it is less than 64 characters, `initLearnCard` will pad the start of
|
|
27
28
|
the string with 0's until it is 64 characters long.
|
|
28
29
|
|
|
29
30
|
```js
|
|
30
|
-
import { initLearnCard } from
|
|
31
|
+
import { initLearnCard } from '@learncard/core';
|
|
31
32
|
|
|
32
33
|
const wallet = await initLearnCard({ seed: 'a'.repeat(64) });
|
|
33
34
|
```
|
|
@@ -35,6 +36,7 @@ const wallet = await initLearnCard({ seed: 'a'.repeat(64) });
|
|
|
35
36
|
### Issuing/Verifying Credentials and Presentations
|
|
36
37
|
|
|
37
38
|
#### Issue a credential
|
|
39
|
+
|
|
38
40
|
```js
|
|
39
41
|
// Grab a test VC, or create your own!
|
|
40
42
|
const unsignedVc = await wallet.invoke.getTestVc();
|
|
@@ -43,6 +45,7 @@ const vc = await wallet.invoke.issueCredential(unsignedVc);
|
|
|
43
45
|
```
|
|
44
46
|
|
|
45
47
|
#### Verify a credential
|
|
48
|
+
|
|
46
49
|
```js
|
|
47
50
|
const result = await wallet.invoke.verifyCredential(vc, {}, true);
|
|
48
51
|
|
|
@@ -53,11 +56,13 @@ else console.log('This credential is valid!');
|
|
|
53
56
|
```
|
|
54
57
|
|
|
55
58
|
#### Issue a presentation
|
|
59
|
+
|
|
56
60
|
```js
|
|
57
61
|
const vp = await wallet.invoke.issuePresentation(vc);
|
|
58
62
|
```
|
|
59
63
|
|
|
60
64
|
#### Verify a presentation
|
|
65
|
+
|
|
61
66
|
```js
|
|
62
67
|
const result = await wallet.invoke.verifyPresentation(vp);
|
|
63
68
|
|
|
@@ -74,14 +79,14 @@ else console.log('This presentation is valid!');
|
|
|
74
79
|
To maintain co-ownership of credentials, it is best to store credentials in a public place, and then
|
|
75
80
|
store references to that public place. While this is not the only way to store credentials (and is
|
|
76
81
|
also definitely not a silver bullet! E.g. credentials containing private data), it is the opinion of
|
|
77
|
-
this library that it should be used by default. As a result, instantiating a wallet, will
|
|
78
|
-
automatically connect you to WeLibrary's ceramic node, and allow you to publish and retrieve
|
|
82
|
+
this library that it should be used by default. As a result, instantiating a wallet, will
|
|
83
|
+
automatically connect you to WeLibrary's ceramic node, and allow you to publish and retrieve
|
|
79
84
|
credentials there using IDX.
|
|
80
85
|
|
|
81
86
|
#### Publish Credential
|
|
82
87
|
|
|
83
88
|
After signing a VC, you may choose to publish that credential to Ceramic. Doing so will return a
|
|
84
|
-
stream ID, which you may share to the recipient. That stream ID can then be used to resolve the
|
|
89
|
+
stream ID, which you may share to the recipient. That stream ID can then be used to resolve the
|
|
85
90
|
issued credential. This means both the issuer and recipient may store the _stream ID_ instead of the
|
|
86
91
|
credential itself.
|
|
87
92
|
|
|
@@ -126,6 +131,7 @@ const vcs = await Promise.all(uris.map(async uri => wallet.read.get(uri)));
|
|
|
126
131
|
```
|
|
127
132
|
|
|
128
133
|
## Contributing
|
|
134
|
+
|
|
129
135
|
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
|
130
136
|
|
|
131
137
|
Please make sure to update tests as appropriate.
|
|
@@ -134,7 +140,6 @@ Please make sure to update tests as appropriate.
|
|
|
134
140
|
|
|
135
141
|
**[Learning Economy Foundation (LEF)](https://www.learningeconomy.io)** is a 501(c)(3) non-profit organization leveraging global standards and web3 protocols to bring quality skills and equal opportunity to every human on earth, and address the persistent inequities that exist around the globe in education and employment. We help you build the future of education and work with:
|
|
136
142
|
|
|
137
|
-
|
|
138
143
|
## License
|
|
139
144
|
|
|
140
145
|
MIT © [Learning Economy Foundation](https://github.com/Learning-Economy-Foundation)
|
|
@@ -25,7 +25,7 @@ __export(index_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
27
|
|
|
28
|
-
// ../../../node_modules
|
|
28
|
+
// ../../../node_modules/hex-lite/dist/hex-lite.mjs
|
|
29
29
|
function toUint8Array(str) {
|
|
30
30
|
var s = 0, sl = str.length, bytes = [];
|
|
31
31
|
if (sl % 2) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts", "../../../../node_modules
|
|
3
|
+
"sources": ["../src/index.ts", "../../../../node_modules/hex-lite/dist/hex-lite.mjs", "../src/helpers.ts"],
|
|
4
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
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIA,SAAS,aAAa,KAAK;AACvB,MAAI,IAAI,GAAG,KAAK,IAAI,QAAQ,QAAQ,CAAC;A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AC1D,QAAM,WAAiD;AAAA,IACnD,SAAS,UAAU,OAAO,4BAA4B,SAAS;AAAA,IAC/D,WAAW,UAAU,OAAO,8BAA8B,SAAS;AAAA,EACvE;AAEA,QAAM,MAAM,wBAAC,SAAS,qBAAqB;AACvC,QAAI,CAAC,aAAa,MAAM,GAAG;AACvB,YAAM,YAAY,yBAAyB,MAAM;AACjD,mBAAa,MAAM,IAAI,UAAU,OAAO,SAAS,QAAQ,SAAS,SAAS,CAAC;AAAA,IAChF;AAEA,WAAO,aAAa,MAAM;AAAA,EAC9B,GAPY;AASZ,QAAM,UAAU,wBAAC,YAAuB,cAAc;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": []
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts", "../../../../node_modules
|
|
3
|
+
"sources": ["../src/index.ts", "../../../../node_modules/hex-lite/dist/hex-lite.mjs", "../src/helpers.ts"],
|
|
4
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
5
|
"mappings": "4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,IAAA,eAAAC,EAAAH,GCIA,SAASI,EAAa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S,CACvE,EAEMI,EAAMT,EAAA,CAACU,EAASP,IAAqB,CACvC,GAAI,CAACI,EAAaG,CAAM,EAAG,CACvB,IAAMC,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
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"]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
|
-
// ../../../node_modules
|
|
4
|
+
// ../../../node_modules/hex-lite/dist/hex-lite.mjs
|
|
5
5
|
function toUint8Array(str) {
|
|
6
6
|
var s = 0, sl = str.length, bytes = [];
|
|
7
7
|
if (sl % 2) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../../node_modules
|
|
3
|
+
"sources": ["../../../../node_modules/hex-lite/dist/hex-lite.mjs", "../src/index.ts", "../src/helpers.ts"],
|
|
4
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 throw new Error('Unspported Did Method');\n};\n"],
|
|
5
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;;;ADRxC,IAAI,mBAAmB;AAMhB,IAAM,kBAAkB,8BAC3B,WACA,KACA,qBACmC;AACnC,MAAI,IAAI,WAAW,EAAG,OAAM,IAAI,MAAM,6CAA6C;AACnF,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SAAS,GAAxD;AAAA,MACnB,QAAQ,6BAAM,MAAN;AAAA,IACZ;AAAA,EACJ;AACJ,GA7D+B;",
|
|
6
6
|
"names": []
|
package/package.json
CHANGED
|
@@ -1,58 +1,60 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
2
|
+
"name": "@learncard/didkey-plugin",
|
|
3
|
+
"version": "1.1.26",
|
|
4
|
+
"description": "",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/didkey-plugin.esm.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"development": "./src/index.ts",
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/didkey-plugin.esm.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"src"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "node ./scripts/build.mjs && shx cp ./scripts/mixedEntypoint.js ./dist/index.cjs && tsc --p tsconfig.json && shx cp ./dist/index.d.ts ./dist/index.d.cts",
|
|
27
|
+
"test": "jest --passWithNoTests",
|
|
28
|
+
"test:watch": "jest --watch",
|
|
29
|
+
"test:coverage": "jest --silent --ci --coverage --coverageReporters=\"text\" --coverageReporters=\"text-summary\""
|
|
30
|
+
},
|
|
31
|
+
"author": "Learning Economy Foundation (www.learningeconomy.io)",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"homepage": "https://github.com/learningeconomy/LearnCard/tree/main/packages/plugins/didkey/README.md",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/learningeconomy/LearnCard"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/learningeconomy/LearnCard/issues"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@learncard/types": "5.17.5",
|
|
43
|
+
"@types/jest": "^29.2.2",
|
|
44
|
+
"@types/node": "^17.0.31",
|
|
45
|
+
"aqu": "0.4.3",
|
|
46
|
+
"esbuild": "^0.27.1",
|
|
47
|
+
"esbuild-jest": "^0.5.0",
|
|
48
|
+
"esbuild-plugin-copy": "^1.3.0",
|
|
49
|
+
"jest": "^29.3.0",
|
|
50
|
+
"shx": "^0.3.4",
|
|
51
|
+
"ts-jest": "^29.0.3"
|
|
52
|
+
},
|
|
53
|
+
"types": "./dist/index.d.ts",
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@learncard/core": "9.4.26",
|
|
56
|
+
"@learncard/helpers": "^1.3.8",
|
|
57
|
+
"hex-lite": "^1.5.0"
|
|
58
|
+
},
|
|
59
|
+
"sideEffects": false
|
|
60
|
+
}
|
package/src/global.d.ts
ADDED
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Algorithm } from './types';
|
|
2
|
+
|
|
3
|
+
export const ED25519_METHODS = ['key', 'tz', 'pkh:tz', 'pkh:tezos', 'pkh:sol', 'pkh:solana'];
|
|
4
|
+
|
|
5
|
+
export const SECP256K1_METHODS = [
|
|
6
|
+
'key',
|
|
7
|
+
'tz',
|
|
8
|
+
'ethr',
|
|
9
|
+
'pkh:tz',
|
|
10
|
+
'pkh:tezos',
|
|
11
|
+
'pkh:eth',
|
|
12
|
+
'pkh:celo',
|
|
13
|
+
'pkh:poly',
|
|
14
|
+
'pkh:btc',
|
|
15
|
+
'pkh:doge',
|
|
16
|
+
'pkh:eip155',
|
|
17
|
+
'pkh:bip122',
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
export const getAlgorithmForDidMethod = <DidMethod extends string>(
|
|
21
|
+
didMethod: DidMethod
|
|
22
|
+
): Algorithm => {
|
|
23
|
+
if (ED25519_METHODS.includes(didMethod)) return 'ed25519';
|
|
24
|
+
if (
|
|
25
|
+
SECP256K1_METHODS.includes(didMethod) ||
|
|
26
|
+
didMethod.startsWith('pkh:eip155:') ||
|
|
27
|
+
didMethod.startsWith('pkh:bip122:')
|
|
28
|
+
) {
|
|
29
|
+
return 'secp256k1';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
throw new Error('Unspported Did Method');
|
|
33
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { toUint8Array } from 'hex-lite';
|
|
2
|
+
import { isHex } from '@learncard/helpers';
|
|
3
|
+
import { JWKWithPrivateKey } from '@learncard/types';
|
|
4
|
+
import { LearnCard } from '@learncard/core';
|
|
5
|
+
|
|
6
|
+
import { getAlgorithmForDidMethod } from './helpers';
|
|
7
|
+
|
|
8
|
+
import { DidKeyPlugin, DependentMethods, Algorithm } from './types';
|
|
9
|
+
|
|
10
|
+
export * from './types';
|
|
11
|
+
|
|
12
|
+
let _shortSeedWarned = false;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @group Plugins
|
|
17
|
+
*/
|
|
18
|
+
export const getDidKeyPlugin = async <DidMethod extends string>(
|
|
19
|
+
learnCard: LearnCard<any, any, DependentMethods<DidMethod>>,
|
|
20
|
+
key: string,
|
|
21
|
+
defaultDidMethod: DidMethod
|
|
22
|
+
): Promise<DidKeyPlugin<DidMethod>> => {
|
|
23
|
+
if (key.length === 0) throw new Error("Please don't use an empty string for a key!");
|
|
24
|
+
if (!isHex(key)) throw new Error('Key must be a hexadecimal string!');
|
|
25
|
+
if (key.length > 64) throw new Error('Key must be less than 64 characters');
|
|
26
|
+
|
|
27
|
+
if (key.length < 64 && !_shortSeedWarned) {
|
|
28
|
+
_shortSeedWarned = true;
|
|
29
|
+
|
|
30
|
+
console.warn(
|
|
31
|
+
'Warning: A LearnCard has been initialized with a seed that is less than 32 bytes, and will be padded with zeroes'
|
|
32
|
+
);
|
|
33
|
+
console.warn(
|
|
34
|
+
'Please instantiate LearnCards using 32 bytes that have been randomly generated in a cryptographically secure fashion!'
|
|
35
|
+
);
|
|
36
|
+
console.warn(
|
|
37
|
+
'See https://app.gitbook.com/o/6uDv1QDlxaaZC7i8EaGb/s/FXvEJ9j3Vf3FW5Nc557n/learn-card-packages/learncard-core/instantiation#key-generation for details'
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const seed = key.padStart(64, '0');
|
|
42
|
+
const seedBytes = toUint8Array(seed);
|
|
43
|
+
|
|
44
|
+
const memoizedDids: Partial<Record<DidMethod, string>> = {};
|
|
45
|
+
const keyPairs: Record<Algorithm, JWKWithPrivateKey> = {
|
|
46
|
+
ed25519: learnCard.invoke.generateEd25519KeyFromBytes(seedBytes),
|
|
47
|
+
secp256k1: learnCard.invoke.generateSecp256k1KeyFromBytes(seedBytes),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const did = (method = defaultDidMethod) => {
|
|
51
|
+
if (!memoizedDids[method]) {
|
|
52
|
+
const algorithm = getAlgorithmForDidMethod(method);
|
|
53
|
+
memoizedDids[method] = learnCard.invoke.keyToDid(method, keyPairs[algorithm]);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return memoizedDids[method]!;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const keypair = (algorithm: Algorithm = 'ed25519') => {
|
|
60
|
+
if (!keyPairs[algorithm]) throw new Error('Unsupported algorithm');
|
|
61
|
+
|
|
62
|
+
return keyPairs[algorithm];
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
name: 'DID Key',
|
|
67
|
+
displayName: 'DID Key',
|
|
68
|
+
description: 'Generates dids and JWKs using 32 Secure Random Bytes of Entropy',
|
|
69
|
+
id: {
|
|
70
|
+
did: (_learnCard, method) => did(method as any),
|
|
71
|
+
keypair: (_learnCard, algorithm) => keypair(algorithm as any),
|
|
72
|
+
},
|
|
73
|
+
methods: {
|
|
74
|
+
getSubjectDid: (_learnCard, method = defaultDidMethod) => did(method),
|
|
75
|
+
getSubjectKeypair: (_learnCard, algorithm = 'ed25519') => keypair(algorithm),
|
|
76
|
+
getKey: () => seed,
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Plugin } from '@learncard/core';
|
|
2
|
+
import { JWKWithPrivateKey } from '@learncard/types';
|
|
3
|
+
|
|
4
|
+
/** @group DidKey Plugin */
|
|
5
|
+
export type Algorithm = 'ed25519' | 'secp256k1';
|
|
6
|
+
|
|
7
|
+
/** @group DidKey Plugin */
|
|
8
|
+
export type DependentMethods<DidMethod extends string> = {
|
|
9
|
+
generateEd25519KeyFromBytes: (bytes: Uint8Array) => JWKWithPrivateKey;
|
|
10
|
+
generateSecp256k1KeyFromBytes: (bytes: Uint8Array) => JWKWithPrivateKey;
|
|
11
|
+
keyToDid: (method: DidMethod, keypair: JWKWithPrivateKey) => string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/** @group DidKey Plugin */
|
|
15
|
+
export type DidKeyPluginMethods<DidMethod extends string> = {
|
|
16
|
+
getSubjectDid: (method?: DidMethod) => string;
|
|
17
|
+
getSubjectKeypair: (algorithm?: Algorithm) => JWKWithPrivateKey;
|
|
18
|
+
getKey: () => string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** @group DidKey Plugin */
|
|
22
|
+
export type DidKeyPlugin<DidMethod extends string = string> = Plugin<
|
|
23
|
+
'DID Key',
|
|
24
|
+
'id',
|
|
25
|
+
DidKeyPluginMethods<DidMethod>,
|
|
26
|
+
any,
|
|
27
|
+
DependentMethods<DidMethod>
|
|
28
|
+
>;
|