feat(store): 添加门店、门店验证

This commit is contained in:
R524809
2026-09-04 10:27:29 +08:00
parent 66ca8b496c
commit 70d9d5b92a
19 changed files with 602 additions and 26 deletions
@@ -1,4 +1,5 @@
import {
createDecipheriv,
createCipheriv,
createHash,
createHmac,
@@ -35,3 +36,23 @@ export function encryptStoreSecret(
.digest('base64url'),
};
}
/** 仅供受信任的后台 Worker 使用;调用方不得记录返回值。 */
export function decryptStoreSecret(
ciphertextWithTag: Buffer,
nonce: Buffer,
keyMaterial: string,
): string {
const authenticationTagLength = 16;
if (ciphertextWithTag.length <= authenticationTagLength) {
throw new Error('Invalid encrypted store secret');
}
const key = createHash('sha256').update(keyMaterial).digest();
const ciphertext = ciphertextWithTag.subarray(0, -authenticationTagLength);
const tag = ciphertextWithTag.subarray(-authenticationTagLength);
const decipher = createDecipheriv('aes-256-gcm', key, nonce);
decipher.setAuthTag(tag);
return Buffer.concat([decipher.update(ciphertext), decipher.final()]).toString(
'utf8',
);
}