@peerbit/crypto
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -27,3 +27,3 @@ export * from "./errors.js"; | ||
getValue(clazz: AbstractType<T>): T; | ||
encrypt(x25519Keypair: X25519Keypair, ...recieverPublicKeys: (X25519PublicKey | Ed25519PublicKey)[]): Promise<EncryptedThing<T>>; | ||
encrypt(x25519Keypair: X25519Keypair, ...receiverPublicKeys: (X25519PublicKey | Ed25519PublicKey)[]): Promise<EncryptedThing<T>>; | ||
get decrypted(): DecryptedThing<T>; | ||
@@ -46,6 +46,6 @@ decrypt(): DecryptedThing<T>; | ||
_encryptedKey: CipherWithNonce; | ||
_recieverPublicKey: X25519PublicKey; | ||
_receiverPublicKey: X25519PublicKey; | ||
constructor(props?: { | ||
encryptedKey: CipherWithNonce; | ||
recieverPublicKey: X25519PublicKey; | ||
receiverPublicKey: X25519PublicKey; | ||
}); | ||
@@ -52,0 +52,0 @@ equals(other: K): boolean; |
@@ -62,3 +62,3 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
} | ||
async encrypt(x25519Keypair, ...recieverPublicKeys) { | ||
async encrypt(x25519Keypair, ...receiverPublicKeys) { | ||
const bytes = serialize(this); | ||
@@ -68,3 +68,3 @@ const epheremalKey = sodium.crypto_secretbox_keygen(); | ||
const cipher = sodium.crypto_secretbox_easy(bytes, nonce, epheremalKey); | ||
const recieverX25519PublicKeys = await Promise.all(recieverPublicKeys.map((key) => { | ||
const receiverX25519PublicKeys = await Promise.all(receiverPublicKeys.map((key) => { | ||
if (key instanceof Ed25519PublicKey) { | ||
@@ -75,10 +75,10 @@ return X25519PublicKey.from(key); | ||
})); | ||
const ks = recieverX25519PublicKeys.map((recieverPublicKey) => { | ||
const ks = receiverX25519PublicKeys.map((receiverPublicKey) => { | ||
const kNonce = randomBytes(NONCE_LENGTH); // crypto random is faster than sodium random | ||
return new K({ | ||
encryptedKey: new CipherWithNonce({ | ||
cipher: sodium.crypto_box_easy(epheremalKey, kNonce, recieverPublicKey.publicKey, x25519Keypair.secretKey.secretKey), | ||
cipher: sodium.crypto_box_easy(epheremalKey, kNonce, receiverPublicKey.publicKey, x25519Keypair.secretKey.secretKey), | ||
nonce: kNonce, | ||
}), | ||
recieverPublicKey, | ||
receiverPublicKey, | ||
}); | ||
@@ -158,7 +158,7 @@ }); | ||
_encryptedKey; | ||
_recieverPublicKey; | ||
_receiverPublicKey; | ||
constructor(props) { | ||
if (props) { | ||
this._encryptedKey = props.encryptedKey; | ||
this._recieverPublicKey = props.recieverPublicKey; | ||
this._receiverPublicKey = props.receiverPublicKey; | ||
} | ||
@@ -169,3 +169,3 @@ } | ||
return (this._encryptedKey.equals(other._encryptedKey) && | ||
this._recieverPublicKey.equals(other._recieverPublicKey)); | ||
this._receiverPublicKey.equals(other._receiverPublicKey)); | ||
} | ||
@@ -184,3 +184,3 @@ else { | ||
__metadata("design:type", X25519PublicKey) | ||
], K.prototype, "_recieverPublicKey", void 0); | ||
], K.prototype, "_receiverPublicKey", void 0); | ||
K = K_1 = __decorate([ | ||
@@ -261,3 +261,3 @@ variant(0), | ||
for (const [i, k] of this._envelope._ks.entries()) { | ||
if (k._recieverPublicKey.equals(keyResolver.publicKey)) { | ||
if (k._receiverPublicKey.equals(keyResolver.publicKey)) { | ||
key = { | ||
@@ -272,3 +272,3 @@ index: i, | ||
for (const [i, k] of this._envelope._ks.entries()) { | ||
const exported = await keyResolver.exportByKey(k._recieverPublicKey); | ||
const exported = await keyResolver.exportByKey(k._receiverPublicKey); | ||
if (exported) { | ||
@@ -275,0 +275,0 @@ key = { |
@@ -115,3 +115,3 @@ import { keysPBM } from "@libp2p/crypto/keys"; | ||
await this.keychain.importPeer(base58btc.encode(id), receiverKeyPeerId); | ||
// import as x so we can decrypt messages with this public key (if recieved any) | ||
// import as x so we can decrypt messages with this public key (if received any) | ||
const xKeypair = await X25519Keypair.from(keypair); | ||
@@ -118,0 +118,0 @@ this.cacheKey(xKeypair); |
{ | ||
"name": "@peerbit/crypto", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Crypto fn", | ||
@@ -54,3 +54,3 @@ "type": "module", | ||
}, | ||
"gitHead": "32f61ad9f3d5906e13d46f2a80f61c1826a3e817" | ||
"gitHead": "464e807d679e24b897b7811ac99d6f85fbd756f9" | ||
} |
@@ -74,3 +74,3 @@ export * from "./errors.js"; | ||
x25519Keypair: X25519Keypair, | ||
...recieverPublicKeys: (X25519PublicKey | Ed25519PublicKey)[] | ||
...receiverPublicKeys: (X25519PublicKey | Ed25519PublicKey)[] | ||
): Promise<EncryptedThing<T>> { | ||
@@ -82,4 +82,4 @@ const bytes = serialize(this); | ||
const recieverX25519PublicKeys = await Promise.all( | ||
recieverPublicKeys.map((key) => { | ||
const receiverX25519PublicKeys = await Promise.all( | ||
receiverPublicKeys.map((key) => { | ||
if (key instanceof Ed25519PublicKey) { | ||
@@ -92,3 +92,3 @@ return X25519PublicKey.from(key); | ||
const ks = recieverX25519PublicKeys.map((recieverPublicKey) => { | ||
const ks = receiverX25519PublicKeys.map((receiverPublicKey) => { | ||
const kNonce = randomBytes(NONCE_LENGTH); // crypto random is faster than sodium random | ||
@@ -100,3 +100,3 @@ return new K({ | ||
kNonce, | ||
recieverPublicKey.publicKey, | ||
receiverPublicKey.publicKey, | ||
x25519Keypair.secretKey.secretKey | ||
@@ -106,3 +106,3 @@ ), | ||
}), | ||
recieverPublicKey, | ||
receiverPublicKey, | ||
}); | ||
@@ -180,11 +180,11 @@ }); | ||
@field({ type: X25519PublicKey }) | ||
_recieverPublicKey: X25519PublicKey; | ||
_receiverPublicKey: X25519PublicKey; | ||
constructor(props?: { | ||
encryptedKey: CipherWithNonce; | ||
recieverPublicKey: X25519PublicKey; | ||
receiverPublicKey: X25519PublicKey; | ||
}) { | ||
if (props) { | ||
this._encryptedKey = props.encryptedKey; | ||
this._recieverPublicKey = props.recieverPublicKey; | ||
this._receiverPublicKey = props.receiverPublicKey; | ||
} | ||
@@ -197,3 +197,3 @@ } | ||
this._encryptedKey.equals(other._encryptedKey) && | ||
this._recieverPublicKey.equals(other._recieverPublicKey) | ||
this._receiverPublicKey.equals(other._receiverPublicKey) | ||
); | ||
@@ -291,3 +291,3 @@ } else { | ||
for (const [i, k] of this._envelope._ks.entries()) { | ||
if (k._recieverPublicKey.equals(keyResolver.publicKey)) { | ||
if (k._receiverPublicKey.equals(keyResolver.publicKey)) { | ||
key = { | ||
@@ -301,3 +301,3 @@ index: i, | ||
for (const [i, k] of this._envelope._ks.entries()) { | ||
const exported = await keyResolver.exportByKey(k._recieverPublicKey); | ||
const exported = await keyResolver.exportByKey(k._receiverPublicKey); | ||
if (exported) { | ||
@@ -304,0 +304,0 @@ key = { |
@@ -168,3 +168,3 @@ import { KeyChain as InternalKeychain } from "@libp2p/interface-keychain"; | ||
// import as x so we can decrypt messages with this public key (if recieved any) | ||
// import as x so we can decrypt messages with this public key (if received any) | ||
const xKeypair = await X25519Keypair.from(keypair); | ||
@@ -171,0 +171,0 @@ this.cacheKey(xKeypair); |