@didcid/keymaster 0.3.10 → 0.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/cjs/index.cjs +0 -1
- package/dist/cjs/keymaster-client.cjs +74 -2
- package/dist/cjs/keymaster.cjs +1949 -206
- package/dist/cjs/node.cjs +0 -1
- package/dist/esm/cli.js +111 -7
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/keymaster-client.js +74 -2
- package/dist/esm/keymaster-client.js.map +1 -1
- package/dist/esm/keymaster.js +374 -206
- package/dist/esm/keymaster.js.map +1 -1
- package/dist/types/keymaster-client.d.ts +12 -5
- package/dist/types/keymaster.d.ts +17 -5
- package/dist/types/types.d.ts +24 -17
- package/package.json +4 -12
- package/dist/cjs/encryption.cjs +0 -59
- package/dist/esm/encryption.js +0 -55
- package/dist/esm/encryption.js.map +0 -1
- package/dist/types/encryption.d.ts +0 -10
package/dist/types/types.d.ts
CHANGED
|
@@ -115,11 +115,10 @@ export interface PollResults {
|
|
|
115
115
|
count: number;
|
|
116
116
|
}>;
|
|
117
117
|
ballots?: Array<{
|
|
118
|
-
ballot: string;
|
|
119
|
-
received: string;
|
|
120
118
|
voter: string;
|
|
121
119
|
vote: number;
|
|
122
120
|
option: string;
|
|
121
|
+
received: string;
|
|
123
122
|
}>;
|
|
124
123
|
votes?: {
|
|
125
124
|
eligible: number;
|
|
@@ -128,18 +127,12 @@ export interface PollResults {
|
|
|
128
127
|
};
|
|
129
128
|
final?: boolean;
|
|
130
129
|
}
|
|
131
|
-
export interface
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
export interface PollConfig {
|
|
131
|
+
version: 2;
|
|
132
|
+
name: string;
|
|
134
133
|
description: string;
|
|
135
|
-
roster: string;
|
|
136
134
|
options: string[];
|
|
137
135
|
deadline: string;
|
|
138
|
-
ballots?: Record<string, {
|
|
139
|
-
ballot: string;
|
|
140
|
-
received: string;
|
|
141
|
-
}>;
|
|
142
|
-
results?: PollResults;
|
|
143
136
|
}
|
|
144
137
|
export interface ViewPollResult {
|
|
145
138
|
description: string;
|
|
@@ -149,8 +142,15 @@ export interface ViewPollResult {
|
|
|
149
142
|
isEligible: boolean;
|
|
150
143
|
voteExpired: boolean;
|
|
151
144
|
hasVoted: boolean;
|
|
145
|
+
ballots?: string[];
|
|
152
146
|
results?: PollResults;
|
|
153
147
|
}
|
|
148
|
+
export interface ViewBallotResult {
|
|
149
|
+
poll: string;
|
|
150
|
+
voter?: string;
|
|
151
|
+
vote?: number;
|
|
152
|
+
option?: string;
|
|
153
|
+
}
|
|
154
154
|
export interface BinaryAsset {
|
|
155
155
|
cid: string;
|
|
156
156
|
type: string;
|
|
@@ -202,8 +202,8 @@ export interface KeymasterOptions {
|
|
|
202
202
|
maxAliasLength?: number;
|
|
203
203
|
}
|
|
204
204
|
export interface EncryptedMessage {
|
|
205
|
-
sender
|
|
206
|
-
created
|
|
205
|
+
sender?: string;
|
|
206
|
+
created?: string;
|
|
207
207
|
cipher_hash?: string | null;
|
|
208
208
|
cipher_sender?: string | null;
|
|
209
209
|
cipher_receiver?: string | null;
|
|
@@ -324,20 +324,27 @@ export interface KeymasterInterface {
|
|
|
324
324
|
retries?: number;
|
|
325
325
|
delay?: number;
|
|
326
326
|
}): Promise<ChallengeResponse>;
|
|
327
|
-
pollTemplate(): Promise<
|
|
328
|
-
createPoll(
|
|
329
|
-
getPoll(pollId: string): Promise<
|
|
327
|
+
pollTemplate(): Promise<PollConfig>;
|
|
328
|
+
createPoll(config: PollConfig, options?: VaultOptions): Promise<string>;
|
|
329
|
+
getPoll(pollId: string): Promise<PollConfig | null>;
|
|
330
|
+
testPoll(id: string): Promise<boolean>;
|
|
331
|
+
listPolls(owner?: string): Promise<string[]>;
|
|
330
332
|
viewPoll(pollId: string): Promise<ViewPollResult>;
|
|
331
333
|
votePoll(pollId: string, vote: number, options?: {
|
|
332
|
-
spoil?: boolean;
|
|
333
334
|
registry?: string;
|
|
334
335
|
validUntil?: string;
|
|
335
336
|
}): Promise<string>;
|
|
337
|
+
sendPoll(pollId: string): Promise<string>;
|
|
338
|
+
sendBallot(ballotDid: string, pollId: string): Promise<string>;
|
|
339
|
+
viewBallot(ballotDid: string): Promise<ViewBallotResult>;
|
|
336
340
|
updatePoll(ballot: string): Promise<boolean>;
|
|
337
341
|
publishPoll(pollId: string, options?: {
|
|
338
342
|
reveal?: boolean;
|
|
339
343
|
}): Promise<boolean>;
|
|
340
344
|
unpublishPoll(pollId: string): Promise<boolean>;
|
|
345
|
+
addPollVoter(pollId: string, memberId: string): Promise<boolean>;
|
|
346
|
+
removePollVoter(pollId: string, memberId: string): Promise<boolean>;
|
|
347
|
+
listPollVoters(pollId: string): Promise<Record<string, any>>;
|
|
341
348
|
createImage(data: Buffer, options?: FileAssetOptions): Promise<string>;
|
|
342
349
|
updateImage(did: string, data: Buffer, options?: FileAssetOptions): Promise<boolean>;
|
|
343
350
|
getImage(id: string): Promise<ImageFileAsset | null>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@didcid/keymaster",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Archon Keymaster",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -37,11 +37,6 @@
|
|
|
37
37
|
"require": "./dist/cjs/keymaster-client.cjs",
|
|
38
38
|
"types": "./dist/types/keymaster-client.d.ts"
|
|
39
39
|
},
|
|
40
|
-
"./encryption": {
|
|
41
|
-
"import": "./dist/esm/encryption.js",
|
|
42
|
-
"require": "./dist/cjs/encryption.cjs",
|
|
43
|
-
"types": "./dist/types/encryption.d.ts"
|
|
44
|
-
},
|
|
45
40
|
"./wallet/json": {
|
|
46
41
|
"import": "./dist/esm/db/json.js",
|
|
47
42
|
"require": "./dist/cjs/db/json.cjs",
|
|
@@ -101,9 +96,6 @@
|
|
|
101
96
|
"client": [
|
|
102
97
|
"./dist/types/keymaster-client.d.ts"
|
|
103
98
|
],
|
|
104
|
-
"encryption": [
|
|
105
|
-
"./dist/types/encryption.d.ts"
|
|
106
|
-
],
|
|
107
99
|
"wallet/json": [
|
|
108
100
|
"./dist/types/db/json.d.ts"
|
|
109
101
|
],
|
|
@@ -149,9 +141,9 @@
|
|
|
149
141
|
"author": "David McFadzean <davidmc@gmail.com>",
|
|
150
142
|
"license": "MIT",
|
|
151
143
|
"dependencies": {
|
|
152
|
-
"@didcid/cipher": "^0.
|
|
144
|
+
"@didcid/cipher": "^0.2.0",
|
|
153
145
|
"@didcid/common": "^0.1.3",
|
|
154
|
-
"@didcid/gatekeeper": "^0.
|
|
146
|
+
"@didcid/gatekeeper": "^0.4.0",
|
|
155
147
|
"axios": "^1.7.7",
|
|
156
148
|
"commander": "^11.1.0",
|
|
157
149
|
"dotenv": "^16.4.5",
|
|
@@ -166,5 +158,5 @@
|
|
|
166
158
|
"type": "git",
|
|
167
159
|
"url": "git+https://github.com/archetech/archon.git"
|
|
168
160
|
},
|
|
169
|
-
"gitHead": "
|
|
161
|
+
"gitHead": "4692cc18e1377cafc96aaf7a55cd969a0b09b77c"
|
|
170
162
|
}
|
package/dist/cjs/encryption.cjs
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const ENC_ALG = 'AES-GCM';
|
|
4
|
-
const ENC_KDF = 'PBKDF2';
|
|
5
|
-
const ENC_HASH = 'SHA-512';
|
|
6
|
-
const ENC_ITER_DEFAULT = 100_000;
|
|
7
|
-
const IV_LEN = 12;
|
|
8
|
-
const SALT_LEN = 16;
|
|
9
|
-
function getIterations() {
|
|
10
|
-
if (typeof process !== 'undefined' && process.env?.PBKDF2_ITERATIONS) {
|
|
11
|
-
const parsed = parseInt(process.env.PBKDF2_ITERATIONS, 10);
|
|
12
|
-
if (!isNaN(parsed) && parsed > 0) {
|
|
13
|
-
return parsed;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return ENC_ITER_DEFAULT;
|
|
17
|
-
}
|
|
18
|
-
async function encMnemonic(mnemonic, pass) {
|
|
19
|
-
if (!hasSubtle()) {
|
|
20
|
-
throw new Error('Web Cryptography API not available');
|
|
21
|
-
}
|
|
22
|
-
const salt = await randBytes(SALT_LEN);
|
|
23
|
-
const iv = await randBytes(IV_LEN);
|
|
24
|
-
const key = await deriveKey(pass, salt);
|
|
25
|
-
const ct = await crypto.subtle.encrypt({ name: ENC_ALG, iv: iv }, key, new TextEncoder().encode(mnemonic));
|
|
26
|
-
return { salt: b64(salt), iv: b64(iv), data: b64(new Uint8Array(ct)) };
|
|
27
|
-
}
|
|
28
|
-
async function decMnemonic(blob, pass) {
|
|
29
|
-
if (!hasSubtle()) {
|
|
30
|
-
throw new Error('Web Cryptography API not available');
|
|
31
|
-
}
|
|
32
|
-
const salt = ub64(blob.salt);
|
|
33
|
-
const iv = ub64(blob.iv);
|
|
34
|
-
const data = ub64(blob.data);
|
|
35
|
-
const key = await deriveKey(pass, salt);
|
|
36
|
-
const pt = await crypto.subtle.decrypt({ name: ENC_ALG, iv }, key, data);
|
|
37
|
-
return new TextDecoder().decode(pt);
|
|
38
|
-
}
|
|
39
|
-
const b64 = (buf) => {
|
|
40
|
-
return Buffer.from(buf).toString('base64');
|
|
41
|
-
};
|
|
42
|
-
const ub64 = (b64) => {
|
|
43
|
-
return new Uint8Array(Buffer.from(b64, 'base64'));
|
|
44
|
-
};
|
|
45
|
-
const hasSubtle = () => typeof globalThis !== 'undefined' &&
|
|
46
|
-
!!(globalThis.crypto && globalThis.crypto.subtle);
|
|
47
|
-
async function randBytes(len) {
|
|
48
|
-
const u8 = new Uint8Array(len);
|
|
49
|
-
crypto.getRandomValues(u8);
|
|
50
|
-
return u8;
|
|
51
|
-
}
|
|
52
|
-
async function deriveKey(pass, salt) {
|
|
53
|
-
const enc = new TextEncoder();
|
|
54
|
-
const passKey = await crypto.subtle.importKey('raw', enc.encode(pass), { name: ENC_KDF }, false, ['deriveKey']);
|
|
55
|
-
return crypto.subtle.deriveKey({ name: ENC_KDF, salt: salt, iterations: getIterations(), hash: ENC_HASH }, passKey, { name: ENC_ALG, length: 256 }, false, ['encrypt', 'decrypt']);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
exports.decMnemonic = decMnemonic;
|
|
59
|
-
exports.encMnemonic = encMnemonic;
|
package/dist/esm/encryption.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
const ENC_ALG = 'AES-GCM';
|
|
2
|
-
const ENC_KDF = 'PBKDF2';
|
|
3
|
-
const ENC_HASH = 'SHA-512';
|
|
4
|
-
const ENC_ITER_DEFAULT = 100_000;
|
|
5
|
-
const IV_LEN = 12;
|
|
6
|
-
const SALT_LEN = 16;
|
|
7
|
-
function getIterations() {
|
|
8
|
-
if (typeof process !== 'undefined' && process.env?.PBKDF2_ITERATIONS) {
|
|
9
|
-
const parsed = parseInt(process.env.PBKDF2_ITERATIONS, 10);
|
|
10
|
-
if (!isNaN(parsed) && parsed > 0) {
|
|
11
|
-
return parsed;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return ENC_ITER_DEFAULT;
|
|
15
|
-
}
|
|
16
|
-
export async function encMnemonic(mnemonic, pass) {
|
|
17
|
-
if (!hasSubtle()) {
|
|
18
|
-
throw new Error('Web Cryptography API not available');
|
|
19
|
-
}
|
|
20
|
-
const salt = await randBytes(SALT_LEN);
|
|
21
|
-
const iv = await randBytes(IV_LEN);
|
|
22
|
-
const key = await deriveKey(pass, salt);
|
|
23
|
-
const ct = await crypto.subtle.encrypt({ name: ENC_ALG, iv: iv }, key, new TextEncoder().encode(mnemonic));
|
|
24
|
-
return { salt: b64(salt), iv: b64(iv), data: b64(new Uint8Array(ct)) };
|
|
25
|
-
}
|
|
26
|
-
export async function decMnemonic(blob, pass) {
|
|
27
|
-
if (!hasSubtle()) {
|
|
28
|
-
throw new Error('Web Cryptography API not available');
|
|
29
|
-
}
|
|
30
|
-
const salt = ub64(blob.salt);
|
|
31
|
-
const iv = ub64(blob.iv);
|
|
32
|
-
const data = ub64(blob.data);
|
|
33
|
-
const key = await deriveKey(pass, salt);
|
|
34
|
-
const pt = await crypto.subtle.decrypt({ name: ENC_ALG, iv }, key, data);
|
|
35
|
-
return new TextDecoder().decode(pt);
|
|
36
|
-
}
|
|
37
|
-
const b64 = (buf) => {
|
|
38
|
-
return Buffer.from(buf).toString('base64');
|
|
39
|
-
};
|
|
40
|
-
const ub64 = (b64) => {
|
|
41
|
-
return new Uint8Array(Buffer.from(b64, 'base64'));
|
|
42
|
-
};
|
|
43
|
-
const hasSubtle = () => typeof globalThis !== 'undefined' &&
|
|
44
|
-
!!(globalThis.crypto && globalThis.crypto.subtle);
|
|
45
|
-
async function randBytes(len) {
|
|
46
|
-
const u8 = new Uint8Array(len);
|
|
47
|
-
crypto.getRandomValues(u8);
|
|
48
|
-
return u8;
|
|
49
|
-
}
|
|
50
|
-
async function deriveKey(pass, salt) {
|
|
51
|
-
const enc = new TextEncoder();
|
|
52
|
-
const passKey = await crypto.subtle.importKey('raw', enc.encode(pass), { name: ENC_KDF }, false, ['deriveKey']);
|
|
53
|
-
return crypto.subtle.deriveKey({ name: ENC_KDF, salt: salt, iterations: getIterations(), hash: ENC_HASH }, passKey, { name: ENC_ALG, length: 256 }, false, ['encrypt', 'decrypt']);
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=encryption.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"encryption.js","sourceRoot":"","sources":["../../src/encryption.ts"],"names":[],"mappings":"AACA,MAAM,OAAO,GAAG,SAAS,CAAC;AAC1B,MAAM,OAAO,GAAG,QAAQ,CAAC;AACzB,MAAM,QAAQ,GAAG,SAAS,CAAC;AAC3B,MAAM,gBAAgB,GAAG,OAAO,CAAC;AACjC,MAAM,MAAM,GAAG,EAAE,CAAC;AAClB,MAAM,QAAQ,GAAG,EAAE,CAAC;AAEpB,SAAS,a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