@libid/contracts 0.13.1 → 0.15.0
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.
- package/README.md +53 -32
- package/dist/abis/handleEscrow.d.ts +632 -0
- package/dist/abis/handleEscrow.d.ts.map +1 -0
- package/dist/abis/handleEscrow.js +815 -0
- package/dist/abis/handleEscrow.js.map +1 -0
- package/dist/abis/handleResolver.d.ts +1 -1
- package/dist/abis/handleResolver.js +1 -1
- package/dist/abis/handleResolver.js.map +1 -1
- package/dist/abis/{identityNames.d.ts → identityRegistry.d.ts} +251 -105
- package/dist/abis/{identityNames.d.ts.map → identityRegistry.d.ts.map} +1 -1
- package/dist/abis/{identityNames.js → identityRegistry.js} +312 -118
- package/dist/abis/identityRegistry.js.map +1 -0
- package/dist/abis/index.d.ts +2 -1
- package/dist/abis/index.d.ts.map +1 -1
- package/dist/abis/index.js +2 -1
- package/dist/abis/index.js.map +1 -1
- package/dist/calls/handleEscrow.d.ts +15 -0
- package/dist/calls/handleEscrow.d.ts.map +1 -0
- package/dist/calls/handleEscrow.js +49 -0
- package/dist/calls/handleEscrow.js.map +1 -0
- package/dist/calls/identityRegistry.d.ts +16 -0
- package/dist/calls/identityRegistry.d.ts.map +1 -0
- package/dist/calls/identityRegistry.js +55 -0
- package/dist/calls/identityRegistry.js.map +1 -0
- package/dist/calls/index.d.ts +2 -1
- package/dist/calls/index.d.ts.map +1 -1
- package/dist/calls/index.js +2 -1
- package/dist/calls/index.js.map +1 -1
- package/dist/ceremony/profiles.d.ts +34 -2
- package/dist/ceremony/profiles.d.ts.map +1 -1
- package/dist/ceremony/profiles.js +52 -2
- package/dist/ceremony/profiles.js.map +1 -1
- package/dist/identity/handle.d.ts +1 -1
- package/dist/identity/handle.d.ts.map +1 -1
- package/dist/identity/handle.js +12 -9
- package/dist/identity/handle.js.map +1 -1
- package/dist/identity/handleVectors.d.ts +3 -6
- package/dist/identity/handleVectors.d.ts.map +1 -1
- package/dist/identity/handleVectors.js +3 -13
- package/dist/identity/handleVectors.js.map +1 -1
- package/dist/identity/index.d.ts +1 -0
- package/dist/identity/index.d.ts.map +1 -1
- package/dist/identity/index.js +2 -1
- package/dist/identity/index.js.map +1 -1
- package/dist/identity/node.d.ts +5 -0
- package/dist/identity/node.d.ts.map +1 -0
- package/dist/identity/node.js +19 -0
- package/dist/identity/node.js.map +1 -0
- package/dist/identity/resolve.d.ts +19 -9
- package/dist/identity/resolve.d.ts.map +1 -1
- package/dist/identity/resolve.js +76 -47
- package/dist/identity/resolve.js.map +1 -1
- package/package.json +2 -2
- package/src/abis/handleEscrow.ts +817 -0
- package/src/abis/handleResolver.ts +1 -1
- package/src/abis/{identityNames.ts → identityRegistry.ts} +311 -117
- package/src/abis/index.ts +2 -1
- package/src/calls/handleEscrow.ts +78 -0
- package/src/calls/identityRegistry.ts +91 -0
- package/src/calls/index.ts +2 -1
- package/src/ceremony/profiles.ts +55 -2
- package/src/identity/handle.ts +14 -8
- package/src/identity/handleVectors.ts +3 -14
- package/src/identity/index.ts +2 -1
- package/src/identity/node.ts +28 -0
- package/src/identity/resolve.ts +127 -69
- package/dist/abis/identityNames.js.map +0 -1
- package/dist/calls/identityNames.d.ts +0 -16
- package/dist/calls/identityNames.d.ts.map +0 -1
- package/dist/calls/identityNames.js +0 -55
- package/dist/calls/identityNames.js.map +0 -1
- package/src/calls/identityNames.ts +0 -88
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Generated by ts/packages/contracts/scripts/codegen.mjs. Do not edit.
|
|
2
|
+
// Source artifact: solidity/out/HandleEscrow.sol/HandleEscrow.json
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
type Address,
|
|
6
|
+
type ContractFunctionArgs,
|
|
7
|
+
type ContractFunctionName,
|
|
8
|
+
encodeFunctionData,
|
|
9
|
+
} from 'viem'
|
|
10
|
+
|
|
11
|
+
import type { Call } from '../call.js'
|
|
12
|
+
import { handleEscrowAbi } from '../abis/handleEscrow.js'
|
|
13
|
+
|
|
14
|
+
type Mutability = 'nonpayable' | 'payable'
|
|
15
|
+
type HandleEscrowFn = ContractFunctionName<typeof handleEscrowAbi, Mutability>
|
|
16
|
+
type HandleEscrowArgs<F extends HandleEscrowFn> = ContractFunctionArgs<
|
|
17
|
+
typeof handleEscrowAbi,
|
|
18
|
+
Mutability,
|
|
19
|
+
F
|
|
20
|
+
>
|
|
21
|
+
|
|
22
|
+
export function acceptOwnership(to: Address, ...args: HandleEscrowArgs<'acceptOwnership'>): Call {
|
|
23
|
+
return {
|
|
24
|
+
to,
|
|
25
|
+
data: encodeFunctionData({ abi: handleEscrowAbi, functionName: 'acceptOwnership', args }),
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function claim(to: Address, ...args: HandleEscrowArgs<'claim'>): Call {
|
|
30
|
+
return {
|
|
31
|
+
to,
|
|
32
|
+
data: encodeFunctionData({ abi: handleEscrowAbi, functionName: 'claim', args }),
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function deposit(to: Address, value: bigint, ...args: HandleEscrowArgs<'deposit'>): Call {
|
|
37
|
+
return {
|
|
38
|
+
to,
|
|
39
|
+
value,
|
|
40
|
+
data: encodeFunctionData({ abi: handleEscrowAbi, functionName: 'deposit', args }),
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function initialize(to: Address, ...args: HandleEscrowArgs<'initialize'>): Call {
|
|
45
|
+
return {
|
|
46
|
+
to,
|
|
47
|
+
data: encodeFunctionData({ abi: handleEscrowAbi, functionName: 'initialize', args }),
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function refund(to: Address, ...args: HandleEscrowArgs<'refund'>): Call {
|
|
52
|
+
return {
|
|
53
|
+
to,
|
|
54
|
+
data: encodeFunctionData({ abi: handleEscrowAbi, functionName: 'refund', args }),
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function transferOwnership(
|
|
59
|
+
to: Address,
|
|
60
|
+
...args: HandleEscrowArgs<'transferOwnership'>
|
|
61
|
+
): Call {
|
|
62
|
+
return {
|
|
63
|
+
to,
|
|
64
|
+
data: encodeFunctionData({ abi: handleEscrowAbi, functionName: 'transferOwnership', args }),
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function upgradeToAndCall(
|
|
69
|
+
to: Address,
|
|
70
|
+
value: bigint,
|
|
71
|
+
...args: HandleEscrowArgs<'upgradeToAndCall'>
|
|
72
|
+
): Call {
|
|
73
|
+
return {
|
|
74
|
+
to,
|
|
75
|
+
value,
|
|
76
|
+
data: encodeFunctionData({ abi: handleEscrowAbi, functionName: 'upgradeToAndCall', args }),
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Generated by ts/packages/contracts/scripts/codegen.mjs. Do not edit.
|
|
2
|
+
// Source artifact: solidity/out/IdentityRegistry.sol/IdentityRegistry.json
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
type Address,
|
|
6
|
+
type ContractFunctionArgs,
|
|
7
|
+
type ContractFunctionName,
|
|
8
|
+
encodeFunctionData,
|
|
9
|
+
} from 'viem'
|
|
10
|
+
|
|
11
|
+
import type { Call } from '../call.js'
|
|
12
|
+
import { identityRegistryAbi } from '../abis/identityRegistry.js'
|
|
13
|
+
|
|
14
|
+
type Mutability = 'nonpayable' | 'payable'
|
|
15
|
+
type IdentityRegistryFn = ContractFunctionName<typeof identityRegistryAbi, Mutability>
|
|
16
|
+
type IdentityRegistryArgs<F extends IdentityRegistryFn> = ContractFunctionArgs<
|
|
17
|
+
typeof identityRegistryAbi,
|
|
18
|
+
Mutability,
|
|
19
|
+
F
|
|
20
|
+
>
|
|
21
|
+
|
|
22
|
+
export function acceptOwnership(
|
|
23
|
+
to: Address,
|
|
24
|
+
...args: IdentityRegistryArgs<'acceptOwnership'>
|
|
25
|
+
): Call {
|
|
26
|
+
return {
|
|
27
|
+
to,
|
|
28
|
+
data: encodeFunctionData({ abi: identityRegistryAbi, functionName: 'acceptOwnership', args }),
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function bind(to: Address, value: bigint, ...args: IdentityRegistryArgs<'bind'>): Call {
|
|
33
|
+
return {
|
|
34
|
+
to,
|
|
35
|
+
value,
|
|
36
|
+
data: encodeFunctionData({ abi: identityRegistryAbi, functionName: 'bind', args }),
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function initialize(to: Address, ...args: IdentityRegistryArgs<'initialize'>): Call {
|
|
41
|
+
return {
|
|
42
|
+
to,
|
|
43
|
+
data: encodeFunctionData({ abi: identityRegistryAbi, functionName: 'initialize', args }),
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function setPlatform(to: Address, ...args: IdentityRegistryArgs<'setPlatform'>): Call {
|
|
48
|
+
return {
|
|
49
|
+
to,
|
|
50
|
+
data: encodeFunctionData({ abi: identityRegistryAbi, functionName: 'setPlatform', args }),
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function setProofVerifier(
|
|
55
|
+
to: Address,
|
|
56
|
+
...args: IdentityRegistryArgs<'setProofVerifier'>
|
|
57
|
+
): Call {
|
|
58
|
+
return {
|
|
59
|
+
to,
|
|
60
|
+
data: encodeFunctionData({ abi: identityRegistryAbi, functionName: 'setProofVerifier', args }),
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function transferOwnership(
|
|
65
|
+
to: Address,
|
|
66
|
+
...args: IdentityRegistryArgs<'transferOwnership'>
|
|
67
|
+
): Call {
|
|
68
|
+
return {
|
|
69
|
+
to,
|
|
70
|
+
data: encodeFunctionData({ abi: identityRegistryAbi, functionName: 'transferOwnership', args }),
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function unpublish(to: Address, ...args: IdentityRegistryArgs<'unpublish'>): Call {
|
|
75
|
+
return {
|
|
76
|
+
to,
|
|
77
|
+
data: encodeFunctionData({ abi: identityRegistryAbi, functionName: 'unpublish', args }),
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function upgradeToAndCall(
|
|
82
|
+
to: Address,
|
|
83
|
+
value: bigint,
|
|
84
|
+
...args: IdentityRegistryArgs<'upgradeToAndCall'>
|
|
85
|
+
): Call {
|
|
86
|
+
return {
|
|
87
|
+
to,
|
|
88
|
+
value,
|
|
89
|
+
data: encodeFunctionData({ abi: identityRegistryAbi, functionName: 'upgradeToAndCall', args }),
|
|
90
|
+
}
|
|
91
|
+
}
|
package/src/calls/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Generated by ts/packages/contracts/scripts/codegen.mjs. Do not edit.
|
|
2
2
|
// Source artifact: solidity/out/*
|
|
3
|
-
export * as
|
|
3
|
+
export * as identityRegistry from './identityRegistry.js'
|
|
4
4
|
export * as handleResolver from './handleResolver.js'
|
|
5
|
+
export * as handleEscrow from './handleEscrow.js'
|
|
5
6
|
export * as notaryService from './notaryService.js'
|
|
6
7
|
export * as ceremonyProofVerifier from './ceremonyProofVerifier.js'
|
|
7
8
|
export * as googleJwtRoots from './googleJwtRoots.js'
|
package/src/ceremony/profiles.ts
CHANGED
|
@@ -179,7 +179,60 @@ export const FORBIDDEN_REQUEST_HEADERS: readonly string[] = [
|
|
|
179
179
|
'x-method-override',
|
|
180
180
|
]
|
|
181
181
|
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
// The seconds each profile fixes. A Platform Verifier reads them as
|
|
183
|
+
// constants: they belong to the profile like its request lines, an upgrade
|
|
184
|
+
// of the verifier keeps them, and a different value is a new
|
|
185
|
+
// ceremonyVersion (REQ-PARAM-01). A browser that knows the version it ran
|
|
186
|
+
// therefore knows the validity every chain enforces. `IdentityRegistry`
|
|
187
|
+
// supersedes a binding only on a strictly newer `observedAt`, so an
|
|
188
|
+
// allowance too generous lets a proof dated ahead hold a name until the
|
|
189
|
+
// clock catches up.
|
|
190
|
+
|
|
191
|
+
// The signed `exp` bounds validity, so the profile fixes no lifetime
|
|
192
|
+
// and no attestation skew. The OIDC circuit exposes no `iat`, so the
|
|
193
|
+
// observation is the token's `exp`: Google issues about an hour of
|
|
194
|
+
// life, and the claim reads roughly an hour ahead of the moment it
|
|
195
|
+
// describes.
|
|
196
|
+
/**
|
|
197
|
+
* `google/v1`: how far ahead of Block Time the evidence time may run.
|
|
198
|
+
* The verifier subtracts it, so every version of a platform reports
|
|
199
|
+
* time on one scale.
|
|
200
|
+
*/
|
|
201
|
+
export const FUTURE_OBSERVATION_ALLOWANCE_SECONDS_GOOGLE = 7200
|
|
202
|
+
|
|
203
|
+
// The token attestation's creation time is the evidence time. A
|
|
204
|
+
// notary states wall-clock time as it observes it, so the observation
|
|
205
|
+
// is never ahead: five minutes covers clock skew between the notary
|
|
206
|
+
// and the chain.
|
|
207
|
+
/**
|
|
208
|
+
* `x/v1`: maximum age of the token attestation.
|
|
209
|
+
*/
|
|
184
210
|
export const PROOF_LIFETIME_SECONDS_X = 3600
|
|
211
|
+
/**
|
|
212
|
+
* `x/v1`: how far ahead of Block Time the token attestation may be
|
|
213
|
+
* dated.
|
|
214
|
+
*/
|
|
215
|
+
export const MAX_FUTURE_ATTESTATION_SKEW_SECONDS_X = 300
|
|
216
|
+
/**
|
|
217
|
+
* `x/v1`: how far ahead of Block Time the evidence time may run. The
|
|
218
|
+
* verifier subtracts it, so every version of a platform reports time
|
|
219
|
+
* on one scale.
|
|
220
|
+
*/
|
|
221
|
+
export const FUTURE_OBSERVATION_ALLOWANCE_SECONDS_X = 300
|
|
222
|
+
|
|
223
|
+
// Same as X: notary wall-clock, five minutes for skew.
|
|
224
|
+
/**
|
|
225
|
+
* `github/v1`: maximum age of the token attestation.
|
|
226
|
+
*/
|
|
185
227
|
export const PROOF_LIFETIME_SECONDS_GITHUB = 3600
|
|
228
|
+
/**
|
|
229
|
+
* `github/v1`: how far ahead of Block Time the token attestation may
|
|
230
|
+
* be dated.
|
|
231
|
+
*/
|
|
232
|
+
export const MAX_FUTURE_ATTESTATION_SKEW_SECONDS_GITHUB = 300
|
|
233
|
+
/**
|
|
234
|
+
* `github/v1`: how far ahead of Block Time the evidence time may run.
|
|
235
|
+
* The verifier subtracts it, so every version of a platform reports
|
|
236
|
+
* time on one scale.
|
|
237
|
+
*/
|
|
238
|
+
export const FUTURE_OBSERVATION_ALLOWANCE_SECONDS_GITHUB = 300
|
package/src/identity/handle.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
/// Turns a platform handle into the one form the identity system
|
|
1
|
+
/// Turns a platform handle into the one form the identity system hashes into a
|
|
2
|
+
/// node.
|
|
2
3
|
///
|
|
3
4
|
/// This mirrors `solidity/contracts/identity/HandleNormalizer.sol` and
|
|
4
5
|
/// `rust/identity/src/handle.rs` byte for byte. The three transforms
|
|
5
6
|
/// are hand written; the rules they run and the vectors they are checked
|
|
6
7
|
/// against are generated from `solidity/contracts/identity/handles.json`, so a
|
|
7
|
-
/// difference between them fails a test instead of looking up a
|
|
8
|
+
/// difference between them fails a test instead of looking up a node the chain
|
|
8
9
|
/// never wrote.
|
|
9
10
|
|
|
10
11
|
import {
|
|
@@ -24,6 +25,9 @@ import {
|
|
|
24
25
|
MAX_LENGTH_GITHUB,
|
|
25
26
|
MAX_LENGTH_GOOGLE,
|
|
26
27
|
MAX_LENGTH_X,
|
|
28
|
+
PLATFORM_GITHUB_KEY,
|
|
29
|
+
PLATFORM_GOOGLE_KEY,
|
|
30
|
+
PLATFORM_X_KEY,
|
|
27
31
|
STRIP_LEADING_AT_GITHUB,
|
|
28
32
|
STRIP_LEADING_AT_GOOGLE,
|
|
29
33
|
STRIP_LEADING_AT_X,
|
|
@@ -87,11 +91,13 @@ export const RULES_GOOGLE: Rules = {
|
|
|
87
91
|
allowHyphen: ALLOW_HYPHEN_GOOGLE,
|
|
88
92
|
}
|
|
89
93
|
|
|
90
|
-
/// The rules for a platform key from the
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (
|
|
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
|
|
95
101
|
return null
|
|
96
102
|
}
|
|
97
103
|
|
|
@@ -134,7 +140,7 @@ export function normalize(raw: string, rules: Rules): string {
|
|
|
134
140
|
|
|
135
141
|
/// One byte, after folding. Anything outside the platform's set is refused,
|
|
136
142
|
/// including every byte above 0x7f, so a multi-byte character never reaches a
|
|
137
|
-
///
|
|
143
|
+
/// node.
|
|
138
144
|
function allowed(c: number, rules: Rules): boolean {
|
|
139
145
|
if (c >= 0x61 && c <= 0x7a) return true // a-z
|
|
140
146
|
if (c >= 0x30 && c <= 0x39) return true // 0-9
|
|
@@ -13,11 +13,11 @@ export interface HandleVector {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/** keccak256 of this string is the platform id. */
|
|
16
|
-
export const
|
|
16
|
+
export const PLATFORM_X_KEY = 'x'
|
|
17
17
|
/** keccak256 of this string is the platform id. */
|
|
18
|
-
export const
|
|
18
|
+
export const PLATFORM_GITHUB_KEY = 'github'
|
|
19
19
|
/** keccak256 of this string is the platform id. */
|
|
20
|
-
export const
|
|
20
|
+
export const PLATFORM_GOOGLE_KEY = 'google'
|
|
21
21
|
|
|
22
22
|
/** Bytes a x handle may have after normalization. */
|
|
23
23
|
export const MAX_LENGTH_X = 15
|
|
@@ -51,17 +51,6 @@ export const ALLOW_UNDERSCORE_GOOGLE = false
|
|
|
51
51
|
/** Allow `-`, but not leading, trailing or doubled. */
|
|
52
52
|
export const ALLOW_HYPHEN_GOOGLE = false
|
|
53
53
|
|
|
54
|
-
/// A notary states wall-clock time as it observes it, so the
|
|
55
|
-
/// observation is never ahead. Five minutes covers clock skew between
|
|
56
|
-
/// the notary and the chain.
|
|
57
|
-
export const FUTURE_ALLOWANCE_X = 300
|
|
58
|
-
/// Same as X: notary wall-clock, five minutes for skew.
|
|
59
|
-
export const FUTURE_ALLOWANCE_GITHUB = 300
|
|
60
|
-
/// The OIDC circuit exposes no `iat`, so the observation is the token's
|
|
61
|
-
/// `exp` — Google issues about an hour of life, and the claim therefore
|
|
62
|
-
/// reads roughly an hour ahead of the moment it describes.
|
|
63
|
-
export const FUTURE_ALLOWANCE_GOOGLE = 7200
|
|
64
|
-
|
|
65
54
|
export const ERROR_EMPTY = 0
|
|
66
55
|
export const ERROR_TOOLONG = 1
|
|
67
56
|
export const ERROR_BADCHARACTER = 2
|
package/src/identity/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// The wallet-agnostic identity system, TypeScript half.
|
|
2
2
|
///
|
|
3
3
|
/// Handle normalization mirrors the on-chain normalizer byte for byte, and the
|
|
4
|
-
/// resolvers wrap the `
|
|
4
|
+
/// resolvers wrap the `IdentityRegistry` view calls. Everything on-chain-shaped
|
|
5
5
|
/// comes from the generated ABIs in `../abis`, so this layer and the contracts
|
|
6
6
|
/// cannot drift apart silently.
|
|
7
7
|
///
|
|
@@ -10,4 +10,5 @@
|
|
|
10
10
|
|
|
11
11
|
export * from './handle.js'
|
|
12
12
|
export * from './handleVectors.js'
|
|
13
|
+
export * from './node.js'
|
|
13
14
|
export * from './resolve.js'
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
}
|
package/src/identity/resolve.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/// Reading
|
|
1
|
+
/// Reading identities from the chain.
|
|
2
2
|
///
|
|
3
|
-
/// Everything here is a view call.
|
|
4
|
-
/// wallet; reading one needs neither, which is the point — any product
|
|
5
|
-
/// resolve a
|
|
3
|
+
/// Everything here is a view call. Binding an identity needs a ceremony payload
|
|
4
|
+
/// and a wallet; reading one needs neither, which is the point — any product
|
|
5
|
+
/// can resolve a handle without touching the ceremony that bound it.
|
|
6
6
|
///
|
|
7
7
|
/// The client and the contract address are arguments rather than imports. This
|
|
8
8
|
/// package ships separately from the repository it currently lives in, so it
|
|
@@ -10,17 +10,23 @@
|
|
|
10
10
|
|
|
11
11
|
import { type Address, keccak256, type PublicClient, toHex, zeroAddress } from 'viem'
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import { identityRegistryAbi } from '../abis/identityRegistry.js'
|
|
14
|
+
import type { Rules } from './handle.js'
|
|
14
15
|
|
|
15
|
-
/// A platform
|
|
16
|
+
/// A platform key (`'x'`, `'github'`, ...), refusing at compile time a value
|
|
17
|
+
/// typed as hex: an id passed where a key belongs would be hashed again into a
|
|
18
|
+
/// platform nothing binds.
|
|
19
|
+
export type PlatformKey<K extends string> = K extends `0x${string}` ? never : K
|
|
20
|
+
|
|
21
|
+
/// A platform id is `keccak256` of its platform key. The keys are generated
|
|
16
22
|
/// from `handles.json`, so this and the contract agree by construction.
|
|
17
|
-
export function platformId(
|
|
18
|
-
return keccak256(toHex(
|
|
23
|
+
export function platformId<K extends string>(platformKey: PlatformKey<K>): `0x${string}` {
|
|
24
|
+
return keccak256(toHex(platformKey))
|
|
19
25
|
}
|
|
20
26
|
|
|
21
|
-
export interface
|
|
27
|
+
export interface RegistryReader {
|
|
22
28
|
client: PublicClient
|
|
23
|
-
/// The deployed `
|
|
29
|
+
/// The deployed `IdentityRegistry` contract.
|
|
24
30
|
address: Address
|
|
25
31
|
}
|
|
26
32
|
|
|
@@ -30,7 +36,11 @@ export interface NamesReader {
|
|
|
30
36
|
/// viem's `PublicClient`, without its chain type parameters, types
|
|
31
37
|
/// `authorizationList` as required even for a read. The alternative is to
|
|
32
38
|
/// spread that noise across every call site here.
|
|
33
|
-
function read<T>(
|
|
39
|
+
function read<T>(
|
|
40
|
+
reader: RegistryReader,
|
|
41
|
+
functionName: string,
|
|
42
|
+
args: readonly unknown[],
|
|
43
|
+
): Promise<T> {
|
|
34
44
|
return (
|
|
35
45
|
reader.client as unknown as {
|
|
36
46
|
readContract: (request: Record<string, unknown>) => Promise<T>
|
|
@@ -38,74 +48,74 @@ function read<T>(reader: NamesReader, functionName: string, args: readonly unkno
|
|
|
38
48
|
).readContract({
|
|
39
49
|
authorizationList: undefined,
|
|
40
50
|
address: reader.address,
|
|
41
|
-
abi:
|
|
51
|
+
abi: identityRegistryAbi,
|
|
42
52
|
functionName,
|
|
43
53
|
args,
|
|
44
54
|
})
|
|
45
55
|
}
|
|
46
56
|
|
|
47
|
-
/// The
|
|
57
|
+
/// The platform's normalization rules as configured on chain now
|
|
58
|
+
/// (`IdentityRegistry.rulesOf`).
|
|
59
|
+
export async function rulesOf(reader: RegistryReader, platformId: `0x${string}`): Promise<Rules> {
|
|
60
|
+
const rules = await read<Rules>(reader, 'rulesOf', [platformId])
|
|
61
|
+
return {
|
|
62
|
+
maxLength: Number(rules.maxLength),
|
|
63
|
+
stripLeadingAt: rules.stripLeadingAt,
|
|
64
|
+
isEmail: rules.isEmail,
|
|
65
|
+
allowUnderscore: rules.allowUnderscore,
|
|
66
|
+
allowHyphen: rules.allowHyphen,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/// The holder that proved this id, or `null`.
|
|
48
71
|
export async function resolveId(
|
|
49
|
-
reader:
|
|
50
|
-
|
|
51
|
-
|
|
72
|
+
reader: RegistryReader,
|
|
73
|
+
platformId: `0x${string}`,
|
|
74
|
+
id: string,
|
|
52
75
|
): Promise<Address | null> {
|
|
53
|
-
const
|
|
54
|
-
return
|
|
76
|
+
const holder = await read<Address>(reader, 'resolveId', [platformId, id])
|
|
77
|
+
return holder === zeroAddress ? null : holder
|
|
55
78
|
}
|
|
56
79
|
|
|
57
|
-
/// The
|
|
80
|
+
/// The holder that last proved this handle, or `null`.
|
|
58
81
|
///
|
|
59
82
|
/// The handle is normalized on chain before it is looked up, so a caller may
|
|
60
|
-
/// pass what
|
|
61
|
-
/// The contract is total in the handle: a string
|
|
62
|
-
/// the zero address, which is the same answer as a handle nobody has
|
|
63
|
-
/// and the one a search box wants.
|
|
83
|
+
/// pass what was typed — including something that is not a handle at all.
|
|
84
|
+
/// The contract is total in the handle: a string the platform's rules refuse
|
|
85
|
+
/// answers the zero address, which is the same answer as a handle nobody has
|
|
86
|
+
/// proved, and the one a search box wants.
|
|
64
87
|
///
|
|
65
88
|
/// A revert propagates. `UnknownPlatform` in particular means the platform is
|
|
66
|
-
/// not configured, and answering "
|
|
89
|
+
/// not configured, and answering "unbound" would bury a deployment mistake
|
|
67
90
|
/// under a plausible result.
|
|
68
91
|
export async function resolveHandle(
|
|
69
|
-
reader:
|
|
70
|
-
|
|
92
|
+
reader: RegistryReader,
|
|
93
|
+
platformId: `0x${string}`,
|
|
71
94
|
handle: string,
|
|
72
95
|
): Promise<Address | null> {
|
|
73
|
-
const
|
|
74
|
-
return
|
|
96
|
+
const holder = await read<Address>(reader, 'resolveHandle', [platformId, handle])
|
|
97
|
+
return holder === zeroAddress ? null : holder
|
|
75
98
|
}
|
|
76
99
|
|
|
77
|
-
/// The handle a
|
|
78
|
-
///
|
|
79
|
-
/// It may be stale: it says what the wallet proved once, not what the handle
|
|
80
|
-
/// resolves to now. Use `primaryName` to display one.
|
|
81
|
-
export async function reverseOf(
|
|
82
|
-
reader: NamesReader,
|
|
83
|
-
wallet: Address,
|
|
84
|
-
platform: `0x${string}`,
|
|
85
|
-
): Promise<string | null> {
|
|
86
|
-
const name = await read<string>(reader, 'reverseOf', [wallet, platform])
|
|
87
|
-
return name.length === 0 ? null : name
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/// The handle to show for a wallet, or `null`.
|
|
100
|
+
/// The handle to show for a holder, or `null`.
|
|
91
101
|
///
|
|
92
102
|
/// Forward-checked on chain: empty once the stored handle resolves somewhere
|
|
93
103
|
/// else. ENS asks integrators to perform that check themselves and warns that
|
|
94
|
-
/// skipping it displays
|
|
95
|
-
/// skipped, because the contract does it.
|
|
96
|
-
export async function
|
|
97
|
-
reader:
|
|
98
|
-
|
|
99
|
-
|
|
104
|
+
/// skipping it displays an ENS primary name that no longer resolves back; here
|
|
105
|
+
/// it cannot be skipped, because the contract does it.
|
|
106
|
+
export async function publishedHandleOf(
|
|
107
|
+
reader: RegistryReader,
|
|
108
|
+
holder: Address,
|
|
109
|
+
platformId: `0x${string}`,
|
|
100
110
|
): Promise<string | null> {
|
|
101
|
-
const
|
|
102
|
-
return
|
|
111
|
+
const handle = await read<string>(reader, 'publishedHandleOf', [holder, platformId])
|
|
112
|
+
return handle.length === 0 ? null : handle
|
|
103
113
|
}
|
|
104
114
|
|
|
105
|
-
export interface
|
|
106
|
-
/// The
|
|
107
|
-
|
|
108
|
-
/// True only when the
|
|
115
|
+
export interface HandleAndIdResolution {
|
|
116
|
+
/// The handle's holder, or `null`.
|
|
117
|
+
holder: Address | null
|
|
118
|
+
/// True only when the id resolves to that same holder.
|
|
109
119
|
///
|
|
110
120
|
/// False means the caller's `(handle, id)` pair comes from two moments:
|
|
111
121
|
/// somebody proved the handle after the caller learned who held it. That is
|
|
@@ -113,29 +123,77 @@ export interface PairResolution {
|
|
|
113
123
|
idAgrees: boolean
|
|
114
124
|
}
|
|
115
125
|
|
|
116
|
-
/// Resolve a handle and report whether an
|
|
126
|
+
/// Resolve a handle and report whether an id still agrees with it.
|
|
117
127
|
///
|
|
118
|
-
/// **Read this before signing, and do not let it block a transfer.** A
|
|
119
|
-
/// that will not route is not a
|
|
128
|
+
/// **Read this before signing, and do not let it block a transfer.** A handle
|
|
129
|
+
/// that will not route is not a handle: sending to a handle means sending to
|
|
120
130
|
/// whoever proved it last, which is what the handle now means. What the flag is
|
|
121
|
-
/// for is telling
|
|
122
|
-
/// one that
|
|
131
|
+
/// for is telling whoever is paying that the identity they think they are
|
|
132
|
+
/// paying is not the one that has the handle today — a decision they can only
|
|
133
|
+
/// make beforehand.
|
|
123
134
|
///
|
|
124
135
|
/// Both halves are needed. A handle on its own has nothing to disagree with.
|
|
125
136
|
///
|
|
126
|
-
/// A handle the platform's rules reject resolves to `{
|
|
137
|
+
/// A handle the platform's rules reject resolves to `{holder: null, idAgrees:
|
|
127
138
|
/// false}`, the same as one nobody has proved — see `resolveHandle`.
|
|
128
|
-
export async function
|
|
129
|
-
reader:
|
|
130
|
-
|
|
139
|
+
export async function resolveHandleAndId(
|
|
140
|
+
reader: RegistryReader,
|
|
141
|
+
platformId: `0x${string}`,
|
|
131
142
|
handle: string,
|
|
132
|
-
|
|
133
|
-
): Promise<
|
|
134
|
-
const [
|
|
135
|
-
|
|
143
|
+
id: string,
|
|
144
|
+
): Promise<HandleAndIdResolution> {
|
|
145
|
+
const [holder, idAgrees] = await read<[Address, boolean]>(reader, 'resolveHandleAndId', [
|
|
146
|
+
platformId,
|
|
136
147
|
handle,
|
|
137
|
-
|
|
148
|
+
id,
|
|
138
149
|
])
|
|
139
150
|
|
|
140
|
-
return {
|
|
151
|
+
return { holder: holder === zeroAddress ? null : holder, idAgrees }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/// One identity a holder proved, as the holder's list reports it.
|
|
155
|
+
export interface Identity {
|
|
156
|
+
/// The platform the identity is on, as `platformId` derives it.
|
|
157
|
+
platformId: `0x${string}`
|
|
158
|
+
/// The id, byte for byte as the platform issued it.
|
|
159
|
+
id: string
|
|
160
|
+
/// The handle this identity proved most recently, as normalized on chain.
|
|
161
|
+
handle: string
|
|
162
|
+
/// True while the handle node still points back at this identity.
|
|
163
|
+
///
|
|
164
|
+
/// False once another identity proves the same handle: the string stays as
|
|
165
|
+
/// the last thing this identity was known as, and the flag says not to route
|
|
166
|
+
/// by it.
|
|
167
|
+
handleCurrent: boolean
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/// How many identities a holder has, on every platform together.
|
|
171
|
+
export async function identityCount(reader: RegistryReader, holder: Address): Promise<bigint> {
|
|
172
|
+
return read<bigint>(reader, 'identityCount', [holder])
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/// A page of a holder's identities, on every platform together:
|
|
176
|
+
/// the indices `[from, from + limit)` of its list, counted from zero and
|
|
177
|
+
/// clipped to the list. A `from` past the end answers an empty page. A reader
|
|
178
|
+
/// that wants one platform filters a page by `platformId`.
|
|
179
|
+
///
|
|
180
|
+
/// Order is arbitrary and changes when an identity leaves the list, so two
|
|
181
|
+
/// pages read across a removal may overlap or skip. A reader that needs every
|
|
182
|
+
/// identity reads `identityCount` and the pages against one block.
|
|
183
|
+
///
|
|
184
|
+
/// A list is as long as its holder made it, and a call's gas is not. A caller
|
|
185
|
+
/// enumerating a holder it did not choose keeps `limit` small and pages.
|
|
186
|
+
export async function identitiesOf(
|
|
187
|
+
reader: RegistryReader,
|
|
188
|
+
holder: Address,
|
|
189
|
+
from: bigint,
|
|
190
|
+
limit: bigint,
|
|
191
|
+
): Promise<Identity[]> {
|
|
192
|
+
const page = await read<readonly Identity[]>(reader, 'identitiesOf', [holder, from, limit])
|
|
193
|
+
return page.map(({ platformId, id, handle, handleCurrent }) => ({
|
|
194
|
+
platformId,
|
|
195
|
+
id,
|
|
196
|
+
handle,
|
|
197
|
+
handleCurrent,
|
|
198
|
+
}))
|
|
141
199
|
}
|