SHA256
Миграция PDA на client.key
This commit is contained in:
@@ -323,15 +323,15 @@ function toJwkB64(value) {
|
||||
return base64UrlEncode(bigIntToUnsignedBytes(value));
|
||||
}
|
||||
|
||||
async function deriveArweaveWalletParts(deviceKey32) {
|
||||
if (!(deviceKey32 instanceof Uint8Array)) {
|
||||
throw new Error('SAWD-v1: deviceKey32 должен быть Uint8Array');
|
||||
async function deriveArweaveWalletParts(clientKey32) {
|
||||
if (!(clientKey32 instanceof Uint8Array)) {
|
||||
throw new Error('SAWD-v1: clientKey32 должен быть Uint8Array');
|
||||
}
|
||||
if (deviceKey32.length !== 32) {
|
||||
throw new Error('SAWD-v1: deviceKey32 должен быть ровно 32 байта');
|
||||
if (clientKey32.length !== 32) {
|
||||
throw new Error('SAWD-v1: clientKey32 должен быть ровно 32 байта');
|
||||
}
|
||||
|
||||
const masterSeed32 = await hmacSha256(MASTER_LABEL_UTF8, deviceKey32);
|
||||
const masterSeed32 = await hmacSha256(MASTER_LABEL_UTF8, clientKey32);
|
||||
const masterSeedKey = await importHmacKey(masterSeed32);
|
||||
|
||||
const pResult = await derivePrimeWithImportedKey(masterSeedKey, 'p');
|
||||
@@ -381,8 +381,8 @@ async function deriveArweaveWalletParts(deviceKey32) {
|
||||
};
|
||||
}
|
||||
|
||||
export async function deriveArweaveWalletFromDeviceKey32(deviceKey32) {
|
||||
const result = await deriveArweaveWalletParts(deviceKey32);
|
||||
export async function deriveArweaveWalletFromClientKey32(clientKey32) {
|
||||
const result = await deriveArweaveWalletParts(clientKey32);
|
||||
return {
|
||||
derivation: result.derivation,
|
||||
jwk: result.jwk,
|
||||
@@ -395,7 +395,7 @@ export async function selfTestSawdV1() {
|
||||
const invalid = new Uint8Array(31);
|
||||
let invalidFailed = false;
|
||||
try {
|
||||
await deriveArweaveWalletFromDeviceKey32(invalid);
|
||||
await deriveArweaveWalletFromClientKey32(invalid);
|
||||
} catch {
|
||||
invalidFailed = true;
|
||||
}
|
||||
@@ -403,13 +403,13 @@ export async function selfTestSawdV1() {
|
||||
throw new Error('SAWD-v1 self-test: длина != 32 должна приводить к ошибке');
|
||||
}
|
||||
|
||||
const deviceKey = new Uint8Array(32);
|
||||
for (let i = 0; i < deviceKey.length; i += 1) {
|
||||
deviceKey[i] = i + 1;
|
||||
const clientKey = new Uint8Array(32);
|
||||
for (let i = 0; i < clientKey.length; i += 1) {
|
||||
clientKey[i] = i + 1;
|
||||
}
|
||||
|
||||
const first = await deriveArweaveWalletParts(deviceKey);
|
||||
const second = await deriveArweaveWalletParts(deviceKey);
|
||||
const first = await deriveArweaveWalletParts(clientKey);
|
||||
const second = await deriveArweaveWalletParts(clientKey);
|
||||
|
||||
if (!first.address || !second.address) {
|
||||
throw new Error('SAWD-v1 self-test: адрес пустой');
|
||||
|
||||
Reference in New Issue
Block a user