@substrate-system/keys 0.2.34 → 0.2.37
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/README.md +188 -15
- package/dist/_base.cjs.map +1 -1
- package/dist/_base.d.ts +4 -4
- package/dist/_base.d.ts.map +1 -1
- package/dist/_base.js.map +1 -1
- package/dist/_base.min.cjs +1 -1
- package/dist/_base.min.cjs.map +1 -1
- package/dist/_base.min.js +2 -2
- package/dist/_base.min.js.map +3 -3
- package/dist/aes/index.cjs +10 -7
- package/dist/aes/index.cjs.map +2 -2
- package/dist/aes/index.d.ts.map +1 -1
- package/dist/aes/index.js +10 -7
- package/dist/aes/index.js.map +2 -2
- package/dist/aes/index.min.cjs +1 -1
- package/dist/aes/index.min.cjs.map +2 -2
- package/dist/aes/index.min.js +2 -2
- package/dist/aes/index.min.js.map +3 -3
- package/dist/browser/index.js +180 -54
- package/dist/browser/index.min.js +2 -2
- package/dist/constants.cjs +7 -9
- package/dist/constants.cjs.map +2 -2
- package/dist/constants.d.ts +3 -4
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +7 -9
- package/dist/constants.js.map +2 -2
- package/dist/constants.min.cjs +1 -1
- package/dist/constants.min.cjs.map +3 -3
- package/dist/constants.min.js +1 -1
- package/dist/constants.min.js.map +3 -3
- package/dist/crypto.min.js +2 -2
- package/dist/crypto.min.js.map +3 -3
- package/dist/ecc/index.cjs +164 -39
- package/dist/ecc/index.cjs.map +2 -2
- package/dist/ecc/index.d.ts +62 -22
- package/dist/ecc/index.d.ts.map +1 -1
- package/dist/ecc/index.js +168 -44
- package/dist/ecc/index.js.map +2 -2
- package/dist/ecc/index.min.cjs +1 -1
- package/dist/ecc/index.min.cjs.map +3 -3
- package/dist/ecc/index.min.js +2 -2
- package/dist/ecc/index.min.js.map +3 -3
- package/dist/errors.min.js +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +3 -3
- package/dist/meta.json +22 -23
- package/dist/rsa/index.cjs.map +2 -2
- package/dist/rsa/index.d.ts.map +1 -1
- package/dist/rsa/index.js.map +2 -2
- package/dist/rsa/index.min.cjs.map +2 -2
- package/dist/rsa/index.min.js +2 -2
- package/dist/rsa/index.min.js.map +3 -3
- package/dist/types.cjs.map +2 -2
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +2 -2
- package/dist/types.min.cjs +1 -1
- package/dist/types.min.cjs.map +2 -2
- package/dist/types.min.js +1 -1
- package/dist/types.min.js.map +2 -2
- package/dist/util.min.js +1 -1
- package/dist/util.min.js.map +3 -3
- package/package.json +4 -10
package/dist/browser/index.js
CHANGED
|
@@ -2379,10 +2379,8 @@
|
|
|
2379
2379
|
DEFAULT_RSA_WRITE: () => DEFAULT_RSA_WRITE,
|
|
2380
2380
|
DEFAULT_SYMM_ALGORITHM: () => DEFAULT_SYMM_ALGORITHM,
|
|
2381
2381
|
DEFAULT_SYMM_LENGTH: () => DEFAULT_SYMM_LENGTH,
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
ECC_WRITE_ALG: () => ECC_WRITE_ALG,
|
|
2385
|
-
ECC_WRITE_NAME: () => ECC_WRITE_NAME,
|
|
2382
|
+
ECC_EXCHANGE_ALGORITHM: () => ECC_EXCHANGE_ALGORITHM,
|
|
2383
|
+
ECC_WRITE_ALGORITHM: () => ECC_WRITE_ALGORITHM,
|
|
2386
2384
|
EDWARDS_DID_PREFIX: () => EDWARDS_DID_PREFIX,
|
|
2387
2385
|
IV_LENGTH: () => IV_LENGTH,
|
|
2388
2386
|
KEY_TYPE: () => KEY_TYPE,
|
|
@@ -2393,6 +2391,7 @@
|
|
|
2393
2391
|
RSA_SIGN_ALGORITHM: () => RSA_SIGN_ALGORITHM,
|
|
2394
2392
|
RsaKeys: () => RsaKeys,
|
|
2395
2393
|
SALT_LENGTH: () => SALT_LENGTH,
|
|
2394
|
+
X25519_PUBLIC_KEY_LENGTH: () => X25519_PUBLIC_KEY_LENGTH,
|
|
2396
2395
|
encrypt: () => encrypt2,
|
|
2397
2396
|
encryptKeyTo: () => encryptKeyTo2,
|
|
2398
2397
|
encryptTo: () => encryptTo2,
|
|
@@ -3675,11 +3674,10 @@
|
|
|
3675
3674
|
|
|
3676
3675
|
// src/constants.ts
|
|
3677
3676
|
var BASE58_DID_PREFIX = "did:key:z";
|
|
3678
|
-
var
|
|
3679
|
-
var
|
|
3677
|
+
var ECC_WRITE_ALGORITHM = "Ed25519";
|
|
3678
|
+
var ECC_EXCHANGE_ALGORITHM = "X25519";
|
|
3680
3679
|
var DEFAULT_ECC_EXCHANGE_CURVE = "X25519" /* X25519 */;
|
|
3681
|
-
var
|
|
3682
|
-
var ECC_EXCHANGE_NAME = "X25519" /* X25519 */;
|
|
3680
|
+
var X25519_PUBLIC_KEY_LENGTH = 32;
|
|
3683
3681
|
var KEY_USE = {
|
|
3684
3682
|
sign: ["sign", "verify"],
|
|
3685
3683
|
encrypt: ["deriveKey", "deriveBits"]
|
|
@@ -4227,13 +4225,16 @@
|
|
|
4227
4225
|
__name(importAesKey, "importAesKey");
|
|
4228
4226
|
async function encrypt(data, cryptoKey, format2, iv) {
|
|
4229
4227
|
const key = isCryptoKey(cryptoKey) ? cryptoKey : await importAesKey(cryptoKey);
|
|
4230
|
-
const encrypted = iv ?
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4228
|
+
const encrypted = iv ? (
|
|
4229
|
+
// was an `iv` passed in? then encrypt here
|
|
4230
|
+
await webcrypto.subtle.encrypt(
|
|
4231
|
+
{
|
|
4232
|
+
name: AES_GCM,
|
|
4233
|
+
iv: toArrayBuffer(iv)
|
|
4234
|
+
},
|
|
4235
|
+
key,
|
|
4236
|
+
data instanceof ArrayBuffer ? data : toArrayBuffer(typeof data === "string" ? fromString2(data) : data)
|
|
4237
|
+
)
|
|
4237
4238
|
) : await encryptBytes(data, key);
|
|
4238
4239
|
if (format2 && format2 === "arraybuffer") return encrypted;
|
|
4239
4240
|
return new Uint8Array(encrypted);
|
|
@@ -4864,7 +4865,7 @@
|
|
|
4864
4865
|
static async _createExchangeKeys(extractable = false) {
|
|
4865
4866
|
return await webcrypto.subtle.generateKey(
|
|
4866
4867
|
{
|
|
4867
|
-
name:
|
|
4868
|
+
name: ECC_EXCHANGE_ALGORITHM
|
|
4868
4869
|
// namedCurve: EccCurve.X25519
|
|
4869
4870
|
},
|
|
4870
4871
|
extractable,
|
|
@@ -4874,7 +4875,7 @@
|
|
|
4874
4875
|
static async _createWriteKeys(extractable = false) {
|
|
4875
4876
|
return await webcrypto.subtle.generateKey(
|
|
4876
4877
|
{
|
|
4877
|
-
name:
|
|
4878
|
+
name: ECC_WRITE_ALGORITHM
|
|
4878
4879
|
},
|
|
4879
4880
|
extractable,
|
|
4880
4881
|
["sign", "verify"]
|
|
@@ -4911,21 +4912,124 @@
|
|
|
4911
4912
|
DID: did2
|
|
4912
4913
|
};
|
|
4913
4914
|
}
|
|
4915
|
+
/**
|
|
4916
|
+
* "Add a device," meaning, take an existing AES key and add the ability
|
|
4917
|
+
* for a new keypair to decrypt/use the AES key.
|
|
4918
|
+
*
|
|
4919
|
+
* This implements HPKE-style key wrapping:
|
|
4920
|
+
* 1. Generate ephemeral X25519 keypair
|
|
4921
|
+
* 2. Do ECDH with recipient's public key -> shared secret
|
|
4922
|
+
* 3. Use HKDF to derive a KEK (key encryption key)
|
|
4923
|
+
* 4. AES-GCM encrypt the content
|
|
4924
|
+
* 5. Return the ephemeral public key (encapsulation) + wrapped key
|
|
4925
|
+
*
|
|
4926
|
+
* @param {SymmKey|Uint8Array|string} contentKey The existing AES key used
|
|
4927
|
+
* to encrypt the content. Can be a base64 encoded string.
|
|
4928
|
+
* @param {CryptoKey} newPublicKey The new device's public X25519 key.
|
|
4929
|
+
* @param {string} [info] Optional info parameter for HKDF.
|
|
4930
|
+
* Defaults to 'key-wrap'.
|
|
4931
|
+
* @returns {Promise<WrappedKey>} The ephemeral public key (base64) and
|
|
4932
|
+
* the wrapped AES key (base64).
|
|
4933
|
+
*/
|
|
4934
|
+
async wrap(contentKey, newPublicKey, info) {
|
|
4935
|
+
const ephemeralKeypair = await _EccKeys._createExchangeKeys(true);
|
|
4936
|
+
const salt = crypto.getRandomValues(new Uint8Array(SALT_LENGTH));
|
|
4937
|
+
const kek = await deriveKey(
|
|
4938
|
+
ephemeralKeypair.privateKey,
|
|
4939
|
+
newPublicKey,
|
|
4940
|
+
salt,
|
|
4941
|
+
info || "key-wrap"
|
|
4942
|
+
);
|
|
4943
|
+
let contentKeyBytes;
|
|
4944
|
+
if (contentKey instanceof CryptoKey) {
|
|
4945
|
+
const exported = await crypto.subtle.exportKey("raw", contentKey);
|
|
4946
|
+
contentKeyBytes = new Uint8Array(exported);
|
|
4947
|
+
} else if (typeof contentKey === "string") {
|
|
4948
|
+
contentKeyBytes = fromString2(contentKey, "base64pad");
|
|
4949
|
+
} else {
|
|
4950
|
+
contentKeyBytes = contentKey;
|
|
4951
|
+
}
|
|
4952
|
+
const iv = crypto.getRandomValues(new Uint8Array(IV_LENGTH));
|
|
4953
|
+
const wrappedKeyBuffer = await crypto.subtle.encrypt(
|
|
4954
|
+
{ name: DEFAULT_SYMM_ALGORITHM, iv },
|
|
4955
|
+
kek,
|
|
4956
|
+
toArrayBuffer3(contentKeyBytes)
|
|
4957
|
+
);
|
|
4958
|
+
const ephemeralPubKeyBuffer = await exportPublicKey(ephemeralKeypair);
|
|
4959
|
+
const saltBuf = new Uint8Array(salt);
|
|
4960
|
+
const ivBuf = new Uint8Array(iv);
|
|
4961
|
+
const wrappedBuf = new Uint8Array(wrappedKeyBuffer);
|
|
4962
|
+
const combinedSize = saltBuf.length + ivBuf.length + wrappedBuf.length;
|
|
4963
|
+
const combined = new Uint8Array(combinedSize);
|
|
4964
|
+
combined.set(saltBuf, 0);
|
|
4965
|
+
combined.set(ivBuf, saltBuf.length);
|
|
4966
|
+
combined.set(wrappedBuf, saltBuf.length + ivBuf.length);
|
|
4967
|
+
return {
|
|
4968
|
+
enc: toBase64(new Uint8Array(ephemeralPubKeyBuffer)),
|
|
4969
|
+
wrappedKey: toBase64(combined)
|
|
4970
|
+
};
|
|
4971
|
+
}
|
|
4972
|
+
/**
|
|
4973
|
+
* Unwrap a content key that was wrapped for this device using the `add` method.
|
|
4974
|
+
*
|
|
4975
|
+
* The recipient device uses its private key + the ephemeral public key
|
|
4976
|
+
* to rederive the KEK and decrypt the wrapped content key.
|
|
4977
|
+
*
|
|
4978
|
+
* @param enc The ephemeral public key (base64) from the sender.
|
|
4979
|
+
* @param wrappedKey The wrapped content key (base64) - contains salt + iv + ciphertext.
|
|
4980
|
+
* @param info Optional info parameter for HKDF. Must match what was used in `add`. Defaults to 'key-wrap'.
|
|
4981
|
+
* @returns {Promise<CryptoKey>} The unwrapped AES content key.
|
|
4982
|
+
*/
|
|
4983
|
+
async unwrap(enc, wrappedKey, info) {
|
|
4984
|
+
const ephemeralPubKey = await importPublicKey(
|
|
4985
|
+
enc,
|
|
4986
|
+
"X25519" /* X25519 */,
|
|
4987
|
+
"exchange" /* Exchange */
|
|
4988
|
+
);
|
|
4989
|
+
const wrappedBuf = new Uint8Array(base64ToArrBuf(wrappedKey));
|
|
4990
|
+
const salt = wrappedBuf.slice(0, SALT_LENGTH);
|
|
4991
|
+
const iv = wrappedBuf.slice(SALT_LENGTH, SALT_LENGTH + IV_LENGTH);
|
|
4992
|
+
const ciphertext = wrappedBuf.slice(SALT_LENGTH + IV_LENGTH);
|
|
4993
|
+
const kek = await deriveKey(
|
|
4994
|
+
this.exchangeKey.privateKey,
|
|
4995
|
+
ephemeralPubKey,
|
|
4996
|
+
salt,
|
|
4997
|
+
info || "key-wrap"
|
|
4998
|
+
);
|
|
4999
|
+
const contentKeyBytes = await crypto.subtle.decrypt(
|
|
5000
|
+
{ name: DEFAULT_SYMM_ALGORITHM, iv },
|
|
5001
|
+
kek,
|
|
5002
|
+
toArrayBuffer3(ciphertext)
|
|
5003
|
+
);
|
|
5004
|
+
const contentKey = await crypto.subtle.importKey(
|
|
5005
|
+
"raw",
|
|
5006
|
+
contentKeyBytes,
|
|
5007
|
+
{ name: DEFAULT_SYMM_ALGORITHM },
|
|
5008
|
+
true,
|
|
5009
|
+
["encrypt", "decrypt"]
|
|
5010
|
+
);
|
|
5011
|
+
return contentKey;
|
|
5012
|
+
}
|
|
4914
5013
|
/**
|
|
4915
5014
|
* Encrypt the given content to the given public key, or encrypt to
|
|
4916
|
-
* our public key if
|
|
5015
|
+
* our own public key if a key is not passed in.
|
|
5016
|
+
*
|
|
5017
|
+
* This does ECIES style encryption -- a new ephemeral keypair is generated
|
|
5018
|
+
* and used to encrypt the message with ephemeral private + recipient public.
|
|
5019
|
+
* The public key from the ephemeral keypair is prefixed to the cipher text.
|
|
4917
5020
|
*
|
|
4918
5021
|
* @param {string|Uint8Array} content Content to encrypt
|
|
4919
5022
|
* @param {CryptoKey|string} [recipient] Their public key. Optional b/c we
|
|
4920
|
-
* will use our own public key if not passed in.
|
|
5023
|
+
* will use our own public key if not passed in. Can be a CryptoKey
|
|
5024
|
+
* or a base64 encoded string.
|
|
4921
5025
|
* @param {string} [info] info tag for HKDF. Default is the class property.
|
|
4922
|
-
* @param {SymmKey|Uint8Array|string} aesKey This is not relevant for most
|
|
5026
|
+
* @param {SymmKey|Uint8Array|string} [aesKey] This is not relevant for most
|
|
4923
5027
|
* use cases.
|
|
4924
5028
|
* @param {SymmKeyLength} [keysize] Default is 256
|
|
4925
|
-
* @returns {Promise<ArrayBuffer>} Buffer of
|
|
5029
|
+
* @returns {Promise<ArrayBuffer>} Buffer of ephemeral-public-key + salt +
|
|
5030
|
+
* iv + cipher text
|
|
4926
5031
|
*/
|
|
4927
5032
|
async encrypt(content, recipient, info, aesKey, keysize) {
|
|
4928
|
-
const encoder = new TextEncoder();
|
|
4929
5033
|
const salt = crypto.getRandomValues(new Uint8Array(SALT_LENGTH));
|
|
4930
5034
|
const _publicKey = recipient || this.exchangeKey.publicKey;
|
|
4931
5035
|
let publicKey;
|
|
@@ -4938,8 +5042,10 @@
|
|
|
4938
5042
|
} else {
|
|
4939
5043
|
publicKey = _publicKey;
|
|
4940
5044
|
}
|
|
5045
|
+
const ephemeralKeypair = await _EccKeys._createExchangeKeys(true);
|
|
4941
5046
|
let key = aesKey || await deriveKey(
|
|
4942
|
-
|
|
5047
|
+
ephemeralKeypair.privateKey,
|
|
5048
|
+
// use ephemeral private key
|
|
4943
5049
|
publicKey,
|
|
4944
5050
|
salt,
|
|
4945
5051
|
info || _EccKeys.INFO,
|
|
@@ -4947,27 +5053,32 @@
|
|
|
4947
5053
|
);
|
|
4948
5054
|
if (!(key instanceof CryptoKey)) {
|
|
4949
5055
|
key = await deriveKey(
|
|
4950
|
-
|
|
5056
|
+
ephemeralKeypair.privateKey,
|
|
5057
|
+
// use ephemeral private key
|
|
4951
5058
|
publicKey,
|
|
4952
5059
|
salt,
|
|
4953
5060
|
info || _EccKeys.INFO
|
|
4954
5061
|
);
|
|
4955
5062
|
}
|
|
4956
5063
|
const iv = crypto.getRandomValues(new Uint8Array(IV_LENGTH));
|
|
4957
|
-
const plaintext = typeof content === "string" ?
|
|
5064
|
+
const plaintext = typeof content === "string" ? new TextEncoder().encode(content) : content;
|
|
4958
5065
|
const ciphertext = await crypto.subtle.encrypt(
|
|
4959
5066
|
{ name: DEFAULT_SYMM_ALGORITHM, iv },
|
|
4960
5067
|
key,
|
|
4961
5068
|
toArrayBuffer3(plaintext)
|
|
4962
5069
|
);
|
|
5070
|
+
const ephemeralPubKeyBuf = new Uint8Array(
|
|
5071
|
+
await exportPublicKey(ephemeralKeypair)
|
|
5072
|
+
);
|
|
4963
5073
|
const saltBuffer = new Uint8Array(salt);
|
|
4964
5074
|
const ivBuffer = new Uint8Array(iv);
|
|
4965
5075
|
const cipherBuf = new Uint8Array(ciphertext);
|
|
4966
|
-
const size = saltBuffer.length + ivBuffer.length + cipherBuf.length;
|
|
5076
|
+
const size = ephemeralPubKeyBuf.length + saltBuffer.length + ivBuffer.length + cipherBuf.length;
|
|
4967
5077
|
const result = new Uint8Array(size);
|
|
4968
|
-
result.set(
|
|
4969
|
-
result.set(
|
|
4970
|
-
result.set(
|
|
5078
|
+
result.set(ephemeralPubKeyBuf, 0);
|
|
5079
|
+
result.set(saltBuffer, ephemeralPubKeyBuf.length);
|
|
5080
|
+
result.set(ivBuffer, ephemeralPubKeyBuf.length + saltBuffer.length);
|
|
5081
|
+
result.set(cipherBuf, ephemeralPubKeyBuf.length + saltBuffer.length + ivBuffer.length);
|
|
4971
5082
|
return result;
|
|
4972
5083
|
}
|
|
4973
5084
|
/**
|
|
@@ -4985,26 +5096,41 @@
|
|
|
4985
5096
|
}
|
|
4986
5097
|
/**
|
|
4987
5098
|
* Decrypt the given message. The encrypted message should be
|
|
4988
|
-
* salt + iv + cipher text.
|
|
5099
|
+
* ephemeral public key + salt + iv + cipher text.
|
|
5100
|
+
*
|
|
5101
|
+
* The ephemeral public key is extracted from the beginning of the message
|
|
5102
|
+
* and used with our private key to derive the AES decryption key.
|
|
5103
|
+
*
|
|
4989
5104
|
* @param msg The encrypted content
|
|
4990
|
-
* @param {CryptoKey|string} [publicKey] The public key used to generate
|
|
4991
|
-
* the AES key used on this message. If omitted, decrypt with our own
|
|
4992
|
-
* public key.
|
|
4993
5105
|
* @param {string} aesAlgorithm The algorithm. Default is AES-GCM.
|
|
4994
5106
|
* @param {string} info Custom "info" parameter
|
|
4995
5107
|
* @returns {Promise<ArrayBuffer>} The decrypted content.
|
|
4996
5108
|
*/
|
|
4997
|
-
async decrypt(msg,
|
|
4998
|
-
let pub = typeof publicKey === "string" ? await importPublicKey(publicKey, "X25519" /* X25519 */, "write" /* Write */) : publicKey;
|
|
4999
|
-
if (!pub) pub = this.publicExchangeKey;
|
|
5109
|
+
async decrypt(msg, aesAlgorithm, info) {
|
|
5000
5110
|
const encrypted = normalizeToBuf(msg, base64ToArrBuf);
|
|
5001
|
-
const
|
|
5002
|
-
const
|
|
5003
|
-
|
|
5111
|
+
const ephemeralPubKeyBuf = encrypted.slice(0, X25519_PUBLIC_KEY_LENGTH);
|
|
5112
|
+
const ephemeralPublicKey = await webcrypto.subtle.importKey(
|
|
5113
|
+
"raw",
|
|
5114
|
+
ephemeralPubKeyBuf,
|
|
5115
|
+
{ name: ECC_EXCHANGE_ALGORITHM },
|
|
5116
|
+
true,
|
|
5117
|
+
[]
|
|
5118
|
+
);
|
|
5119
|
+
const salt = encrypted.slice(
|
|
5120
|
+
X25519_PUBLIC_KEY_LENGTH,
|
|
5121
|
+
X25519_PUBLIC_KEY_LENGTH + SALT_LENGTH
|
|
5122
|
+
);
|
|
5123
|
+
const iv = encrypted.slice(
|
|
5124
|
+
X25519_PUBLIC_KEY_LENGTH + SALT_LENGTH,
|
|
5125
|
+
X25519_PUBLIC_KEY_LENGTH + SALT_LENGTH + IV_LENGTH
|
|
5126
|
+
);
|
|
5127
|
+
const ciphertext = encrypted.slice(
|
|
5128
|
+
X25519_PUBLIC_KEY_LENGTH + SALT_LENGTH + IV_LENGTH
|
|
5129
|
+
);
|
|
5004
5130
|
const { privateKey } = this.exchangeKey;
|
|
5005
5131
|
const key = await deriveKey(
|
|
5006
5132
|
privateKey,
|
|
5007
|
-
|
|
5133
|
+
ephemeralPublicKey,
|
|
5008
5134
|
salt,
|
|
5009
5135
|
info || _EccKeys.INFO
|
|
5010
5136
|
);
|
|
@@ -5019,19 +5145,19 @@
|
|
|
5019
5145
|
return decrypted;
|
|
5020
5146
|
}
|
|
5021
5147
|
/**
|
|
5022
|
-
* Decrypt and return as string.
|
|
5023
|
-
*
|
|
5148
|
+
* Decrypt and return as string using ECIES. The encrypted message should be
|
|
5149
|
+
* ephemeral public key + salt + iv + cipher text.
|
|
5150
|
+
*
|
|
5151
|
+
* The ephemeral public key is extracted from the beginning of the message
|
|
5152
|
+
* and used with our private key to derive the AES decryption key.
|
|
5024
5153
|
*
|
|
5025
5154
|
* @param msg The encrypted content
|
|
5026
|
-
* @param {CryptoKey|string} [publicKey] The public key used to generate
|
|
5027
|
-
* the AES key used on this message. If omitted, decrypt with our own
|
|
5028
|
-
* public key.
|
|
5029
5155
|
* @param {string} aesAlgorithm The algorithm. Default is AES-GCM.
|
|
5030
5156
|
* @param {string} info Custom "info" parameter
|
|
5031
|
-
* @returns {Promise<
|
|
5157
|
+
* @returns {Promise<string>} The decrypted content as a string.
|
|
5032
5158
|
*/
|
|
5033
|
-
async decryptAsString(msg,
|
|
5034
|
-
const dec = await this.decrypt(msg,
|
|
5159
|
+
async decryptAsString(msg, aesAlgorithm, info) {
|
|
5160
|
+
const dec = await this.decrypt(msg, aesAlgorithm, info);
|
|
5035
5161
|
return toString2(new Uint8Array(dec));
|
|
5036
5162
|
}
|
|
5037
5163
|
/**
|
|
@@ -5080,7 +5206,7 @@
|
|
|
5080
5206
|
data = msg;
|
|
5081
5207
|
}
|
|
5082
5208
|
const signature = await webcrypto.subtle.sign(
|
|
5083
|
-
{ name:
|
|
5209
|
+
{ name: ECC_WRITE_ALGORITHM },
|
|
5084
5210
|
this.writeKey.privateKey,
|
|
5085
5211
|
toArrayBuffer3(data)
|
|
5086
5212
|
);
|
|
@@ -5106,7 +5232,7 @@
|
|
|
5106
5232
|
__name(exportPublicKey, "exportPublicKey");
|
|
5107
5233
|
async function importPublicKey(base64Key, curve, use) {
|
|
5108
5234
|
checkValidKeyUse2(use);
|
|
5109
|
-
const alg = use === "exchange" /* Exchange */ ?
|
|
5235
|
+
const alg = use === "exchange" /* Exchange */ ? ECC_EXCHANGE_ALGORITHM : ECC_WRITE_ALGORITHM;
|
|
5110
5236
|
const uses = use === "exchange" /* Exchange */ ? [] : ["verify"];
|
|
5111
5237
|
const buf = base64ToArrBuf(base64Key);
|
|
5112
5238
|
const algorithm = curve === "X25519" /* X25519 */ ? { name: alg } : { name: alg, namedCurve: curve };
|
|
@@ -5129,8 +5255,8 @@
|
|
|
5129
5255
|
}, "asString")
|
|
5130
5256
|
});
|
|
5131
5257
|
Object.assign(EccKeys.prototype.decrypt, {
|
|
5132
|
-
asString: /* @__PURE__ */ __name(async function(msg,
|
|
5133
|
-
return this.decryptAsString(msg,
|
|
5258
|
+
asString: /* @__PURE__ */ __name(async function(msg, aesAlgorithm) {
|
|
5259
|
+
return this.decryptAsString(msg, aesAlgorithm);
|
|
5134
5260
|
}, "asString")
|
|
5135
5261
|
});
|
|
5136
5262
|
Object.assign(EccKeys.prototype.sign, {
|
|
@@ -5148,7 +5274,7 @@
|
|
|
5148
5274
|
const publicKey = await webcrypto.subtle.importKey(
|
|
5149
5275
|
"raw",
|
|
5150
5276
|
rawKeyBytes,
|
|
5151
|
-
{ name:
|
|
5277
|
+
{ name: ECC_WRITE_ALGORITHM },
|
|
5152
5278
|
true,
|
|
5153
5279
|
["verify"]
|
|
5154
5280
|
);
|
|
@@ -5168,7 +5294,7 @@
|
|
|
5168
5294
|
signature = sig;
|
|
5169
5295
|
}
|
|
5170
5296
|
const isValid = await webcrypto.subtle.verify(
|
|
5171
|
-
{ name:
|
|
5297
|
+
{ name: ECC_WRITE_ALGORITHM },
|
|
5172
5298
|
publicKey,
|
|
5173
5299
|
toArrayBuffer3(signature),
|
|
5174
5300
|
toArrayBuffer3(data)
|