Module curve25519/ed25519
source · [−]Expand description
Code related to Ed25519
Functions
sourceexportKey
exportKey
source(format: KeyFormat, key: Ed25519PubCryptoKey | Ed25519PrivCryptoKey): Promise<ArrayBuffer | JsonWebKey>
(format: KeyFormat, key: Ed25519PubCryptoKey | Ed25519PrivCryptoKey): Promise<ArrayBuffer | JsonWebKey>
Export an Ed25519 public or private key
exampleconst pubKeyJwk = await Ed25519.exportKey("jwk", keyPair.publicKey.self);
exampleconst privKeyJwk = await Ed25519.exportKey("jwk", keyPair.privateKey.self);
exampleconst pubKeyJwk = await keyPair.publicKey.exportKey("jwk");
exampleconst privKeyJwk = await keyPair.privateKey.exportKey("jwk");
Parameters
format: KeyFormat
key: Ed25519PubCryptoKey | Ed25519PrivCryptoKey
Returns Promise<ArrayBuffer | JsonWebKey>
sourcegenerateKey
generateKey
source(extractable?: boolean, keyUsages?: KeyUsage[]): Promise<Ed25519ProxiedCryptoKeyPair>
(extractable?: boolean, keyUsages?: KeyUsage[]): Promise<Ed25519ProxiedCryptoKeyPair>
Generate a new Ed25519 keypair
exampleconst keyPair = await Ed25519.generateKey();
exampleconst keyPair = await Ed25519.generateKey(false);
exampleconst keyPair = await Ed25519.generateKey(true, ['sign', 'verify']);
Parameters
Optional extractable: boolean
Optional keyUsages: KeyUsage[]
Returns Promise<Ed25519ProxiedCryptoKeyPair>
sourcegenerateKeyPair
generateKeyPair
source(extractable?: boolean, keyUsages?: KeyUsage[]): Promise<Ed25519ProxiedCryptoKeyPair>
(extractable?: boolean, keyUsages?: KeyUsage[]): Promise<Ed25519ProxiedCryptoKeyPair>
Generate a new Ed25519 keypair
aliasgenerateKey
exampleconst keyPair = await Ed25519.generateKeyPair();
exampleconst keyPair = await Ed25519.generateKeyPair(false);
exampleconst keyPair = await Ed25519.generateKeyPair(true, ['sign', 'verify']);
Parameters
Optional extractable: boolean
Optional keyUsages: KeyUsage[]
Returns Promise<Ed25519ProxiedCryptoKeyPair>
sourceimportKey
importKey
source(format: KeyFormat, key: BufferSource | JsonWebKey, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<Ed25519ProxiedPubCryptoKey | Ed25519ProxiedPrivCryptoKey>
(format: KeyFormat, key: BufferSource | JsonWebKey, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<Ed25519ProxiedPubCryptoKey | Ed25519ProxiedPrivCryptoKey>
Import an Ed25519 public or private key
exampleconst pubKey = await Ed25519.importKey("jwk", pubKeyJwk, true, ['verify']);
exampleconst privKey = await Ed25519.importKey("jwk", privKeyJwk, true, ['sign']);
Parameters
format: KeyFormat
key: BufferSource | JsonWebKey
Optional extractable: boolean
Optional keyUsages: KeyUsage[]
Returns Promise<Ed25519ProxiedPubCryptoKey | Ed25519ProxiedPrivCryptoKey>
sourcesign
sign
source(key: Ed25519PrivCryptoKey, data: BufferSource): Promise<ArrayBuffer>
(key: Ed25519PrivCryptoKey, data: BufferSource): Promise<ArrayBuffer>
Sign a given payload
exampleconst message = new TextEncoder().encode("a message");
const signature = await Ed25519.sign(keyPair.privateKey.self, message);
exampleconst message = new TextEncoder().encode("a message");
const signature = await keyPair.privateKey.sign(message);
Parameters
key: Ed25519PrivCryptoKey
data: BufferSource
Returns Promise<ArrayBuffer>
sourceverify
verify
source(key: Ed25519PubCryptoKey, signature: BufferSource, data: BufferSource): Promise<boolean>
(key: Ed25519PubCryptoKey, signature: BufferSource, data: BufferSource): Promise<boolean>
Verify a given signature
exampleconst message = new TextEncoder().encode("a message");
const isVerified = await Ed25519.verify(keyPair.publicKey.self, signature, message);
exampleconst message = new TextEncoder().encode("a message");
const isVerified = await keyPair.publicKey.verify(signature, message);
Parameters
key: Ed25519PubCryptoKey
signature: BufferSource
data: BufferSource