Skip to content

Commit a53ce9d

Browse files
committed
feat: add key validation function
1 parent 7fccb76 commit a53ce9d

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/key.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ export class Key {
3636
return concatBytes(key, csIn);
3737
}
3838

39+
/** Validate key */
40+
static validate(key: Uint8Array | string): boolean {
41+
if(typeof key == "string") key = Key.fromString(key);
42+
if (key.length !== 60) return false;
43+
return this.arraysEqual(this.computeChecksum(key.slice(0, 50)), key.slice(50));
44+
}
45+
3946
private static computeChecksum(key: Uint8Array): Uint8Array {
4047
const csRaw = Angstrem3Core.generateKeystream(this.CHECKSUM_MRK, key, 1).slice(0, 5);
4148
const cs = new Uint8Array(10);

0 commit comments

Comments
 (0)