(keyMaterial: any[])
| 1538 | |
| 1539 | // Generate a stable idempotency key for the key material, using a stable json stringification |
| 1540 | async function generateIdempotencyKey(keyMaterial: any[]) { |
| 1541 | const keys = keyMaterial.map((key) => { |
| 1542 | if (typeof key === "string") { |
| 1543 | return key; |
| 1544 | } |
| 1545 | |
| 1546 | return stableStringify(key); |
| 1547 | }); |
| 1548 | |
| 1549 | const key = keys.join(":"); |
| 1550 | |
| 1551 | const hash = await webcrypto.subtle.digest("SHA-256", Buffer.from(key)); |
| 1552 | |
| 1553 | return Buffer.from(hash).toString("hex"); |
| 1554 | } |
| 1555 | |
| 1556 | function stableStringify(obj: any): string { |
| 1557 | function sortKeys(obj: any): any { |
no test coverage detected
searching dependent graphs…