@near-js/crypto
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -14,3 +14,3 @@ import { KeyPairBase, Signature } from './key_pair_base'; | ||
* It's generally assumed that these are encoded in base58. | ||
* @param {string} extendedSecretKey | ||
* @param extendedSecretKey | ||
*/ | ||
@@ -29,7 +29,26 @@ constructor(extendedSecretKey: string); | ||
static fromRandom(): KeyPairEd25519; | ||
/** | ||
* Signs a message using the key pair's secret key. | ||
* @param message The message to be signed. | ||
* @returns {Signature} The signature object containing the signature and the public key. | ||
*/ | ||
sign(message: Uint8Array): Signature; | ||
/** | ||
* Verifies the signature of a message using the key pair's public key. | ||
* @param message The message to be verified. | ||
* @param signature The signature to be verified. | ||
* @returns {boolean} `true` if the signature is valid, otherwise `false`. | ||
*/ | ||
verify(message: Uint8Array, signature: Uint8Array): boolean; | ||
/** | ||
* Returns a string representation of the key pair in the format 'ed25519:[extendedSecretKey]'. | ||
* @returns {string} The string representation of the key pair. | ||
*/ | ||
toString(): string; | ||
/** | ||
* Retrieves the public key associated with the key pair. | ||
* @returns {PublicKey} The public key. | ||
*/ | ||
getPublicKey(): PublicKey; | ||
} | ||
//# sourceMappingURL=key_pair_ed25519.d.ts.map |
@@ -21,3 +21,3 @@ "use strict"; | ||
* It's generally assumed that these are encoded in base58. | ||
* @param {string} extendedSecretKey | ||
* @param extendedSecretKey | ||
*/ | ||
@@ -45,6 +45,11 @@ constructor(extendedSecretKey) { | ||
const secretKey = (0, randombytes_1.default)(constants_1.KeySize.SECRET_KEY); | ||
const publicKey = ed25519_1.ed25519.getPublicKey(secretKey); | ||
const publicKey = ed25519_1.ed25519.getPublicKey(new Uint8Array(secretKey)); | ||
const extendedSecretKey = new Uint8Array([...secretKey, ...publicKey]); | ||
return new KeyPairEd25519((0, utils_1.baseEncode)(extendedSecretKey)); | ||
} | ||
/** | ||
* Signs a message using the key pair's secret key. | ||
* @param message The message to be signed. | ||
* @returns {Signature} The signature object containing the signature and the public key. | ||
*/ | ||
sign(message) { | ||
@@ -54,8 +59,22 @@ const signature = ed25519_1.ed25519.sign(message, (0, utils_1.baseDecode)(this.secretKey)); | ||
} | ||
/** | ||
* Verifies the signature of a message using the key pair's public key. | ||
* @param message The message to be verified. | ||
* @param signature The signature to be verified. | ||
* @returns {boolean} `true` if the signature is valid, otherwise `false`. | ||
*/ | ||
verify(message, signature) { | ||
return this.publicKey.verify(message, signature); | ||
} | ||
/** | ||
* Returns a string representation of the key pair in the format 'ed25519:[extendedSecretKey]'. | ||
* @returns {string} The string representation of the key pair. | ||
*/ | ||
toString() { | ||
return `ed25519:${this.extendedSecretKey}`; | ||
} | ||
/** | ||
* Retrieves the public key associated with the key pair. | ||
* @returns {PublicKey} The public key. | ||
*/ | ||
getPublicKey() { | ||
@@ -62,0 +81,0 @@ return this.publicKey; |
@@ -8,4 +8,9 @@ import { KeyPairBase } from './key_pair_base'; | ||
static fromRandom(curve: string): KeyPair; | ||
/** | ||
* Creates a key pair from an encoded key string. | ||
* @param encodedKey The encoded key string. | ||
* @returns {KeyPair} The key pair created from the encoded key string. | ||
*/ | ||
static fromString(encodedKey: string): KeyPair; | ||
} | ||
//# sourceMappingURL=key_pair.d.ts.map |
@@ -17,2 +17,7 @@ "use strict"; | ||
} | ||
/** | ||
* Creates a key pair from an encoded key string. | ||
* @param encodedKey The encoded key string. | ||
* @returns {KeyPair} The key pair created from the encoded key string. | ||
*/ | ||
static fromString(encodedKey) { | ||
@@ -19,0 +24,0 @@ const parts = encodedKey.split(':'); |
@@ -9,7 +9,27 @@ import { Assignable } from '@near-js/types'; | ||
data: Uint8Array; | ||
/** | ||
* Creates a PublicKey instance from a string or an existing PublicKey instance. | ||
* @param value The string or PublicKey instance to create a PublicKey from. | ||
* @returns {PublicKey} The PublicKey instance. | ||
*/ | ||
static from(value: string | PublicKey): PublicKey; | ||
/** | ||
* Creates a PublicKey instance from an encoded key string. | ||
* @param encodedKey The encoded key string. | ||
* @returns {PublicKey} The PublicKey instance created from the encoded key string. | ||
*/ | ||
static fromString(encodedKey: string): PublicKey; | ||
/** | ||
* Returns a string representation of the public key. | ||
* @returns {string} The string representation of the public key. | ||
*/ | ||
toString(): string; | ||
/** | ||
* Verifies a message signature using the public key. | ||
* @param message The message to be verified. | ||
* @param signature The signature to be verified. | ||
* @returns {boolean} `true` if the signature is valid, otherwise `false`. | ||
*/ | ||
verify(message: Uint8Array, signature: Uint8Array): boolean; | ||
} | ||
//# sourceMappingURL=public_key.d.ts.map |
@@ -24,2 +24,7 @@ "use strict"; | ||
class PublicKey extends types_1.Assignable { | ||
/** | ||
* Creates a PublicKey instance from a string or an existing PublicKey instance. | ||
* @param value The string or PublicKey instance to create a PublicKey from. | ||
* @returns {PublicKey} The PublicKey instance. | ||
*/ | ||
static from(value) { | ||
@@ -31,2 +36,7 @@ if (typeof value === 'string') { | ||
} | ||
/** | ||
* Creates a PublicKey instance from an encoded key string. | ||
* @param encodedKey The encoded key string. | ||
* @returns {PublicKey} The PublicKey instance created from the encoded key string. | ||
*/ | ||
static fromString(encodedKey) { | ||
@@ -52,5 +62,15 @@ const parts = encodedKey.split(':'); | ||
} | ||
/** | ||
* Returns a string representation of the public key. | ||
* @returns {string} The string representation of the public key. | ||
*/ | ||
toString() { | ||
return `${key_type_to_str(this.keyType)}:${(0, utils_1.baseEncode)(this.data)}`; | ||
} | ||
/** | ||
* Verifies a message signature using the public key. | ||
* @param message The message to be verified. | ||
* @param signature The signature to be verified. | ||
* @returns {boolean} `true` if the signature is valid, otherwise `false`. | ||
*/ | ||
verify(message, signature) { | ||
@@ -57,0 +77,0 @@ switch (this.keyType) { |
{ | ||
"name": "@near-js/crypto", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Abstractions around NEAR-compatible elliptical curves and cryptographic keys", | ||
@@ -15,3 +15,3 @@ "main": "lib/index.js", | ||
"@near-js/types": "0.0.4", | ||
"@near-js/utils": "0.0.5" | ||
"@near-js/utils": "0.1.0" | ||
}, | ||
@@ -18,0 +18,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19570
349
+ Added@near-js/utils@0.1.0(transitive)
- Removed@near-js/utils@0.0.5(transitive)
Updated@near-js/utils@0.1.0