cojson 0.0.6 → 0.0.8
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/.eslintrc.cjs +11 -8
- package/dist/coValue.d.ts +97 -0
- package/dist/coValue.js +341 -401
- package/dist/coValue.js.map +1 -0
- package/dist/coValue.test.d.ts +1 -0
- package/dist/coValue.test.js +69 -113
- package/dist/coValue.test.js.map +1 -0
- package/dist/contentType.d.ts +15 -0
- package/dist/contentType.js +5 -5
- package/dist/contentType.js.map +1 -0
- package/dist/contentType.test.d.ts +1 -0
- package/dist/contentType.test.js +138 -168
- package/dist/contentType.test.js.map +1 -0
- package/dist/contentTypes/coList.d.ts +11 -0
- package/dist/contentTypes/coList.js +14 -16
- package/dist/contentTypes/coList.js.map +1 -0
- package/dist/contentTypes/coMap.d.ts +56 -0
- package/dist/contentTypes/coMap.js +112 -112
- package/dist/contentTypes/coMap.js.map +1 -0
- package/dist/contentTypes/coStream.d.ts +11 -0
- package/dist/contentTypes/coStream.js +14 -16
- package/dist/contentTypes/coStream.js.map +1 -0
- package/dist/contentTypes/static.d.ts +11 -0
- package/dist/contentTypes/static.js +12 -14
- package/dist/contentTypes/static.js.map +1 -0
- package/dist/crypto.d.ts +97 -0
- package/dist/crypto.js +100 -151
- package/dist/crypto.js.map +1 -0
- package/dist/crypto.test.d.ts +1 -0
- package/dist/crypto.test.js +94 -134
- package/dist/crypto.test.js.map +1 -0
- package/dist/ids.d.ts +7 -0
- package/dist/ids.js +2 -1
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +10 -18
- package/dist/index.js.map +1 -0
- package/dist/jsonValue.d.ts +7 -0
- package/dist/jsonValue.js +2 -1
- package/dist/jsonValue.js.map +1 -0
- package/dist/node.d.ts +33 -0
- package/dist/node.js +102 -133
- package/dist/node.js.map +1 -0
- package/dist/permissions.d.ts +54 -0
- package/dist/permissions.js +202 -228
- package/dist/permissions.js.map +1 -0
- package/dist/permissions.test.d.ts +1 -0
- package/dist/permissions.test.js +724 -915
- package/dist/permissions.test.js.map +1 -0
- package/dist/sync.d.ts +80 -0
- package/dist/sync.js +247 -294
- package/dist/sync.js.map +1 -0
- package/dist/sync.test.d.ts +1 -0
- package/dist/sync.test.js +763 -798
- package/dist/sync.test.js.map +1 -0
- package/package.json +7 -4
- package/src/coValue.test.ts +3 -4
- package/src/coValue.ts +11 -17
- package/src/contentType.test.ts +3 -3
- package/src/contentType.ts +6 -6
- package/src/contentTypes/coList.ts +4 -4
- package/src/contentTypes/coMap.ts +6 -6
- package/src/contentTypes/coStream.ts +4 -4
- package/src/contentTypes/static.ts +5 -5
- package/src/crypto.test.ts +1 -1
- package/src/crypto.ts +2 -2
- package/src/index.ts +9 -7
- package/src/jsonValue.ts +1 -1
- package/src/node.ts +6 -7
- package/src/permissions.test.ts +5 -5
- package/src/permissions.ts +7 -7
- package/src/sync.test.ts +7 -7
- package/src/sync.ts +6 -6
- package/tsconfig.json +1 -7
package/dist/crypto.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
import { ed25519, x25519 } from "@noble/curves/ed25519";
|
|
3
2
|
import { xsalsa20_poly1305, xsalsa20 } from "@noble/ciphers/salsa";
|
|
4
3
|
import { base58, base64url } from "@scure/base";
|
|
@@ -8,200 +7,150 @@ import { randomBytes } from "@noble/ciphers/webcrypto/utils";
|
|
|
8
7
|
const textEncoder = new TextEncoder();
|
|
9
8
|
const textDecoder = new TextDecoder();
|
|
10
9
|
export function newRandomSignatory() {
|
|
11
|
-
|
|
12
|
-
ed25519.utils.randomPrivateKey()
|
|
13
|
-
)}`;
|
|
10
|
+
return `signatorySecret_z${base58.encode(ed25519.utils.randomPrivateKey())}`;
|
|
14
11
|
}
|
|
15
12
|
export function signatorySecretToBytes(secret) {
|
|
16
|
-
|
|
13
|
+
return base58.decode(secret.substring("signatorySecret_z".length));
|
|
17
14
|
}
|
|
18
15
|
export function signatorySecretFromBytes(bytes) {
|
|
19
|
-
|
|
16
|
+
return `signatorySecret_z${base58.encode(bytes)}`;
|
|
20
17
|
}
|
|
21
18
|
export function getSignatoryID(secret) {
|
|
22
|
-
|
|
23
|
-
ed25519.getPublicKey(
|
|
24
|
-
base58.decode(secret.substring("signatorySecret_z".length))
|
|
25
|
-
)
|
|
26
|
-
)}`;
|
|
19
|
+
return `signatory_z${base58.encode(ed25519.getPublicKey(base58.decode(secret.substring("signatorySecret_z".length))))}`;
|
|
27
20
|
}
|
|
28
21
|
export function sign(secret, message) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
base58.decode(secret.substring("signatorySecret_z".length))
|
|
32
|
-
);
|
|
33
|
-
return `signature_z${base58.encode(signature)}`;
|
|
22
|
+
const signature = ed25519.sign(textEncoder.encode(stableStringify(message)), base58.decode(secret.substring("signatorySecret_z".length)));
|
|
23
|
+
return `signature_z${base58.encode(signature)}`;
|
|
34
24
|
}
|
|
35
25
|
export function verify(signature, message, id) {
|
|
36
|
-
|
|
37
|
-
base58.decode(signature.substring("signature_z".length)),
|
|
38
|
-
textEncoder.encode(stableStringify(message)),
|
|
39
|
-
base58.decode(id.substring("signatory_z".length))
|
|
40
|
-
);
|
|
26
|
+
return ed25519.verify(base58.decode(signature.substring("signature_z".length)), textEncoder.encode(stableStringify(message)), base58.decode(id.substring("signatory_z".length)));
|
|
41
27
|
}
|
|
42
28
|
export function newRandomRecipient() {
|
|
43
|
-
|
|
29
|
+
return `recipientSecret_z${base58.encode(x25519.utils.randomPrivateKey())}`;
|
|
44
30
|
}
|
|
45
31
|
export function recipientSecretToBytes(secret) {
|
|
46
|
-
|
|
32
|
+
return base58.decode(secret.substring("recipientSecret_z".length));
|
|
47
33
|
}
|
|
48
34
|
export function recipientSecretFromBytes(bytes) {
|
|
49
|
-
|
|
35
|
+
return `recipientSecret_z${base58.encode(bytes)}`;
|
|
50
36
|
}
|
|
51
37
|
export function getRecipientID(secret) {
|
|
52
|
-
|
|
53
|
-
x25519.getPublicKey(
|
|
54
|
-
base58.decode(secret.substring("recipientSecret_z".length))
|
|
55
|
-
)
|
|
56
|
-
)}`;
|
|
38
|
+
return `recipient_z${base58.encode(x25519.getPublicKey(base58.decode(secret.substring("recipientSecret_z".length))))}`;
|
|
57
39
|
}
|
|
58
40
|
export function seal(message, from, to, nOnceMaterial) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
senderPriv,
|
|
75
|
-
recipientPubs[i]
|
|
76
|
-
);
|
|
77
|
-
const sealedBytes = xsalsa20_poly1305(sharedSecret, nOnce).encrypt(
|
|
78
|
-
plaintext
|
|
79
|
-
);
|
|
80
|
-
sealedSet[recipient] = `sealed_U${base64url.encode(
|
|
81
|
-
sealedBytes
|
|
82
|
-
)}`;
|
|
83
|
-
}
|
|
84
|
-
return sealedSet;
|
|
41
|
+
const nOnce = blake3(textEncoder.encode(stableStringify(nOnceMaterial))).slice(0, 24);
|
|
42
|
+
const recipientsSorted = Array.from(to).sort();
|
|
43
|
+
const recipientPubs = recipientsSorted.map((recipient) => {
|
|
44
|
+
return base58.decode(recipient.substring("recipient_z".length));
|
|
45
|
+
});
|
|
46
|
+
const senderPriv = base58.decode(from.substring("recipientSecret_z".length));
|
|
47
|
+
const plaintext = textEncoder.encode(stableStringify(message));
|
|
48
|
+
const sealedSet = {};
|
|
49
|
+
for (let i = 0; i < recipientsSorted.length; i++) {
|
|
50
|
+
const recipient = recipientsSorted[i];
|
|
51
|
+
const sharedSecret = x25519.getSharedSecret(senderPriv, recipientPubs[i]);
|
|
52
|
+
const sealedBytes = xsalsa20_poly1305(sharedSecret, nOnce).encrypt(plaintext);
|
|
53
|
+
sealedSet[recipient] = `sealed_U${base64url.encode(sealedBytes)}`;
|
|
54
|
+
}
|
|
55
|
+
return sealedSet;
|
|
85
56
|
}
|
|
86
57
|
export function openAs(sealedSet, recipient, from, nOnceMaterial) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return JSON.parse(textDecoder.decode(plaintext));
|
|
105
|
-
} catch (e) {
|
|
106
|
-
console.error("Failed to decrypt/parse sealed message", e);
|
|
107
|
-
return void 0;
|
|
108
|
-
}
|
|
58
|
+
const nOnce = blake3(textEncoder.encode(stableStringify(nOnceMaterial))).slice(0, 24);
|
|
59
|
+
const recipientPriv = base58.decode(recipient.substring("recipientSecret_z".length));
|
|
60
|
+
const senderPub = base58.decode(from.substring("recipient_z".length));
|
|
61
|
+
const sealed = sealedSet[getRecipientID(recipient)];
|
|
62
|
+
if (!sealed) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
const sealedBytes = base64url.decode(sealed.substring("sealed_U".length));
|
|
66
|
+
const sharedSecret = x25519.getSharedSecret(recipientPriv, senderPub);
|
|
67
|
+
const plaintext = xsalsa20_poly1305(sharedSecret, nOnce).decrypt(sealedBytes);
|
|
68
|
+
try {
|
|
69
|
+
return JSON.parse(textDecoder.decode(plaintext));
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
console.error("Failed to decrypt/parse sealed message", e);
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
109
75
|
}
|
|
110
76
|
export function secureHash(value) {
|
|
111
|
-
|
|
112
|
-
blake3(textEncoder.encode(stableStringify(value)))
|
|
113
|
-
)}`;
|
|
77
|
+
return `hash_z${base58.encode(blake3(textEncoder.encode(stableStringify(value))))}`;
|
|
114
78
|
}
|
|
115
79
|
export class StreamingHash {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
80
|
+
constructor(fromClone) {
|
|
81
|
+
this.state = fromClone || blake3.create({});
|
|
82
|
+
}
|
|
83
|
+
update(value) {
|
|
84
|
+
this.state.update(textEncoder.encode(stableStringify(value)));
|
|
85
|
+
}
|
|
86
|
+
digest() {
|
|
87
|
+
const hash = this.state.digest();
|
|
88
|
+
return `hash_z${base58.encode(hash)}`;
|
|
89
|
+
}
|
|
90
|
+
clone() {
|
|
91
|
+
return new StreamingHash(this.state.clone());
|
|
92
|
+
}
|
|
130
93
|
}
|
|
131
94
|
export function shortHash(value) {
|
|
132
|
-
|
|
133
|
-
blake3(textEncoder.encode(stableStringify(value))).slice(0, 19)
|
|
134
|
-
)}`;
|
|
95
|
+
return `shortHash_z${base58.encode(blake3(textEncoder.encode(stableStringify(value))).slice(0, 19))}`;
|
|
135
96
|
}
|
|
136
97
|
export function newRandomKeySecret() {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
98
|
+
return {
|
|
99
|
+
secret: `keySecret_z${base58.encode(randomBytes(32))}`,
|
|
100
|
+
id: `key_z${base58.encode(randomBytes(12))}`,
|
|
101
|
+
};
|
|
141
102
|
}
|
|
142
103
|
function encrypt(value, keySecret, nOnceMaterial) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
).slice(0, 24);
|
|
149
|
-
const plaintext = textEncoder.encode(stableStringify(value));
|
|
150
|
-
const ciphertext = xsalsa20(keySecretBytes, nOnce, plaintext);
|
|
151
|
-
return `encrypted_U${base64url.encode(ciphertext)}`;
|
|
104
|
+
const keySecretBytes = base58.decode(keySecret.substring("keySecret_z".length));
|
|
105
|
+
const nOnce = blake3(textEncoder.encode(stableStringify(nOnceMaterial))).slice(0, 24);
|
|
106
|
+
const plaintext = textEncoder.encode(stableStringify(value));
|
|
107
|
+
const ciphertext = xsalsa20(keySecretBytes, nOnce, plaintext);
|
|
108
|
+
return `encrypted_U${base64url.encode(ciphertext)}`;
|
|
152
109
|
}
|
|
153
110
|
export function encryptForTransaction(value, keySecret, nOnceMaterial) {
|
|
154
|
-
|
|
111
|
+
return encrypt(value, keySecret, nOnceMaterial);
|
|
155
112
|
}
|
|
156
113
|
export function sealKeySecret(keys) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
keys.sealing.secret,
|
|
167
|
-
nOnceMaterial
|
|
168
|
-
)
|
|
169
|
-
};
|
|
114
|
+
const nOnceMaterial = {
|
|
115
|
+
sealed: keys.toSeal.id,
|
|
116
|
+
sealing: keys.sealing.id,
|
|
117
|
+
};
|
|
118
|
+
return {
|
|
119
|
+
sealed: keys.toSeal.id,
|
|
120
|
+
sealing: keys.sealing.id,
|
|
121
|
+
encrypted: encrypt(keys.toSeal.secret, keys.sealing.secret, nOnceMaterial),
|
|
122
|
+
};
|
|
170
123
|
}
|
|
171
124
|
function decrypt(encrypted, keySecret, nOnceMaterial) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
try {
|
|
183
|
-
return JSON.parse(textDecoder.decode(plaintext));
|
|
184
|
-
} catch (e) {
|
|
185
|
-
return void 0;
|
|
186
|
-
}
|
|
125
|
+
const keySecretBytes = base58.decode(keySecret.substring("keySecret_z".length));
|
|
126
|
+
const nOnce = blake3(textEncoder.encode(stableStringify(nOnceMaterial))).slice(0, 24);
|
|
127
|
+
const ciphertext = base64url.decode(encrypted.substring("encrypted_U".length));
|
|
128
|
+
const plaintext = xsalsa20(keySecretBytes, nOnce, ciphertext);
|
|
129
|
+
try {
|
|
130
|
+
return JSON.parse(textDecoder.decode(plaintext));
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
187
135
|
}
|
|
188
136
|
export function decryptForTransaction(encrypted, keySecret, nOnceMaterial) {
|
|
189
|
-
|
|
137
|
+
return decrypt(encrypted, keySecret, nOnceMaterial);
|
|
190
138
|
}
|
|
191
139
|
export function unsealKeySecret(sealedInfo, sealingSecret) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
140
|
+
const nOnceMaterial = {
|
|
141
|
+
sealed: sealedInfo.sealed,
|
|
142
|
+
sealing: sealedInfo.sealing,
|
|
143
|
+
};
|
|
144
|
+
return decrypt(sealedInfo.encrypted, sealingSecret, nOnceMaterial);
|
|
197
145
|
}
|
|
198
146
|
export function uniquenessForHeader() {
|
|
199
|
-
|
|
147
|
+
return `z${base58.encode(randomBytes(12))}`;
|
|
200
148
|
}
|
|
201
149
|
export function createdNowUnique() {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
150
|
+
const createdAt = (new Date()).toISOString();
|
|
151
|
+
return {
|
|
152
|
+
createdAt,
|
|
153
|
+
uniqueness: uniquenessForHeader(),
|
|
154
|
+
};
|
|
207
155
|
}
|
|
156
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEnE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,eAAe,MAAM,4BAA4B,C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KACpB;AACL,CAAC;AAED,MAAM,UAAU,qBAAqB,CACjC,SAAgE,EAChE,SAAoB,EACpB,aAAsD;IAEtD,OAAO,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,eAAe,CAC3B,UAIC,EACD,aAAwB;IAExB,MAAM,aAAa,GAAG;QAClB,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,OAAO,EAAE,UAAU,CAAC,OAAO;KAC9B,CAAC;IAEF,OAAO,OAAO,CAAC,UAAU,CAAC,SAAS,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,mBAAmB;IAC/B,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC5B,MAAM,SAAS,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,WAAW,EAAkB,CAAC;IAC7D,OAAO;QACH,SAAS;QACT,UAAU,EAAE,mBAAmB,EAAE;KACpC,CAAA;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/crypto.test.js
CHANGED
|
@@ -1,155 +1,115 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
getRecipientID,
|
|
4
|
-
getSignatoryID,
|
|
5
|
-
secureHash,
|
|
6
|
-
newRandomRecipient,
|
|
7
|
-
newRandomSignatory,
|
|
8
|
-
seal,
|
|
9
|
-
sign,
|
|
10
|
-
openAs,
|
|
11
|
-
verify,
|
|
12
|
-
shortHash,
|
|
13
|
-
newRandomKeySecret,
|
|
14
|
-
encryptForTransaction,
|
|
15
|
-
decryptForTransaction,
|
|
16
|
-
sealKeySecret,
|
|
17
|
-
unsealKeySecret
|
|
18
|
-
} from "./crypto";
|
|
1
|
+
import { getRecipientID, getSignatoryID, secureHash, newRandomRecipient, newRandomSignatory, seal, sign, openAs, verify, shortHash, newRandomKeySecret, encryptForTransaction, decryptForTransaction, sealKeySecret, unsealKeySecret, } from './crypto.js';
|
|
19
2
|
import { base58, base64url } from "@scure/base";
|
|
20
3
|
import { x25519 } from "@noble/curves/ed25519";
|
|
21
4
|
import { xsalsa20_poly1305 } from "@noble/ciphers/salsa";
|
|
22
5
|
import { blake3 } from "@noble/hashes/blake3";
|
|
23
6
|
import stableStringify from "fast-json-stable-stringify";
|
|
24
7
|
test("Signatures round-trip and use stable stringify", () => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
verify(signature, { a: "hello", b: "world" }, getSignatoryID(signatory))
|
|
31
|
-
).toBe(true);
|
|
8
|
+
const data = { b: "world", a: "hello" };
|
|
9
|
+
const signatory = newRandomSignatory();
|
|
10
|
+
const signature = sign(signatory, data);
|
|
11
|
+
expect(signature).toMatch(/^signature_z/);
|
|
12
|
+
expect(verify(signature, { a: "hello", b: "world" }, getSignatoryID(signatory))).toBe(true);
|
|
32
13
|
});
|
|
33
14
|
test("Invalid signatures don't verify", () => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
15
|
+
const data = { b: "world", a: "hello" };
|
|
16
|
+
const signatory = newRandomSignatory();
|
|
17
|
+
const signatory2 = newRandomSignatory();
|
|
18
|
+
const wrongSignature = sign(signatory2, data);
|
|
19
|
+
expect(verify(wrongSignature, data, getSignatoryID(signatory))).toBe(false);
|
|
39
20
|
});
|
|
40
21
|
test("Sealing round-trips, but invalid receiver can't unseal", () => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
nOnceMaterial
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
openAs(sealed, recipient3, getRecipientID(sender), nOnceMaterial)
|
|
66
|
-
).toBeUndefined();
|
|
67
|
-
const nOnce = blake3(
|
|
68
|
-
new TextEncoder().encode(stableStringify(nOnceMaterial))
|
|
69
|
-
).slice(0, 24);
|
|
70
|
-
const recipient3priv = base58.decode(
|
|
71
|
-
recipient3.substring("recipientSecret_z".length)
|
|
72
|
-
);
|
|
73
|
-
const senderPub = base58.decode(
|
|
74
|
-
getRecipientID(sender).substring("recipient_z".length)
|
|
75
|
-
);
|
|
76
|
-
const sealedBytes = base64url.decode(
|
|
77
|
-
sealed[getRecipientID(recipient1)].substring("sealed_U".length)
|
|
78
|
-
);
|
|
79
|
-
const sharedSecret = x25519.getSharedSecret(recipient3priv, senderPub);
|
|
80
|
-
expect(() => {
|
|
81
|
-
const _ = xsalsa20_poly1305(sharedSecret, nOnce).decrypt(sealedBytes);
|
|
82
|
-
}).toThrow("Wrong tag");
|
|
22
|
+
const data = { b: "world", a: "hello" };
|
|
23
|
+
const sender = newRandomRecipient();
|
|
24
|
+
const recipient1 = newRandomRecipient();
|
|
25
|
+
const recipient2 = newRandomRecipient();
|
|
26
|
+
const recipient3 = newRandomRecipient();
|
|
27
|
+
const nOnceMaterial = {
|
|
28
|
+
in: "co_zTEST",
|
|
29
|
+
tx: { sessionID: "co_agent_zTEST_session_zTEST", txIndex: 0 },
|
|
30
|
+
};
|
|
31
|
+
const sealed = seal(data, sender, new Set([getRecipientID(recipient1), getRecipientID(recipient2)]), nOnceMaterial);
|
|
32
|
+
expect(sealed[getRecipientID(recipient1)]).toMatch(/^sealed_U/);
|
|
33
|
+
expect(sealed[getRecipientID(recipient2)]).toMatch(/^sealed_U/);
|
|
34
|
+
expect(openAs(sealed, recipient1, getRecipientID(sender), nOnceMaterial)).toEqual(data);
|
|
35
|
+
expect(openAs(sealed, recipient2, getRecipientID(sender), nOnceMaterial)).toEqual(data);
|
|
36
|
+
expect(openAs(sealed, recipient3, getRecipientID(sender), nOnceMaterial)).toBeUndefined();
|
|
37
|
+
// trying with wrong recipient secret, by hand
|
|
38
|
+
const nOnce = blake3(new TextEncoder().encode(stableStringify(nOnceMaterial))).slice(0, 24);
|
|
39
|
+
const recipient3priv = base58.decode(recipient3.substring("recipientSecret_z".length));
|
|
40
|
+
const senderPub = base58.decode(getRecipientID(sender).substring("recipient_z".length));
|
|
41
|
+
const sealedBytes = base64url.decode(sealed[getRecipientID(recipient1)].substring("sealed_U".length));
|
|
42
|
+
const sharedSecret = x25519.getSharedSecret(recipient3priv, senderPub);
|
|
43
|
+
expect(() => {
|
|
44
|
+
const _ = xsalsa20_poly1305(sharedSecret, nOnce).decrypt(sealedBytes);
|
|
45
|
+
}).toThrow("Wrong tag");
|
|
83
46
|
});
|
|
84
47
|
test("Hashing is deterministic", () => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
);
|
|
88
|
-
expect(shortHash({ b: "world", a: "hello" })).toEqual(
|
|
89
|
-
shortHash({ a: "hello", b: "world" })
|
|
90
|
-
);
|
|
48
|
+
expect(secureHash({ b: "world", a: "hello" })).toEqual(secureHash({ a: "hello", b: "world" }));
|
|
49
|
+
expect(shortHash({ b: "world", a: "hello" })).toEqual(shortHash({ a: "hello", b: "world" }));
|
|
91
50
|
});
|
|
92
51
|
test("Encryption for transactions round-trips", () => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
52
|
+
const { secret } = newRandomKeySecret();
|
|
53
|
+
const encrypted1 = encryptForTransaction({ a: "hello" }, secret, {
|
|
54
|
+
in: "co_zTEST",
|
|
55
|
+
tx: { sessionID: "co_agent_zTEST_session_zTEST", txIndex: 0 },
|
|
56
|
+
});
|
|
57
|
+
const encrypted2 = encryptForTransaction({ b: "world" }, secret, {
|
|
58
|
+
in: "co_zTEST",
|
|
59
|
+
tx: { sessionID: "co_agent_zTEST_session_zTEST", txIndex: 1 },
|
|
60
|
+
});
|
|
61
|
+
const decrypted1 = decryptForTransaction(encrypted1, secret, {
|
|
62
|
+
in: "co_zTEST",
|
|
63
|
+
tx: { sessionID: "co_agent_zTEST_session_zTEST", txIndex: 0 },
|
|
64
|
+
});
|
|
65
|
+
const decrypted2 = decryptForTransaction(encrypted2, secret, {
|
|
66
|
+
in: "co_zTEST",
|
|
67
|
+
tx: { sessionID: "co_agent_zTEST_session_zTEST", txIndex: 1 },
|
|
68
|
+
});
|
|
69
|
+
expect([decrypted1, decrypted2]).toEqual([{ a: "hello" }, { b: "world" }]);
|
|
111
70
|
});
|
|
112
71
|
test("Encryption for transactions doesn't decrypt with a wrong key", () => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
72
|
+
const { secret } = newRandomKeySecret();
|
|
73
|
+
const { secret: secret2 } = newRandomKeySecret();
|
|
74
|
+
const encrypted1 = encryptForTransaction({ a: "hello" }, secret, {
|
|
75
|
+
in: "co_zTEST",
|
|
76
|
+
tx: { sessionID: "co_agent_zTEST_session_zTEST", txIndex: 0 },
|
|
77
|
+
});
|
|
78
|
+
const encrypted2 = encryptForTransaction({ b: "world" }, secret, {
|
|
79
|
+
in: "co_zTEST",
|
|
80
|
+
tx: { sessionID: "co_agent_zTEST_session_zTEST", txIndex: 1 },
|
|
81
|
+
});
|
|
82
|
+
const decrypted1 = decryptForTransaction(encrypted1, secret2, {
|
|
83
|
+
in: "co_zTEST",
|
|
84
|
+
tx: { sessionID: "co_agent_zTEST_session_zTEST", txIndex: 0 },
|
|
85
|
+
});
|
|
86
|
+
const decrypted2 = decryptForTransaction(encrypted2, secret2, {
|
|
87
|
+
in: "co_zTEST",
|
|
88
|
+
tx: { sessionID: "co_agent_zTEST_session_zTEST", txIndex: 1 },
|
|
89
|
+
});
|
|
90
|
+
expect([decrypted1, decrypted2]).toEqual([undefined, undefined]);
|
|
132
91
|
});
|
|
133
92
|
test("Encryption of keySecrets round-trips", () => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
93
|
+
const toSeal = newRandomKeySecret();
|
|
94
|
+
const sealing = newRandomKeySecret();
|
|
95
|
+
const keys = {
|
|
96
|
+
toSeal,
|
|
97
|
+
sealing,
|
|
98
|
+
};
|
|
99
|
+
const sealed = sealKeySecret(keys);
|
|
100
|
+
const unsealed = unsealKeySecret(sealed, sealing.secret);
|
|
101
|
+
expect(unsealed).toEqual(toSeal.secret);
|
|
143
102
|
});
|
|
144
103
|
test("Encryption of keySecrets doesn't unseal with a wrong key", () => {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
104
|
+
const toSeal = newRandomKeySecret();
|
|
105
|
+
const sealing = newRandomKeySecret();
|
|
106
|
+
const sealingWrong = newRandomKeySecret();
|
|
107
|
+
const keys = {
|
|
108
|
+
toSeal,
|
|
109
|
+
sealing,
|
|
110
|
+
};
|
|
111
|
+
const sealed = sealKeySecret(keys);
|
|
112
|
+
const unsealed = unsealKeySecret(sealed, sealingWrong.secret);
|
|
113
|
+
expect(unsealed).toBeUndefined();
|
|
155
114
|
});
|
|
115
|
+
//# sourceMappingURL=crypto.test.js.map
|
|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;AAEH,IAAI,CAAC,sCAAsC,EAAE,GAAG,EAAE;IAC9C,MAAM,MAAM,GAAG,kBAAkB,EAAE,CAAC;IACpC,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAC;IAErC,MAAM,IAAI,GAAG;QACT,MAAM;QACN,OAAO;KACV,CAAC;IAEF,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAEnC,MAAM,QAAQ,GAAG,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAEzD,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC5C,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,0DAA0D,EAAE,GAAG,EAAE;IAClE,MAAM,MAAM,GAAG,kBAAkB,EAAE,CAAC;IACpC,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAC;IACrC,MAAM,YAAY,GAAG,kBAAkB,EAAE,CAAC;IAE1C,MAAM,IAAI,GAAG;QACT,MAAM;QACN,OAAO;KACV,CAAC;IAEF,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAEnC,MAAM,QAAQ,GAAG,eAAe,CAAC,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;IAE9D,MAAM,CAAC,QAAQ,CAAC,CAAC,aAAa,EAAE,CAAC;AACrC,CAAC,CAAC,CAAC"}
|
package/dist/ids.d.ts
ADDED
package/dist/ids.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=ids.js.map
|
package/dist/ids.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.js","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CoValue, agentCredentialFromBytes, agentCredentialToBytes, getAgent, getAgentID, newRandomAgentCredential, newRandomSessionID } from './coValue.js';
|
|
2
|
+
import { LocalNode } from './node.js';
|
|
3
|
+
import { CoMap } from './contentTypes/coMap.js';
|
|
4
|
+
import type { AgentCredential } from './coValue.js';
|
|
5
|
+
import type { AgentID, SessionID } from './ids.js';
|
|
6
|
+
import type { CoValueID, ContentType } from './contentType.js';
|
|
7
|
+
import type { JsonValue } from './jsonValue.js';
|
|
8
|
+
import type { SyncMessage } from './sync.js';
|
|
9
|
+
type Value = JsonValue | ContentType;
|
|
10
|
+
declare const internals: {
|
|
11
|
+
agentCredentialToBytes: typeof agentCredentialToBytes;
|
|
12
|
+
agentCredentialFromBytes: typeof agentCredentialFromBytes;
|
|
13
|
+
getAgent: typeof getAgent;
|
|
14
|
+
getAgentID: typeof getAgentID;
|
|
15
|
+
newRandomAgentCredential: typeof newRandomAgentCredential;
|
|
16
|
+
newRandomSessionID: typeof newRandomSessionID;
|
|
17
|
+
};
|
|
18
|
+
export { LocalNode, CoValue, CoMap, internals };
|
|
19
|
+
export type { Value, JsonValue, ContentType, CoValueID, AgentCredential, SessionID, AgentID, SyncMessage };
|