Download this file
| 1 | package assist |
| 2 | |
| 3 | import ( |
| 4 | "crypto/sha1" |
| 5 | "fmt" |
| 6 | ) |
| 7 | |
| 8 | // keyNamespace is the UUID namespace for idempotency keys sent to providers. |
| 9 | var keyNamespace = [16]byte{0x34, 0xb8, 0x06, 0xef, 0xc4, 0x87, 0x4c, 0x5b, 0xb2, 0x04, 0x47, 0x40, 0xb8, 0x0a, 0x8b, 0xf8} |
| 10 | |
| 11 | // Key turns a ledger key into the UUIDv5 sent to a provider, so the raw call |
| 12 | // id never leaves the instance and the result is never the nil UUID. |
| 13 | func Key(ledger string) string { |
| 14 | h := sha1.New() |
| 15 | h.Write(keyNamespace[:]) |
| 16 | h.Write([]byte(ledger)) |
| 17 | b := h.Sum(nil)[:16] |
| 18 | b[6] = b[6]&0x0f | 0x50 |
| 19 | b[8] = b[8]&0x3f | 0x80 |
| 20 | return fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:16]) |
| 21 | } |
| 22 | |