@peerbit/crypto 1.0.1
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/LICENSE +202 -0
- package/README.md +3 -0
- package/lib/esm/bytes.d.ts +5 -0
- package/lib/esm/bytes.js +15 -0
- package/lib/esm/bytes.js.map +1 -0
- package/lib/esm/ed25519-sign-browser.d.ts +5 -0
- package/lib/esm/ed25519-sign-browser.js +27 -0
- package/lib/esm/ed25519-sign-browser.js.map +1 -0
- package/lib/esm/ed25519-sign.d.ts +5 -0
- package/lib/esm/ed25519-sign.js +64 -0
- package/lib/esm/ed25519-sign.js.map +1 -0
- package/lib/esm/ed25519.d.ts +41 -0
- package/lib/esm/ed25519.js +181 -0
- package/lib/esm/ed25519.js.map +1 -0
- package/lib/esm/encryption.d.ts +76 -0
- package/lib/esm/encryption.js +350 -0
- package/lib/esm/encryption.js.map +1 -0
- package/lib/esm/errors.d.ts +3 -0
- package/lib/esm/errors.js +6 -0
- package/lib/esm/errors.js.map +1 -0
- package/lib/esm/hash-browser.d.ts +4 -0
- package/lib/esm/hash-browser.js +7 -0
- package/lib/esm/hash-browser.js.map +1 -0
- package/lib/esm/hash.d.ts +4 -0
- package/lib/esm/hash.js +6 -0
- package/lib/esm/hash.js.map +1 -0
- package/lib/esm/index.d.ts +14 -0
- package/lib/esm/index.js +15 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/key.d.ts +44 -0
- package/lib/esm/key.js +51 -0
- package/lib/esm/key.js.map +1 -0
- package/lib/esm/keychain.d.ts +30 -0
- package/lib/esm/keychain.js +142 -0
- package/lib/esm/keychain.js.map +1 -0
- package/lib/esm/libp2p.d.ts +5 -0
- package/lib/esm/libp2p.js +21 -0
- package/lib/esm/libp2p.js.map +1 -0
- package/lib/esm/prehash.d.ts +6 -0
- package/lib/esm/prehash.js +32 -0
- package/lib/esm/prehash.js.map +1 -0
- package/lib/esm/random-browser.d.ts +1 -0
- package/lib/esm/random-browser.js +2 -0
- package/lib/esm/random-browser.js.map +1 -0
- package/lib/esm/random.d.ts +2 -0
- package/lib/esm/random.js +3 -0
- package/lib/esm/random.js.map +1 -0
- package/lib/esm/sepc256k1.d.ts +42 -0
- package/lib/esm/sepc256k1.js +194 -0
- package/lib/esm/sepc256k1.js.map +1 -0
- package/lib/esm/signature.d.ts +34 -0
- package/lib/esm/signature.js +283 -0
- package/lib/esm/signature.js.map +1 -0
- package/lib/esm/signer.d.ts +10 -0
- package/lib/esm/signer.js +2 -0
- package/lib/esm/signer.js.map +1 -0
- package/lib/esm/utils.d.ts +4 -0
- package/lib/esm/utils.js +10 -0
- package/lib/esm/utils.js.map +1 -0
- package/lib/esm/x25519.d.ts +38 -0
- package/lib/esm/x25519.js +158 -0
- package/lib/esm/x25519.js.map +1 -0
- package/package.json +55 -0
- package/src/bytes.ts +12 -0
- package/src/ed25519-sign-browser.ts +43 -0
- package/src/ed25519-sign.ts +83 -0
- package/src/ed25519.ts +194 -0
- package/src/encryption.ts +376 -0
- package/src/errors.ts +5 -0
- package/src/hash-browser.ts +10 -0
- package/src/hash.ts +10 -0
- package/src/index.ts +14 -0
- package/src/key.ts +80 -0
- package/src/keychain.ts +197 -0
- package/src/libp2p.ts +27 -0
- package/src/prehash.ts +42 -0
- package/src/random-browser.ts +2 -0
- package/src/random.ts +2 -0
- package/src/sepc256k1.ts +229 -0
- package/src/signature.ts +284 -0
- package/src/signer.ts +18 -0
- package/src/utils.ts +15 -0
- package/src/x25519.ts +167 -0
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var DecryptedThing_1, CipherWithNonce_1, K_1, Envelope_1, EncryptedThing_1;
|
|
11
|
+
export * from "./errors.js";
|
|
12
|
+
import { deserialize, field, serialize, variant, vec, } from "@dao-xyz/borsh";
|
|
13
|
+
import { equals } from "@peerbit/uint8arrays";
|
|
14
|
+
import { AccessError } from "./errors.js";
|
|
15
|
+
import sodium from "libsodium-wrappers";
|
|
16
|
+
import { X25519Keypair, X25519PublicKey, X25519SecretKey } from "./x25519.js";
|
|
17
|
+
import { Ed25519PublicKey } from "./ed25519.js";
|
|
18
|
+
import { randomBytes } from "./random.js";
|
|
19
|
+
const NONCE_LENGTH = 24;
|
|
20
|
+
export let MaybeEncrypted = class MaybeEncrypted {
|
|
21
|
+
/**
|
|
22
|
+
* Will throw error if not decrypted
|
|
23
|
+
*/
|
|
24
|
+
get decrypted() {
|
|
25
|
+
throw new Error("Not implented");
|
|
26
|
+
}
|
|
27
|
+
decrypt(keyOrKeychain) {
|
|
28
|
+
throw new Error("Not implemented");
|
|
29
|
+
}
|
|
30
|
+
equals(other) {
|
|
31
|
+
throw new Error("Not implemented");
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Clear cached data
|
|
35
|
+
*/
|
|
36
|
+
clear() {
|
|
37
|
+
throw new Error("Not implemented");
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
MaybeEncrypted = __decorate([
|
|
41
|
+
variant(0)
|
|
42
|
+
], MaybeEncrypted);
|
|
43
|
+
export let DecryptedThing = DecryptedThing_1 = class DecryptedThing extends MaybeEncrypted {
|
|
44
|
+
_data;
|
|
45
|
+
constructor(props) {
|
|
46
|
+
super();
|
|
47
|
+
if (props) {
|
|
48
|
+
this._data = props.data;
|
|
49
|
+
this._value = props.value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
_value;
|
|
53
|
+
getValue(clazz) {
|
|
54
|
+
if (this._value) {
|
|
55
|
+
return this._value;
|
|
56
|
+
}
|
|
57
|
+
if (!this._data) {
|
|
58
|
+
throw new Error("Missing data");
|
|
59
|
+
}
|
|
60
|
+
return deserialize(this._data, clazz);
|
|
61
|
+
}
|
|
62
|
+
async encrypt(x25519Keypair, ...recieverPublicKeys) {
|
|
63
|
+
const bytes = serialize(this);
|
|
64
|
+
const epheremalKey = sodium.crypto_secretbox_keygen();
|
|
65
|
+
const nonce = randomBytes(NONCE_LENGTH); // crypto random is faster than sodim random
|
|
66
|
+
const cipher = sodium.crypto_secretbox_easy(bytes, nonce, epheremalKey);
|
|
67
|
+
const recieverX25519PublicKeys = await Promise.all(recieverPublicKeys.map((key) => {
|
|
68
|
+
if (key instanceof Ed25519PublicKey) {
|
|
69
|
+
return X25519PublicKey.from(key);
|
|
70
|
+
}
|
|
71
|
+
return key;
|
|
72
|
+
}));
|
|
73
|
+
const ks = recieverX25519PublicKeys.map((recieverPublicKey) => {
|
|
74
|
+
const kNonce = randomBytes(NONCE_LENGTH); // crypto random is faster than sodium random
|
|
75
|
+
return new K({
|
|
76
|
+
encryptedKey: new CipherWithNonce({
|
|
77
|
+
cipher: sodium.crypto_box_easy(epheremalKey, kNonce, recieverPublicKey.publicKey, x25519Keypair.secretKey.secretKey),
|
|
78
|
+
nonce: kNonce,
|
|
79
|
+
}),
|
|
80
|
+
recieverPublicKey,
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
const enc = new EncryptedThing({
|
|
84
|
+
encrypted: new Uint8Array(cipher),
|
|
85
|
+
nonce,
|
|
86
|
+
envelope: new Envelope({
|
|
87
|
+
senderPublicKey: x25519Keypair.publicKey,
|
|
88
|
+
ks,
|
|
89
|
+
}),
|
|
90
|
+
});
|
|
91
|
+
enc._decrypted = this;
|
|
92
|
+
return enc;
|
|
93
|
+
}
|
|
94
|
+
get decrypted() {
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
decrypt() {
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
equals(other) {
|
|
101
|
+
if (other instanceof DecryptedThing_1) {
|
|
102
|
+
return equals(this._data, other._data);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
clear() {
|
|
109
|
+
this._value = undefined;
|
|
110
|
+
}
|
|
111
|
+
get byteLength() {
|
|
112
|
+
return this._data.byteLength;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
__decorate([
|
|
116
|
+
field({ type: Uint8Array }),
|
|
117
|
+
__metadata("design:type", Uint8Array)
|
|
118
|
+
], DecryptedThing.prototype, "_data", void 0);
|
|
119
|
+
DecryptedThing = DecryptedThing_1 = __decorate([
|
|
120
|
+
variant(0),
|
|
121
|
+
__metadata("design:paramtypes", [Object])
|
|
122
|
+
], DecryptedThing);
|
|
123
|
+
export let CipherWithNonce = CipherWithNonce_1 = class CipherWithNonce {
|
|
124
|
+
nonce;
|
|
125
|
+
cipher;
|
|
126
|
+
constructor(props) {
|
|
127
|
+
if (props) {
|
|
128
|
+
this.nonce = props.nonce;
|
|
129
|
+
this.cipher = props.cipher;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
equals(other) {
|
|
133
|
+
if (other instanceof CipherWithNonce_1) {
|
|
134
|
+
return (equals(this.nonce, other.nonce) && equals(this.cipher, other.cipher));
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
__decorate([
|
|
142
|
+
field({ type: Uint8Array }),
|
|
143
|
+
__metadata("design:type", Uint8Array)
|
|
144
|
+
], CipherWithNonce.prototype, "nonce", void 0);
|
|
145
|
+
__decorate([
|
|
146
|
+
field({ type: Uint8Array }),
|
|
147
|
+
__metadata("design:type", Uint8Array)
|
|
148
|
+
], CipherWithNonce.prototype, "cipher", void 0);
|
|
149
|
+
CipherWithNonce = CipherWithNonce_1 = __decorate([
|
|
150
|
+
variant(0),
|
|
151
|
+
__metadata("design:paramtypes", [Object])
|
|
152
|
+
], CipherWithNonce);
|
|
153
|
+
export let K = K_1 = class K {
|
|
154
|
+
_encryptedKey;
|
|
155
|
+
_recieverPublicKey;
|
|
156
|
+
constructor(props) {
|
|
157
|
+
if (props) {
|
|
158
|
+
this._encryptedKey = props.encryptedKey;
|
|
159
|
+
this._recieverPublicKey = props.recieverPublicKey;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
equals(other) {
|
|
163
|
+
if (other instanceof K_1) {
|
|
164
|
+
return (this._encryptedKey.equals(other._encryptedKey) &&
|
|
165
|
+
this._recieverPublicKey.equals(other._recieverPublicKey));
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
__decorate([
|
|
173
|
+
field({ type: CipherWithNonce }),
|
|
174
|
+
__metadata("design:type", CipherWithNonce)
|
|
175
|
+
], K.prototype, "_encryptedKey", void 0);
|
|
176
|
+
__decorate([
|
|
177
|
+
field({ type: X25519PublicKey }),
|
|
178
|
+
__metadata("design:type", X25519PublicKey)
|
|
179
|
+
], K.prototype, "_recieverPublicKey", void 0);
|
|
180
|
+
K = K_1 = __decorate([
|
|
181
|
+
variant(0),
|
|
182
|
+
__metadata("design:paramtypes", [Object])
|
|
183
|
+
], K);
|
|
184
|
+
export let Envelope = Envelope_1 = class Envelope {
|
|
185
|
+
_senderPublicKey;
|
|
186
|
+
_ks;
|
|
187
|
+
constructor(props) {
|
|
188
|
+
if (props) {
|
|
189
|
+
this._senderPublicKey = props.senderPublicKey;
|
|
190
|
+
this._ks = props.ks;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
equals(other) {
|
|
194
|
+
if (other instanceof Envelope_1) {
|
|
195
|
+
if (!this._senderPublicKey.equals(other._senderPublicKey)) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
if (this._ks.length !== other._ks.length) {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
for (let i = 0; i < this._ks.length; i++) {
|
|
202
|
+
if (!this._ks[i].equals(other._ks[i])) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
__decorate([
|
|
214
|
+
field({ type: X25519PublicKey }),
|
|
215
|
+
__metadata("design:type", X25519PublicKey)
|
|
216
|
+
], Envelope.prototype, "_senderPublicKey", void 0);
|
|
217
|
+
__decorate([
|
|
218
|
+
field({ type: vec(K) }),
|
|
219
|
+
__metadata("design:type", Array)
|
|
220
|
+
], Envelope.prototype, "_ks", void 0);
|
|
221
|
+
Envelope = Envelope_1 = __decorate([
|
|
222
|
+
variant(0),
|
|
223
|
+
__metadata("design:paramtypes", [Object])
|
|
224
|
+
], Envelope);
|
|
225
|
+
export let EncryptedThing = EncryptedThing_1 = class EncryptedThing extends MaybeEncrypted {
|
|
226
|
+
_encrypted;
|
|
227
|
+
_nonce;
|
|
228
|
+
_envelope;
|
|
229
|
+
constructor(props) {
|
|
230
|
+
super();
|
|
231
|
+
if (props) {
|
|
232
|
+
this._encrypted = props.encrypted;
|
|
233
|
+
this._nonce = props.nonce;
|
|
234
|
+
this._envelope = props.envelope;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
_decrypted;
|
|
238
|
+
get decrypted() {
|
|
239
|
+
if (!this._decrypted) {
|
|
240
|
+
throw new Error("Entry has not been decrypted, invoke decrypt method before");
|
|
241
|
+
}
|
|
242
|
+
return this._decrypted;
|
|
243
|
+
}
|
|
244
|
+
async decrypt(keyResolver) {
|
|
245
|
+
if (this._decrypted) {
|
|
246
|
+
return this._decrypted;
|
|
247
|
+
}
|
|
248
|
+
if (!keyResolver) {
|
|
249
|
+
throw new AccessError("Expecting key resolver");
|
|
250
|
+
}
|
|
251
|
+
// We only need to open with one of the keys
|
|
252
|
+
let key;
|
|
253
|
+
if (keyResolver instanceof X25519Keypair) {
|
|
254
|
+
for (const [i, k] of this._envelope._ks.entries()) {
|
|
255
|
+
if (k._recieverPublicKey.equals(keyResolver.publicKey)) {
|
|
256
|
+
key = {
|
|
257
|
+
index: i,
|
|
258
|
+
keypair: keyResolver,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
for (const [i, k] of this._envelope._ks.entries()) {
|
|
265
|
+
const exported = await keyResolver.exportByKey(k._recieverPublicKey);
|
|
266
|
+
if (exported) {
|
|
267
|
+
key = {
|
|
268
|
+
index: i,
|
|
269
|
+
keypair: exported,
|
|
270
|
+
};
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (key) {
|
|
276
|
+
const k = this._envelope._ks[key.index];
|
|
277
|
+
let secretKey = undefined;
|
|
278
|
+
if (key.keypair instanceof X25519Keypair) {
|
|
279
|
+
secretKey = key.keypair.secretKey;
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
secretKey = await X25519SecretKey.from(key.keypair);
|
|
283
|
+
}
|
|
284
|
+
let epheremalKey;
|
|
285
|
+
try {
|
|
286
|
+
epheremalKey = sodium.crypto_box_open_easy(k._encryptedKey.cipher, k._encryptedKey.nonce, this._envelope._senderPublicKey.publicKey, secretKey.secretKey);
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
289
|
+
throw new AccessError("Failed to decrypt");
|
|
290
|
+
}
|
|
291
|
+
// TODO: is nested decryption necessary?
|
|
292
|
+
/* let der: any = this;
|
|
293
|
+
let counter = 0;
|
|
294
|
+
while (der instanceof EncryptedThing) {
|
|
295
|
+
const decrypted = await sodium.crypto_secretbox_open_easy(this._encrypted, this._nonce, epheremalKey);
|
|
296
|
+
der = deserialize(decrypted, DecryptedThing)
|
|
297
|
+
counter += 1;
|
|
298
|
+
if (counter >= 10) {
|
|
299
|
+
throw new Error("Unexpected decryption behaviour, data seems to always be in encrypted state")
|
|
300
|
+
}
|
|
301
|
+
} */
|
|
302
|
+
const der = deserialize(sodium.crypto_secretbox_open_easy(this._encrypted, this._nonce, epheremalKey), DecryptedThing);
|
|
303
|
+
this._decrypted = der;
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
throw new AccessError("Failed to resolve decryption key");
|
|
307
|
+
}
|
|
308
|
+
return this._decrypted;
|
|
309
|
+
}
|
|
310
|
+
equals(other) {
|
|
311
|
+
if (other instanceof EncryptedThing_1) {
|
|
312
|
+
if (!equals(this._encrypted, other._encrypted)) {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
if (!equals(this._nonce, other._nonce)) {
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
if (!this._envelope.equals(other._envelope)) {
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
clear() {
|
|
328
|
+
this._decrypted = undefined;
|
|
329
|
+
}
|
|
330
|
+
get byteLength() {
|
|
331
|
+
return this._encrypted.byteLength; // ignore other metdata for now in the size calculation
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
__decorate([
|
|
335
|
+
field({ type: Uint8Array }),
|
|
336
|
+
__metadata("design:type", Uint8Array)
|
|
337
|
+
], EncryptedThing.prototype, "_encrypted", void 0);
|
|
338
|
+
__decorate([
|
|
339
|
+
field({ type: Uint8Array }),
|
|
340
|
+
__metadata("design:type", Uint8Array)
|
|
341
|
+
], EncryptedThing.prototype, "_nonce", void 0);
|
|
342
|
+
__decorate([
|
|
343
|
+
field({ type: Envelope }),
|
|
344
|
+
__metadata("design:type", Envelope)
|
|
345
|
+
], EncryptedThing.prototype, "_envelope", void 0);
|
|
346
|
+
EncryptedThing = EncryptedThing_1 = __decorate([
|
|
347
|
+
variant(1),
|
|
348
|
+
__metadata("design:paramtypes", [Object])
|
|
349
|
+
], EncryptedThing);
|
|
350
|
+
//# sourceMappingURL=encryption.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.js","sourceRoot":"","sources":["../../src/encryption.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,cAAc,aAAa,CAAC;AAC5B,OAAO,EAEN,WAAW,EACX,KAAK,EACL,SAAS,EACT,OAAO,EACP,GAAG,GACH,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAkB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,MAAM,YAAY,GAAG,EAAE,CAAC;AAGjB,WAAe,cAAc,GAA7B,MAAe,cAAc;IACnC;;OAEG;IACH,IAAI,SAAS;QACZ,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,CACN,aAAwC;QAExC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;IACD,MAAM,CAAC,KAAwB;QAC9B,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,KAAK;QACJ,MAAM,IAAI,KAAK,CAA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
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,WAAY,SAAQ,KAAK;IACrC,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,CAAC,CAAC;IAChB,CAAC;CACD"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const sha256Base64: (bytes: Uint8Array) => Promise<string>;
|
|
2
|
+
export declare const sha256Base64Sync: (bytes: Uint8Array) => string;
|
|
3
|
+
export declare const sha256: (bytes: Uint8Array) => Promise<Uint8Array>;
|
|
4
|
+
export declare const sha256Sync: (bytes: Uint8Array) => Uint8Array;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { toBase64 } from "./utils";
|
|
2
|
+
import { SHA256 } from "@stablelib/sha256";
|
|
3
|
+
export const sha256Base64 = async (bytes) => toBase64(await sha256(bytes));
|
|
4
|
+
export const sha256Base64Sync = (bytes) => toBase64(new SHA256().update(bytes).digest());
|
|
5
|
+
export const sha256 = async (bytes) => new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256", bytes));
|
|
6
|
+
export const sha256Sync = (bytes) => new SHA256().update(bytes).digest();
|
|
7
|
+
//# sourceMappingURL=hash-browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash-browser.js","sourceRoot":"","sources":["../../src/hash-browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,KAAiB,EAAmB,EAAE,CACxE,QAAQ,CAAC,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/B,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAiB,EAAU,EAAE,CAC7D,QAAQ,CAAC,IAAI,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;AAC/C,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EAAE,KAAiB,EAAuB,EAAE,CACtE,IAAI,UAAU,CAAC,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;AACzE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAiB,EAAc,EAAE,CAC3D,IAAI,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const sha256Base64Sync: (bytes: Uint8Array) => string;
|
|
2
|
+
export declare const sha256Base64: (bytes: Uint8Array) => Promise<string>;
|
|
3
|
+
export declare const sha256: (bytes: Uint8Array) => Promise<Uint8Array>;
|
|
4
|
+
export declare const sha256Sync: (bytes: Uint8Array) => Uint8Array;
|
package/lib/esm/hash.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
export const sha256Base64Sync = (bytes) => crypto.createHash("sha256").update(bytes).digest("base64");
|
|
3
|
+
export const sha256Base64 = async (bytes) => crypto.createHash("sha256").update(bytes).digest("base64");
|
|
4
|
+
export const sha256 = async (bytes) => crypto.createHash("sha256").update(bytes).digest();
|
|
5
|
+
export const sha256Sync = (bytes) => crypto.createHash("sha256").update(bytes).digest();
|
|
6
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAiB,EAAU,EAAE,CAC7D,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC5D,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,KAAiB,EAAmB,EAAE,CACxE,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC5D,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EAAE,KAAiB,EAAuB,EAAE,CACtE,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;AACpD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAiB,EAAc,EAAE,CAC3D,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./key.js";
|
|
2
|
+
export * from "./ed25519.js";
|
|
3
|
+
export * from "./signature.js";
|
|
4
|
+
export * from "./key.js";
|
|
5
|
+
export * from "./sepc256k1.js";
|
|
6
|
+
export * from "./x25519.js";
|
|
7
|
+
export * from "./encryption.js";
|
|
8
|
+
export * from "./libp2p.js";
|
|
9
|
+
export * from "./utils.js";
|
|
10
|
+
export * from "./hash.js";
|
|
11
|
+
export * from "./random.js";
|
|
12
|
+
export * from "./prehash.js";
|
|
13
|
+
export * from "./signer.js";
|
|
14
|
+
export * from "./keychain.js";
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from "./key.js";
|
|
2
|
+
export * from "./ed25519.js";
|
|
3
|
+
export * from "./signature.js";
|
|
4
|
+
export * from "./key.js";
|
|
5
|
+
export * from "./sepc256k1.js";
|
|
6
|
+
export * from "./x25519.js";
|
|
7
|
+
export * from "./encryption.js";
|
|
8
|
+
export * from "./libp2p.js";
|
|
9
|
+
export * from "./utils.js";
|
|
10
|
+
export * from "./hash.js";
|
|
11
|
+
export * from "./random.js";
|
|
12
|
+
export * from "./prehash.js";
|
|
13
|
+
export * from "./signer.js";
|
|
14
|
+
export * from "./keychain.js";
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
|
package/lib/esm/key.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { PeerId } from "@libp2p/interface-peer-id";
|
|
2
|
+
interface Key {
|
|
3
|
+
equals(other: Key): boolean;
|
|
4
|
+
get bytes(): Uint8Array;
|
|
5
|
+
hashcode(): string;
|
|
6
|
+
toString(): string;
|
|
7
|
+
_hashcode: string;
|
|
8
|
+
}
|
|
9
|
+
export declare abstract class Keypair {
|
|
10
|
+
abstract get publicKey(): PublicSignKey | PublicKeyEncryptionKey;
|
|
11
|
+
equals(other: Keypair): boolean;
|
|
12
|
+
toPeerId(): Promise<PeerId>;
|
|
13
|
+
}
|
|
14
|
+
export interface PublicSignKey extends Key {
|
|
15
|
+
}
|
|
16
|
+
export declare abstract class PublicSignKey implements Key {
|
|
17
|
+
get bytes(): Uint8Array;
|
|
18
|
+
hashcode(): string;
|
|
19
|
+
}
|
|
20
|
+
export interface PrivateSignKey extends Key {
|
|
21
|
+
}
|
|
22
|
+
export declare abstract class PrivateSignKey implements Key {
|
|
23
|
+
get bytes(): Uint8Array;
|
|
24
|
+
hashcode(): string;
|
|
25
|
+
}
|
|
26
|
+
export interface PublicKeyEncryptionKey extends Key {
|
|
27
|
+
}
|
|
28
|
+
export declare abstract class PublicKeyEncryptionKey implements Key {
|
|
29
|
+
get bytes(): Uint8Array;
|
|
30
|
+
hashcode(): string;
|
|
31
|
+
}
|
|
32
|
+
export interface PrivateEncryptionKey extends Key {
|
|
33
|
+
}
|
|
34
|
+
export declare abstract class PrivateEncryptionKey implements Key {
|
|
35
|
+
get bytes(): Uint8Array;
|
|
36
|
+
hashcode(): string;
|
|
37
|
+
}
|
|
38
|
+
export interface PlainKey extends Key {
|
|
39
|
+
}
|
|
40
|
+
export declare abstract class PlainKey implements Key {
|
|
41
|
+
get bytes(): Uint8Array;
|
|
42
|
+
hashcode(): string;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
package/lib/esm/key.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { serialize } from "@dao-xyz/borsh";
|
|
2
|
+
import { sha256Base64Sync } from "./hash.js";
|
|
3
|
+
export class Keypair {
|
|
4
|
+
equals(other) {
|
|
5
|
+
throw new Error("Not implemented");
|
|
6
|
+
}
|
|
7
|
+
toPeerId() {
|
|
8
|
+
throw new Error("Not implemented");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class PublicSignKey {
|
|
12
|
+
get bytes() {
|
|
13
|
+
return serialize(this);
|
|
14
|
+
}
|
|
15
|
+
hashcode() {
|
|
16
|
+
return this._hashcode || (this._hashcode = sha256Base64Sync(this.bytes));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export class PrivateSignKey {
|
|
20
|
+
get bytes() {
|
|
21
|
+
return serialize(this);
|
|
22
|
+
}
|
|
23
|
+
hashcode() {
|
|
24
|
+
return this._hashcode || (this._hashcode = sha256Base64Sync(this.bytes));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class PublicKeyEncryptionKey {
|
|
28
|
+
get bytes() {
|
|
29
|
+
return serialize(this);
|
|
30
|
+
}
|
|
31
|
+
hashcode() {
|
|
32
|
+
return this._hashcode || (this._hashcode = sha256Base64Sync(this.bytes));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class PrivateEncryptionKey {
|
|
36
|
+
get bytes() {
|
|
37
|
+
return serialize(this);
|
|
38
|
+
}
|
|
39
|
+
hashcode() {
|
|
40
|
+
return this._hashcode || (this._hashcode = sha256Base64Sync(this.bytes));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export class PlainKey {
|
|
44
|
+
get bytes() {
|
|
45
|
+
return serialize(this);
|
|
46
|
+
}
|
|
47
|
+
hashcode() {
|
|
48
|
+
return this._hashcode || (this._hashcode = sha256Base64Sync(this.bytes));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key.js","sourceRoot":"","sources":["../../src/key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAW7C,MAAM,OAAgB,OAAO;IAG5B,MAAM,CAAC,KAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;IAED,QAAQ;QACP,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;CACD;AAID,MAAM,OAAgB,aAAa;IAClC,IAAI,KAAK;QACR,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,QAAQ;QACP,OAAO,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1E,CAAC;CACD;AAGD,MAAM,OAAgB,cAAc;IACnC,IAAI,KAAK;QACR,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,QAAQ;QACP,OAAO,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1E,CAAC;CACD;AAID,MAAM,OAAgB,sBAAsB;IAC3C,IAAI,KAAK;QACR,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,QAAQ;QACP,OAAO,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1E,CAAC;CACD;AAED,MAAM,OAAgB,oBAAoB;IACzC,IAAI,KAAK;QACR,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,QAAQ;QACP,OAAO,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1E,CAAC;CACD;AAID,MAAM,OAAgB,QAAQ;IAC7B,IAAI,KAAK;QACR,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,QAAQ;QACP,OAAO,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1E,CAAC;CACD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { KeyChain as InternalKeychain } from "@libp2p/interface-keychain";
|
|
2
|
+
import { Cache } from "@peerbit/cache";
|
|
3
|
+
import { Ed25519Keypair, Ed25519PublicKey } from "./ed25519.js";
|
|
4
|
+
import { X25519Keypair, X25519PublicKey } from "./x25519.js";
|
|
5
|
+
export type KeypairFromPublicKey<T> = T extends X25519PublicKey ? X25519PublicKey extends T ? X25519Keypair : Ed25519Keypair : Ed25519Keypair;
|
|
6
|
+
export interface Keychain {
|
|
7
|
+
import(keypair: Ed25519Keypair, id: Uint8Array): Promise<void>;
|
|
8
|
+
exportByKey<T extends Ed25519PublicKey | X25519PublicKey, Q = KeypairFromPublicKey<T>>(publicKey: T): Promise<Q | undefined>;
|
|
9
|
+
exportById<T = "ed25519" | "x25519", Q = T extends "ed25519" ? Ed25519Keypair : X25519Keypair>(id: Uint8Array, type: T): Promise<Q | undefined>;
|
|
10
|
+
}
|
|
11
|
+
export declare class Libp2pKeychain implements Keychain {
|
|
12
|
+
readonly keychain: InternalKeychain;
|
|
13
|
+
readonly options?: {
|
|
14
|
+
cache?: Cache<Ed25519Keypair | X25519Keypair | null> | undefined;
|
|
15
|
+
} | undefined;
|
|
16
|
+
constructor(keychain: InternalKeychain, options?: {
|
|
17
|
+
cache?: Cache<Ed25519Keypair | X25519Keypair | null> | undefined;
|
|
18
|
+
} | undefined);
|
|
19
|
+
keychainKeyIdFromPublicKey(publicKey: X25519PublicKey): string;
|
|
20
|
+
private cacheKey;
|
|
21
|
+
private getCachedById;
|
|
22
|
+
private getCachedByKey;
|
|
23
|
+
exportByKey: <T extends Ed25519PublicKey | X25519PublicKey, Q = KeypairFromPublicKey<T>>(publicKey: T) => Promise<Q | undefined>;
|
|
24
|
+
exportById<T = "ed25519" | "x25519", Q = T extends "ed25519" ? Ed25519Keypair : X25519Keypair>(id: Uint8Array, type: T): Promise<Q | undefined>;
|
|
25
|
+
import: (keypair: Ed25519Keypair, id: Uint8Array) => Promise<void>;
|
|
26
|
+
getAnyKeypair: (publicKeys: any) => Promise<{
|
|
27
|
+
index: number;
|
|
28
|
+
keypair: X25519Keypair;
|
|
29
|
+
}>;
|
|
30
|
+
}
|