@libid/contracts 0.17.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/README.md +108 -47
  2. package/dist/abis/bindErrors.d.ts +714 -0
  3. package/dist/abis/bindErrors.d.ts.map +1 -0
  4. package/dist/abis/bindErrors.js +955 -0
  5. package/dist/abis/bindErrors.js.map +1 -0
  6. package/dist/abis/ceremonyPayloads.d.ts +118 -0
  7. package/dist/abis/ceremonyPayloads.d.ts.map +1 -0
  8. package/dist/abis/ceremonyPayloads.js +154 -0
  9. package/dist/abis/ceremonyPayloads.js.map +1 -0
  10. package/dist/abis/ceremonyProofVerifier.d.ts +6 -6
  11. package/dist/abis/ceremonyProofVerifier.js +6 -6
  12. package/dist/abis/ceremonyProofVerifier.js.map +1 -1
  13. package/dist/abis/handleEscrow.d.ts +56 -16
  14. package/dist/abis/handleEscrow.d.ts.map +1 -1
  15. package/dist/abis/handleEscrow.js +71 -19
  16. package/dist/abis/handleEscrow.js.map +1 -1
  17. package/dist/abis/honkVerifierErrors.d.ts +54 -0
  18. package/dist/abis/honkVerifierErrors.d.ts.map +1 -0
  19. package/dist/abis/honkVerifierErrors.js +71 -0
  20. package/dist/abis/honkVerifierErrors.js.map +1 -0
  21. package/dist/abis/identityRegistry.d.ts +123 -157
  22. package/dist/abis/identityRegistry.d.ts.map +1 -1
  23. package/dist/abis/identityRegistry.js +150 -194
  24. package/dist/abis/identityRegistry.js.map +1 -1
  25. package/dist/abis/index.d.ts +3 -0
  26. package/dist/abis/index.d.ts.map +1 -1
  27. package/dist/abis/index.js +3 -0
  28. package/dist/abis/index.js.map +1 -1
  29. package/dist/calls/handleEscrow.d.ts +1 -0
  30. package/dist/calls/handleEscrow.d.ts.map +1 -1
  31. package/dist/calls/handleEscrow.js +7 -0
  32. package/dist/calls/handleEscrow.js.map +1 -1
  33. package/dist/calls/identityRegistry.d.ts +2 -1
  34. package/dist/calls/identityRegistry.d.ts.map +1 -1
  35. package/dist/calls/identityRegistry.js +9 -2
  36. package/dist/calls/identityRegistry.js.map +1 -1
  37. package/dist/ceremony/profiles.d.ts +38 -48
  38. package/dist/ceremony/profiles.d.ts.map +1 -1
  39. package/dist/ceremony/profiles.js +31 -36
  40. package/dist/ceremony/profiles.js.map +1 -1
  41. package/dist/identity/index.d.ts +1 -3
  42. package/dist/identity/index.d.ts.map +1 -1
  43. package/dist/identity/index.js +5 -11
  44. package/dist/identity/index.js.map +1 -1
  45. package/dist/identity/resolve.d.ts +6 -8
  46. package/dist/identity/resolve.d.ts.map +1 -1
  47. package/dist/identity/resolve.js +53 -86
  48. package/dist/identity/resolve.js.map +1 -1
  49. package/dist/index.d.ts +1 -0
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +3 -4
  52. package/dist/index.js.map +1 -1
  53. package/dist/payloads.d.ts +124 -0
  54. package/dist/payloads.d.ts.map +1 -0
  55. package/dist/payloads.js +59 -0
  56. package/dist/payloads.js.map +1 -0
  57. package/dist/platforms/handle.d.ts +11 -0
  58. package/dist/platforms/handle.d.ts.map +1 -0
  59. package/dist/platforms/handle.js +29 -0
  60. package/dist/platforms/handle.js.map +1 -0
  61. package/dist/platforms/id.d.ts +8 -0
  62. package/dist/platforms/id.d.ts.map +1 -0
  63. package/dist/platforms/id.js +21 -0
  64. package/dist/platforms/id.js.map +1 -0
  65. package/dist/platforms/index.d.ts +5 -0
  66. package/dist/platforms/index.d.ts.map +1 -0
  67. package/dist/platforms/index.js +8 -0
  68. package/dist/platforms/index.js.map +1 -0
  69. package/dist/platforms/node.d.ts +4 -0
  70. package/dist/platforms/node.d.ts.map +1 -0
  71. package/dist/platforms/node.js +36 -0
  72. package/dist/platforms/node.js.map +1 -0
  73. package/dist/platforms/platforms.d.ts +39 -0
  74. package/dist/platforms/platforms.d.ts.map +1 -0
  75. package/dist/platforms/platforms.js +90 -0
  76. package/dist/platforms/platforms.js.map +1 -0
  77. package/package.json +11 -3
  78. package/src/abis/bindErrors.ts +957 -0
  79. package/src/abis/ceremonyPayloads.ts +156 -0
  80. package/src/abis/ceremonyProofVerifier.ts +6 -6
  81. package/src/abis/handleEscrow.ts +71 -19
  82. package/src/abis/honkVerifierErrors.ts +73 -0
  83. package/src/abis/identityRegistry.ts +150 -194
  84. package/src/abis/index.ts +3 -0
  85. package/src/calls/handleEscrow.ts +12 -0
  86. package/src/calls/identityRegistry.ts +14 -2
  87. package/src/ceremony/profiles.ts +53 -65
  88. package/src/identity/index.ts +5 -11
  89. package/src/identity/resolve.ts +71 -118
  90. package/src/index.ts +3 -4
  91. package/src/payloads.ts +90 -0
  92. package/src/platforms/handle.ts +36 -0
  93. package/src/platforms/id.ts +26 -0
  94. package/src/platforms/index.ts +8 -0
  95. package/src/platforms/node.ts +41 -0
  96. package/src/platforms/platforms.ts +114 -0
  97. package/dist/identity/handle.d.ts +0 -22
  98. package/dist/identity/handle.d.ts.map +0 -1
  99. package/dist/identity/handle.js +0 -140
  100. package/dist/identity/handle.js.map +0 -1
  101. package/dist/identity/handleVectors.d.ts +0 -50
  102. package/dist/identity/handleVectors.d.ts.map +0 -1
  103. package/dist/identity/handleVectors.js +0 -89
  104. package/dist/identity/handleVectors.js.map +0 -1
  105. package/dist/identity/node.d.ts +0 -5
  106. package/dist/identity/node.d.ts.map +0 -1
  107. package/dist/identity/node.js +0 -19
  108. package/dist/identity/node.js.map +0 -1
  109. package/src/identity/handle.ts +0 -176
  110. package/src/identity/handleVectors.ts +0 -104
  111. package/src/identity/node.ts +0 -28
@@ -1,176 +0,0 @@
1
- /// Turns a platform handle into the one form the identity system hashes into a
2
- /// node.
3
- ///
4
- /// This mirrors `solidity/contracts/identity/HandleNormalizer.sol` and
5
- /// `rust/identity/src/handle.rs` byte for byte. The three transforms
6
- /// are hand written; the rules they run and the vectors they are checked
7
- /// against are generated from `solidity/contracts/identity/handles.json`, so a
8
- /// difference between them fails a test instead of looking up a node the chain
9
- /// never wrote.
10
-
11
- import {
12
- ALLOW_HYPHEN_GITHUB,
13
- ALLOW_HYPHEN_GOOGLE,
14
- ALLOW_HYPHEN_X,
15
- ALLOW_UNDERSCORE_GITHUB,
16
- ALLOW_UNDERSCORE_GOOGLE,
17
- ALLOW_UNDERSCORE_X,
18
- ERROR_BADCHARACTER,
19
- ERROR_BADSHAPE,
20
- ERROR_EMPTY,
21
- ERROR_TOOLONG,
22
- IS_EMAIL_GITHUB,
23
- IS_EMAIL_GOOGLE,
24
- IS_EMAIL_X,
25
- MAX_LENGTH_GITHUB,
26
- MAX_LENGTH_GOOGLE,
27
- MAX_LENGTH_X,
28
- PLATFORM_GITHUB_KEY,
29
- PLATFORM_GOOGLE_KEY,
30
- PLATFORM_X_KEY,
31
- STRIP_LEADING_AT_GITHUB,
32
- STRIP_LEADING_AT_GOOGLE,
33
- STRIP_LEADING_AT_X,
34
- } from './handleVectors.js'
35
-
36
- /// Why a handle was refused. The kinds match the Solidity errors and the Rust
37
- /// ones, because the vector table names which refusal it expects.
38
- export class HandleError extends Error {
39
- constructor(
40
- readonly kind: number,
41
- message: string,
42
- ) {
43
- super(message)
44
- this.name = 'HandleError'
45
- }
46
- }
47
-
48
- const EMPTY = () => new HandleError(ERROR_EMPTY, 'the handle is empty')
49
- const TOO_LONG = () => new HandleError(ERROR_TOOLONG, 'the handle is too long for this platform')
50
- const BAD_CHARACTER = () =>
51
- new HandleError(ERROR_BADCHARACTER, 'the handle has a character this platform does not allow')
52
- const BAD_SHAPE = () =>
53
- new HandleError(ERROR_BADSHAPE, 'the handle has an arrangement this platform does not allow')
54
-
55
- /// What one platform accepts. Held per platform, so a new platform is
56
- /// configuration rather than code.
57
- export interface Rules {
58
- /** Bytes allowed after trimming and the `@` strip. */
59
- maxLength: number
60
- /** Remove one leading `@`. X and GitHub do. An email keeps its own `@`. */
61
- stripLeadingAt: boolean
62
- /** Validate as an address instead of a bare handle. */
63
- isEmail: boolean
64
- /** Allowed by X, not by GitHub. */
65
- allowUnderscore: boolean
66
- /** A hyphen may not start or end the handle, and two may not touch. */
67
- allowHyphen: boolean
68
- }
69
-
70
- export const RULES_X: Rules = {
71
- maxLength: MAX_LENGTH_X,
72
- stripLeadingAt: STRIP_LEADING_AT_X,
73
- isEmail: IS_EMAIL_X,
74
- allowUnderscore: ALLOW_UNDERSCORE_X,
75
- allowHyphen: ALLOW_HYPHEN_X,
76
- }
77
-
78
- export const RULES_GITHUB: Rules = {
79
- maxLength: MAX_LENGTH_GITHUB,
80
- stripLeadingAt: STRIP_LEADING_AT_GITHUB,
81
- isEmail: IS_EMAIL_GITHUB,
82
- allowUnderscore: ALLOW_UNDERSCORE_GITHUB,
83
- allowHyphen: ALLOW_HYPHEN_GITHUB,
84
- }
85
-
86
- export const RULES_GOOGLE: Rules = {
87
- maxLength: MAX_LENGTH_GOOGLE,
88
- stripLeadingAt: STRIP_LEADING_AT_GOOGLE,
89
- isEmail: IS_EMAIL_GOOGLE,
90
- allowUnderscore: ALLOW_UNDERSCORE_GOOGLE,
91
- allowHyphen: ALLOW_HYPHEN_GOOGLE,
92
- }
93
-
94
- /// The rules for a platform key from the generated table: what the contracts
95
- /// were released with. The chain's owner can change a platform's rules, so a
96
- /// hash for a deposit should use `rulesOf`.
97
- export function rulesFor(platformKey: string): Rules | null {
98
- if (platformKey === PLATFORM_X_KEY) return RULES_X
99
- if (platformKey === PLATFORM_GITHUB_KEY) return RULES_GITHUB
100
- if (platformKey === PLATFORM_GOOGLE_KEY) return RULES_GOOGLE
101
- return null
102
- }
103
-
104
- /// The normalized handle, or a `HandleError` naming what was wrong.
105
- export function normalize(raw: string, rules: Rules): string {
106
- // Work on bytes, not code units. A character above 0x7f is several bytes and
107
- // must be refused as bytes, the way Solidity sees it.
108
- const input = new TextEncoder().encode(raw)
109
-
110
- // Trim ASCII spaces only. A tab or a newline is not whitespace to remove
111
- // here; it is a byte the platform does not allow, and the character check
112
- // below refuses it. Trimming it would accept "ali\tce" as "alice" here and
113
- // refuse it on chain.
114
- let start = 0
115
- let end = input.length
116
- while (start < end && input[start] === 0x20) start++
117
- while (end > start && input[end - 1] === 0x20) end--
118
-
119
- if (rules.stripLeadingAt && end > start && input[start] === 0x40) start++
120
-
121
- const length = end - start
122
- if (length === 0) throw EMPTY()
123
- if (length > rules.maxLength) throw TOO_LONG()
124
-
125
- const out = new Uint8Array(length)
126
- for (let i = 0; i < length; i++) {
127
- let c = input[start + i]
128
- // Fold A-Z down. Nothing else changes, so two addresses that differ in more
129
- // than case stay two identities.
130
- if (c >= 0x41 && c <= 0x5a) c += 0x20
131
- if (!allowed(c, rules)) throw BAD_CHARACTER()
132
- out[i] = c
133
- }
134
-
135
- if (rules.isEmail) requireEmailShape(out)
136
- else if (rules.allowHyphen) requireHyphenShape(out)
137
-
138
- return new TextDecoder().decode(out)
139
- }
140
-
141
- /// One byte, after folding. Anything outside the platform's set is refused,
142
- /// including every byte above 0x7f, so a multi-byte character never reaches a
143
- /// node.
144
- function allowed(c: number, rules: Rules): boolean {
145
- if (c >= 0x61 && c <= 0x7a) return true // a-z
146
- if (c >= 0x30 && c <= 0x39) return true // 0-9
147
- if (rules.isEmail) {
148
- // The set a Google address uses. The dot, the plus and the tag stay exactly
149
- // as proved: this transform must never map two addresses onto one identity.
150
- return c === 0x2e || c === 0x2b || c === 0x2d || c === 0x5f || c === 0x40
151
- }
152
- if (rules.allowUnderscore && c === 0x5f) return true
153
- if (rules.allowHyphen && c === 0x2d) return true
154
- return false
155
- }
156
-
157
- /// Exactly one `@`, and not at either edge.
158
- function requireEmailShape(value: Uint8Array): void {
159
- let at = -1
160
- for (let i = 0; i < value.length; i++) {
161
- if (value[i] === 0x40) {
162
- if (at !== -1) throw BAD_SHAPE() // a second one
163
- at = i
164
- }
165
- }
166
- if (at === -1) throw BAD_SHAPE() // none
167
- if (at === 0 || at === value.length - 1) throw BAD_SHAPE() // an empty side
168
- }
169
-
170
- /// A hyphen may not start or end the handle, and two may not touch.
171
- function requireHyphenShape(value: Uint8Array): void {
172
- if (value[0] === 0x2d || value[value.length - 1] === 0x2d) throw BAD_SHAPE()
173
- for (let i = 1; i < value.length; i++) {
174
- if (value[i] === 0x2d && value[i - 1] === 0x2d) throw BAD_SHAPE()
175
- }
176
- }
@@ -1,104 +0,0 @@
1
- // Generated by scripts/regen-identity-handles.py. Do not edit.
2
- // The source of truth is solidity/contracts/identity/handles.json.
3
-
4
- /// Platform ids and the shared handle vector table.
5
-
6
- export interface HandleVector {
7
- platform: string
8
- input: string
9
- /** The normalized handle, or an empty string when the case is refused. */
10
- output: string
11
- accepted: boolean
12
- errorKind: number
13
- }
14
-
15
- /** keccak256 of this string is the platform id. */
16
- export const PLATFORM_X_KEY = 'x'
17
- /** keccak256 of this string is the platform id. */
18
- export const PLATFORM_GITHUB_KEY = 'github'
19
- /** keccak256 of this string is the platform id. */
20
- export const PLATFORM_GOOGLE_KEY = 'google'
21
-
22
- /** Bytes a x handle may have after normalization. */
23
- export const MAX_LENGTH_X = 15
24
- /** Bytes a github handle may have after normalization. */
25
- export const MAX_LENGTH_GITHUB = 39
26
- /** Bytes a google handle may have after normalization. */
27
- export const MAX_LENGTH_GOOGLE = 62
28
-
29
- /** Remove one leading `@`. */
30
- export const STRIP_LEADING_AT_X = true
31
- /** Validate as an address instead of a bare handle. */
32
- export const IS_EMAIL_X = false
33
- /** Allow `_`. */
34
- export const ALLOW_UNDERSCORE_X = true
35
- /** Allow `-`, but not leading, trailing or doubled. */
36
- export const ALLOW_HYPHEN_X = false
37
- /** Remove one leading `@`. */
38
- export const STRIP_LEADING_AT_GITHUB = true
39
- /** Validate as an address instead of a bare handle. */
40
- export const IS_EMAIL_GITHUB = false
41
- /** Allow `_`. */
42
- export const ALLOW_UNDERSCORE_GITHUB = false
43
- /** Allow `-`, but not leading, trailing or doubled. */
44
- export const ALLOW_HYPHEN_GITHUB = true
45
- /** Remove one leading `@`. */
46
- export const STRIP_LEADING_AT_GOOGLE = false
47
- /** Validate as an address instead of a bare handle. */
48
- export const IS_EMAIL_GOOGLE = true
49
- /** Allow `_`. */
50
- export const ALLOW_UNDERSCORE_GOOGLE = false
51
- /** Allow `-`, but not leading, trailing or doubled. */
52
- export const ALLOW_HYPHEN_GOOGLE = false
53
-
54
- export const ERROR_EMPTY = 0
55
- export const ERROR_TOOLONG = 1
56
- export const ERROR_BADCHARACTER = 2
57
- export const ERROR_BADSHAPE = 3
58
-
59
- export const HANDLE_VECTORS: HandleVector[] = [
60
- { platform: "x", input: " @Alice_1 ", output: "alice_1", accepted: true, errorKind: 0 },
61
- { platform: "x", input: "alice", output: "alice", accepted: true, errorKind: 0 },
62
- { platform: "x", input: "@a", output: "a", accepted: true, errorKind: 0 },
63
- { platform: "x", input: "A1_b2", output: "a1_b2", accepted: true, errorKind: 0 },
64
- { platform: "x", input: "a12345678901234", output: "a12345678901234", accepted: true, errorKind: 0 },
65
- { platform: "x", input: "a123456789012345", output: "", accepted: false, errorKind: 1 },
66
- { platform: "x", input: "", output: "", accepted: false, errorKind: 0 },
67
- { platform: "x", input: " ", output: "", accepted: false, errorKind: 0 },
68
- { platform: "x", input: "@", output: "", accepted: false, errorKind: 0 },
69
- { platform: "x", input: "@@alice", output: "", accepted: false, errorKind: 2 },
70
- { platform: "x", input: "alice-1", output: "", accepted: false, errorKind: 2 },
71
- { platform: "x", input: "ali ce", output: "", accepted: false, errorKind: 2 },
72
- { platform: "x", input: "ali\tce", output: "", accepted: false, errorKind: 2 },
73
- { platform: "x", input: "ali\nce", output: "", accepted: false, errorKind: 2 },
74
- { platform: "x", input: "alic\u00e9", output: "", accepted: false, errorKind: 2 },
75
- { platform: "x", input: "\talice", output: "", accepted: false, errorKind: 2 },
76
- { platform: "x", input: "alice\t", output: "", accepted: false, errorKind: 2 },
77
- { platform: "x", input: "\nalice", output: "", accepted: false, errorKind: 2 },
78
- { platform: "x", input: " @ alice ", output: "", accepted: false, errorKind: 2 },
79
- { platform: "github", input: "@Octo-Cat", output: "octo-cat", accepted: true, errorKind: 0 },
80
- { platform: "github", input: "octocat", output: "octocat", accepted: true, errorKind: 0 },
81
- { platform: "github", input: " OctoCat ", output: "octocat", accepted: true, errorKind: 0 },
82
- { platform: "github", input: "a", output: "a", accepted: true, errorKind: 0 },
83
- { platform: "github", input: "o-c", output: "o-c", accepted: true, errorKind: 0 },
84
- { platform: "github", input: "-octocat", output: "", accepted: false, errorKind: 3 },
85
- { platform: "github", input: "octocat-", output: "", accepted: false, errorKind: 3 },
86
- { platform: "github", input: "octo--cat", output: "", accepted: false, errorKind: 3 },
87
- { platform: "github", input: "octo_cat", output: "", accepted: false, errorKind: 2 },
88
- { platform: "github", input: "-", output: "", accepted: false, errorKind: 3 },
89
- { platform: "github", input: "", output: "", accepted: false, errorKind: 0 },
90
- { platform: "github", input: "abcdefghijabcdefghijabcdefghijabcdefghi", output: "abcdefghijabcdefghijabcdefghijabcdefghi", accepted: true, errorKind: 0 },
91
- { platform: "github", input: "abcdefghijabcdefghijabcdefghijabcdefghij", output: "", accepted: false, errorKind: 1 },
92
- { platform: "github", input: "\n", output: "", accepted: false, errorKind: 2 },
93
- { platform: "google", input: "A.B+tag@Example.COM", output: "a.b+tag@example.com", accepted: true, errorKind: 0 },
94
- { platform: "google", input: "alice@example.com", output: "alice@example.com", accepted: true, errorKind: 0 },
95
- { platform: "google", input: " Alice@Example.com ", output: "alice@example.com", accepted: true, errorKind: 0 },
96
- { platform: "google", input: "@Alice@example.com", output: "", accepted: false, errorKind: 3 },
97
- { platform: "google", input: "alice", output: "", accepted: false, errorKind: 3 },
98
- { platform: "google", input: "@example.com", output: "", accepted: false, errorKind: 3 },
99
- { platform: "google", input: "alice@", output: "", accepted: false, errorKind: 3 },
100
- { platform: "google", input: "", output: "", accepted: false, errorKind: 0 },
101
- { platform: "google", input: "ali ce@example.com", output: "", accepted: false, errorKind: 2 },
102
- { platform: "google", input: "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij@example.com", output: "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij@example.com", accepted: true, errorKind: 0 },
103
- { platform: "google", input: "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijk@example.com", output: "", accepted: false, errorKind: 1 },
104
- ]
@@ -1,28 +0,0 @@
1
- /// Handle hashes and nodes, mirroring `IdentityRegistry.handleHashOf` and
2
- /// `handleNodeOfHash`, computed locally so the handle text never reaches an
3
- /// RPC. `HandleEscrow.deposit` takes the hash; `handleBinding` and the
4
- /// escrow's reads take the node.
5
-
6
- import { encodeAbiParameters, type Hex, keccak256, toHex } from 'viem'
7
-
8
- import { normalize, type Rules } from './handle.js'
9
-
10
- const HANDLE_NODE_V1: Hex = keccak256(toHex('libid.identity.handle-node.v1'))
11
-
12
- /// `keccak256` of `raw` normalized under `rules` (from `rulesOf`, or
13
- /// `rulesFor` offline). Throws `HandleError` for text the rules refuse.
14
- export function handleHash(raw: string, rules: Rules): Hex {
15
- return keccak256(toHex(normalize(raw, rules)))
16
- }
17
-
18
- /// The node a handle hash sits on, on the platform `platformId` names
19
- /// (`platformId(PLATFORM_X_KEY)`), as `IdentityRegistry.handleNodeOfHash` derives
20
- /// it.
21
- export function handleNode(platformId: Hex, hash: Hex): Hex {
22
- return keccak256(
23
- encodeAbiParameters(
24
- [{ type: 'bytes32' }, { type: 'bytes32' }, { type: 'bytes32' }],
25
- [HANDLE_NODE_V1, platformId, hash],
26
- ),
27
- )
28
- }