@libid/contracts 0.1.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 +96 -0
- package/dist/abis/adminFacet.d.ts +339 -0
- package/dist/abis/adminFacet.d.ts.map +1 -0
- package/dist/abis/adminFacet.js +442 -0
- package/dist/abis/adminFacet.js.map +1 -0
- package/dist/abis/bank.d.ts +916 -0
- package/dist/abis/bank.d.ts.map +1 -0
- package/dist/abis/bank.js +1184 -0
- package/dist/abis/bank.js.map +1 -0
- package/dist/abis/diamondLoupeFacet.d.ts +73 -0
- package/dist/abis/diamondLoupeFacet.d.ts.map +1 -0
- package/dist/abis/diamondLoupeFacet.js +100 -0
- package/dist/abis/diamondLoupeFacet.js.map +1 -0
- package/dist/abis/gitHubIdentityVerifier.d.ts +451 -0
- package/dist/abis/gitHubIdentityVerifier.d.ts.map +1 -0
- package/dist/abis/gitHubIdentityVerifier.js +586 -0
- package/dist/abis/gitHubIdentityVerifier.js.map +1 -0
- package/dist/abis/googleIdentityVerifier.d.ts +373 -0
- package/dist/abis/googleIdentityVerifier.d.ts.map +1 -0
- package/dist/abis/googleIdentityVerifier.js +485 -0
- package/dist/abis/googleIdentityVerifier.js.map +1 -0
- package/dist/abis/googleOidcVerifier.d.ts +743 -0
- package/dist/abis/googleOidcVerifier.d.ts.map +1 -0
- package/dist/abis/googleOidcVerifier.js +962 -0
- package/dist/abis/googleOidcVerifier.js.map +1 -0
- package/dist/abis/identityJwksRoots.d.ts +515 -0
- package/dist/abis/identityJwksRoots.d.ts.map +1 -0
- package/dist/abis/identityJwksRoots.js +669 -0
- package/dist/abis/identityJwksRoots.js.map +1 -0
- package/dist/abis/identityNames.d.ts +614 -0
- package/dist/abis/identityNames.d.ts.map +1 -0
- package/dist/abis/identityNames.js +798 -0
- package/dist/abis/identityNames.js.map +1 -0
- package/dist/abis/index.d.ts +19 -0
- package/dist/abis/index.d.ts.map +1 -0
- package/dist/abis/index.js +21 -0
- package/dist/abis/index.js.map +1 -0
- package/dist/abis/mockErc20.d.ts +262 -0
- package/dist/abis/mockErc20.d.ts.map +1 -0
- package/dist/abis/mockErc20.js +347 -0
- package/dist/abis/mockErc20.js.map +1 -0
- package/dist/abis/notaryRegistry.d.ts +272 -0
- package/dist/abis/notaryRegistry.d.ts.map +1 -0
- package/dist/abis/notaryRegistry.js +355 -0
- package/dist/abis/notaryRegistry.js.map +1 -0
- package/dist/abis/registry.d.ts +1166 -0
- package/dist/abis/registry.d.ts.map +1 -0
- package/dist/abis/registry.js +1506 -0
- package/dist/abis/registry.js.map +1 -0
- package/dist/abis/transferFacet.d.ts +814 -0
- package/dist/abis/transferFacet.d.ts.map +1 -0
- package/dist/abis/transferFacet.js +1035 -0
- package/dist/abis/transferFacet.js.map +1 -0
- package/dist/abis/vaultFacet.d.ts +306 -0
- package/dist/abis/vaultFacet.d.ts.map +1 -0
- package/dist/abis/vaultFacet.js +398 -0
- package/dist/abis/vaultFacet.js.map +1 -0
- package/dist/abis/walletFactory.d.ts +325 -0
- package/dist/abis/walletFactory.d.ts.map +1 -0
- package/dist/abis/walletFactory.js +424 -0
- package/dist/abis/walletFactory.js.map +1 -0
- package/dist/abis/webWallet.d.ts +523 -0
- package/dist/abis/webWallet.d.ts.map +1 -0
- package/dist/abis/webWallet.js +680 -0
- package/dist/abis/webWallet.js.map +1 -0
- package/dist/abis/wtia9.d.ts +233 -0
- package/dist/abis/wtia9.d.ts.map +1 -0
- package/dist/abis/wtia9.js +304 -0
- package/dist/abis/wtia9.js.map +1 -0
- package/dist/abis/xIdentityVerifier.d.ts +487 -0
- package/dist/abis/xIdentityVerifier.d.ts.map +1 -0
- package/dist/abis/xIdentityVerifier.js +631 -0
- package/dist/abis/xIdentityVerifier.js.map +1 -0
- package/dist/abis/xZkVerifier.d.ts +586 -0
- package/dist/abis/xZkVerifier.d.ts.map +1 -0
- package/dist/abis/xZkVerifier.js +760 -0
- package/dist/abis/xZkVerifier.js.map +1 -0
- package/dist/identity/bind.d.ts +60 -0
- package/dist/identity/bind.d.ts.map +1 -0
- package/dist/identity/bind.fixtures.d.ts +8 -0
- package/dist/identity/bind.fixtures.d.ts.map +1 -0
- package/dist/identity/bind.fixtures.js +57 -0
- package/dist/identity/bind.fixtures.js.map +1 -0
- package/dist/identity/bind.js +119 -0
- package/dist/identity/bind.js.map +1 -0
- package/dist/identity/handle.d.ts +22 -0
- package/dist/identity/handle.d.ts.map +1 -0
- package/dist/identity/handle.js +137 -0
- package/dist/identity/handle.js.map +1 -0
- package/dist/identity/handleVectors.d.ts +53 -0
- package/dist/identity/handleVectors.d.ts.map +1 -0
- package/dist/identity/handleVectors.js +99 -0
- package/dist/identity/handleVectors.js.map +1 -0
- package/dist/identity/index.d.ts +5 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +12 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/identity/resolve.d.ts +16 -0
- package/dist/identity/resolve.d.ts.map +1 -0
- package/dist/identity/resolve.js +90 -0
- package/dist/identity/resolve.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
- package/src/abis/adminFacet.ts +444 -0
- package/src/abis/bank.ts +1186 -0
- package/src/abis/diamondLoupeFacet.ts +102 -0
- package/src/abis/gitHubIdentityVerifier.ts +588 -0
- package/src/abis/googleIdentityVerifier.ts +487 -0
- package/src/abis/googleOidcVerifier.ts +964 -0
- package/src/abis/identityJwksRoots.ts +671 -0
- package/src/abis/identityNames.ts +800 -0
- package/src/abis/index.ts +20 -0
- package/src/abis/mockErc20.ts +349 -0
- package/src/abis/notaryRegistry.ts +357 -0
- package/src/abis/registry.ts +1508 -0
- package/src/abis/transferFacet.ts +1037 -0
- package/src/abis/vaultFacet.ts +400 -0
- package/src/abis/walletFactory.ts +426 -0
- package/src/abis/webWallet.ts +682 -0
- package/src/abis/wtia9.ts +306 -0
- package/src/abis/xIdentityVerifier.ts +633 -0
- package/src/abis/xZkVerifier.ts +762 -0
- package/src/identity/bind.fixtures.ts +65 -0
- package/src/identity/bind.ts +209 -0
- package/src/identity/handle.ts +170 -0
- package/src/identity/handleVectors.ts +115 -0
- package/src/identity/index.ts +12 -0
- package/src/identity/resolve.ts +141 -0
- package/src/index.ts +6 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/// The proofs the encoding tests pin.
|
|
2
|
+
///
|
|
3
|
+
/// Their own module so the generator that writes `fixtures/bind-encoding.json`
|
|
4
|
+
/// and the test that checks against it read the same values — and so the shapes
|
|
5
|
+
/// double as a worked example of what each verifier takes.
|
|
6
|
+
|
|
7
|
+
import type { Address, Hex } from 'viem'
|
|
8
|
+
|
|
9
|
+
import type { GitHubProof, GoogleProof, XProof } from './bind.js'
|
|
10
|
+
|
|
11
|
+
export const NAMES = '0x1111111111111111111111111111111111111111' as Address
|
|
12
|
+
const WALLET = '0x2222222222222222222222222222222222222222' as Address
|
|
13
|
+
const SESSION = '0x3333333333333333333333333333333333333333' as Address
|
|
14
|
+
|
|
15
|
+
export const b32 = (n: number): Hex => `0x${n.toString(16).padStart(64, '0')}`
|
|
16
|
+
|
|
17
|
+
export const GITHUB_FIXTURE: GitHubProof = {
|
|
18
|
+
tls: {
|
|
19
|
+
notarySignature: '0xaabb',
|
|
20
|
+
backendSignature: '0xccdd',
|
|
21
|
+
userAddress: SESSION,
|
|
22
|
+
walletAddress: WALLET,
|
|
23
|
+
domainHash: b32(1),
|
|
24
|
+
clientRandom: b32(2),
|
|
25
|
+
serverRandom: b32(3),
|
|
26
|
+
serverEphemeralKey: '0xeeff',
|
|
27
|
+
transcriptRoot: b32(4),
|
|
28
|
+
timestamp: 1_700_000_000n,
|
|
29
|
+
domainPath: [b32(5), b32(6)],
|
|
30
|
+
usernamePath: [b32(7)],
|
|
31
|
+
endpointPath: [],
|
|
32
|
+
idPath: [b32(8), b32(9), b32(10)],
|
|
33
|
+
},
|
|
34
|
+
domain: 'api.github.com',
|
|
35
|
+
handle: 'octocat',
|
|
36
|
+
userId: '583231',
|
|
37
|
+
endpoint: '/user',
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const X_FIXTURE: XProof = {
|
|
41
|
+
proof: '0x1234',
|
|
42
|
+
publicInputs: [b32(11), b32(12)],
|
|
43
|
+
meAttest: {
|
|
44
|
+
bearerHash: b32(13),
|
|
45
|
+
bearerRangeStart: 100,
|
|
46
|
+
bearerRangeEnd: 200,
|
|
47
|
+
sentRevealed: '0x5566',
|
|
48
|
+
sentPrefixEnd: 100,
|
|
49
|
+
sentSuffixEnd: 202,
|
|
50
|
+
recvRevealed: '0x7788',
|
|
51
|
+
handle: 'alice',
|
|
52
|
+
userId: '42',
|
|
53
|
+
sessionAddr: SESSION,
|
|
54
|
+
timestamp: 1_700_000_001n,
|
|
55
|
+
notarySignature: '0x99aa',
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const GOOGLE_FIXTURE: GoogleProof = {
|
|
60
|
+
honkProof: '0xbbcc',
|
|
61
|
+
publicInputs: [b32(14), b32(15), b32(16)],
|
|
62
|
+
email: 'alice@example.com',
|
|
63
|
+
sessionKey: WALLET,
|
|
64
|
+
sub: '1234567890',
|
|
65
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/// Binding a name: the write half.
|
|
2
|
+
///
|
|
3
|
+
/// Reading a name is a view call and needs nothing. Writing one is a
|
|
4
|
+
/// transaction the holder's own address sends, because `IdentityNames` requires
|
|
5
|
+
/// the proof's target to be the caller — that single rule is the whole of the
|
|
6
|
+
/// authorization, and it is why a proof read from the mempool is useless to
|
|
7
|
+
/// anybody else.
|
|
8
|
+
///
|
|
9
|
+
/// This module builds the calldata and nothing more. It does not sign, does not
|
|
10
|
+
/// send, and does not know what kind of address the caller is: an EOA sends it
|
|
11
|
+
/// directly, a smart account wraps it in whatever its own execute looks like.
|
|
12
|
+
/// Keeping it at calldata is what lets a product with its own account model use
|
|
13
|
+
/// the naming system without either side knowing about the other.
|
|
14
|
+
|
|
15
|
+
import { type Address, encodeAbiParameters, encodeFunctionData, type Hex } from 'viem'
|
|
16
|
+
|
|
17
|
+
import { identityNamesAbi } from '../abis/identityNames.js'
|
|
18
|
+
|
|
19
|
+
/// The proof each platform's verifier takes, as it travels on chain.
|
|
20
|
+
///
|
|
21
|
+
/// The verifier decodes one `bytes` argument, so a platform's fields are
|
|
22
|
+
/// abi-encoded into it here. The shapes mirror the verifier structs exactly; a
|
|
23
|
+
/// mismatch does not compile there and reverts here, which is why they are
|
|
24
|
+
/// written out rather than built by hand at a call site.
|
|
25
|
+
|
|
26
|
+
/// One notarized TLS session, as `GitHubIdentityVerifier` takes it.
|
|
27
|
+
export interface TlsProof {
|
|
28
|
+
notarySignature: Hex
|
|
29
|
+
backendSignature: Hex
|
|
30
|
+
userAddress: Address
|
|
31
|
+
/// The address the proof is made out to. `IdentityNames` refuses a zero.
|
|
32
|
+
walletAddress: Address
|
|
33
|
+
domainHash: Hex
|
|
34
|
+
clientRandom: Hex
|
|
35
|
+
serverRandom: Hex
|
|
36
|
+
serverEphemeralKey: Hex
|
|
37
|
+
transcriptRoot: Hex
|
|
38
|
+
timestamp: bigint
|
|
39
|
+
domainPath: readonly Hex[]
|
|
40
|
+
usernamePath: readonly Hex[]
|
|
41
|
+
endpointPath: readonly Hex[]
|
|
42
|
+
idPath: readonly Hex[]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface GitHubProof {
|
|
46
|
+
tls: TlsProof
|
|
47
|
+
domain: string
|
|
48
|
+
handle: string
|
|
49
|
+
userId: string
|
|
50
|
+
endpoint: string
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/// The notarized `/me` session, as `XIdentityVerifier` takes it. There is only
|
|
54
|
+
/// one: a name binding does not read the OAuth client id, so it never asks for
|
|
55
|
+
/// the `/token` session that exists to carry it.
|
|
56
|
+
export interface MeAttestation {
|
|
57
|
+
bearerHash: Hex
|
|
58
|
+
bearerRangeStart: number
|
|
59
|
+
bearerRangeEnd: number
|
|
60
|
+
sentRevealed: Hex
|
|
61
|
+
sentPrefixEnd: number
|
|
62
|
+
sentSuffixEnd: number
|
|
63
|
+
recvRevealed: Hex
|
|
64
|
+
handle: string
|
|
65
|
+
userId: string
|
|
66
|
+
sessionAddr: Address
|
|
67
|
+
timestamp: bigint
|
|
68
|
+
notarySignature: Hex
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface XProof {
|
|
72
|
+
proof: Hex
|
|
73
|
+
publicInputs: readonly Hex[]
|
|
74
|
+
meAttest: MeAttestation
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface GoogleProof {
|
|
78
|
+
honkProof: Hex
|
|
79
|
+
publicInputs: readonly Hex[]
|
|
80
|
+
email: string
|
|
81
|
+
/// The address inside the Google-signed nonce. This is the target, so it must
|
|
82
|
+
/// be the address that will hold the name — the wallet, not a session key.
|
|
83
|
+
sessionKey: Address
|
|
84
|
+
sub: string
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const tlsProofComponents = [
|
|
88
|
+
{ name: 'notarySignature', type: 'bytes' },
|
|
89
|
+
{ name: 'backendSignature', type: 'bytes' },
|
|
90
|
+
{ name: 'userAddress', type: 'address' },
|
|
91
|
+
{ name: 'walletAddress', type: 'address' },
|
|
92
|
+
{ name: 'domainHash', type: 'bytes32' },
|
|
93
|
+
{ name: 'clientRandom', type: 'bytes32' },
|
|
94
|
+
{ name: 'serverRandom', type: 'bytes32' },
|
|
95
|
+
{ name: 'serverEphemeralKey', type: 'bytes' },
|
|
96
|
+
{ name: 'transcriptRoot', type: 'bytes32' },
|
|
97
|
+
{ name: 'timestamp', type: 'uint256' },
|
|
98
|
+
{ name: 'domainPath', type: 'bytes32[]' },
|
|
99
|
+
{ name: 'usernamePath', type: 'bytes32[]' },
|
|
100
|
+
{ name: 'endpointPath', type: 'bytes32[]' },
|
|
101
|
+
{ name: 'idPath', type: 'bytes32[]' },
|
|
102
|
+
] as const
|
|
103
|
+
|
|
104
|
+
export function encodeGitHubProof(p: GitHubProof): Hex {
|
|
105
|
+
return encodeAbiParameters(
|
|
106
|
+
[
|
|
107
|
+
{
|
|
108
|
+
type: 'tuple',
|
|
109
|
+
components: [
|
|
110
|
+
{ name: 'tls', type: 'tuple', components: tlsProofComponents },
|
|
111
|
+
{ name: 'domain', type: 'string' },
|
|
112
|
+
{ name: 'handle', type: 'string' },
|
|
113
|
+
{ name: 'userId', type: 'string' },
|
|
114
|
+
{ name: 'endpoint', type: 'string' },
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
[p],
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function encodeXProof(p: XProof): Hex {
|
|
123
|
+
return encodeAbiParameters(
|
|
124
|
+
[
|
|
125
|
+
{
|
|
126
|
+
type: 'tuple',
|
|
127
|
+
components: [
|
|
128
|
+
{ name: 'proof', type: 'bytes' },
|
|
129
|
+
{ name: 'publicInputs', type: 'bytes32[]' },
|
|
130
|
+
{
|
|
131
|
+
name: 'meAttest',
|
|
132
|
+
type: 'tuple',
|
|
133
|
+
components: [
|
|
134
|
+
{ name: 'bearerHash', type: 'bytes32' },
|
|
135
|
+
{ name: 'bearerRangeStart', type: 'uint32' },
|
|
136
|
+
{ name: 'bearerRangeEnd', type: 'uint32' },
|
|
137
|
+
{ name: 'sentRevealed', type: 'bytes' },
|
|
138
|
+
{ name: 'sentPrefixEnd', type: 'uint32' },
|
|
139
|
+
{ name: 'sentSuffixEnd', type: 'uint32' },
|
|
140
|
+
{ name: 'recvRevealed', type: 'bytes' },
|
|
141
|
+
{ name: 'handle', type: 'string' },
|
|
142
|
+
{ name: 'userId', type: 'string' },
|
|
143
|
+
{ name: 'sessionAddr', type: 'address' },
|
|
144
|
+
{ name: 'timestamp', type: 'uint64' },
|
|
145
|
+
{ name: 'notarySignature', type: 'bytes' },
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
[p],
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function encodeGoogleProof(p: GoogleProof): Hex {
|
|
156
|
+
return encodeAbiParameters(
|
|
157
|
+
[
|
|
158
|
+
{
|
|
159
|
+
type: 'tuple',
|
|
160
|
+
components: [
|
|
161
|
+
{ name: 'honkProof', type: 'bytes' },
|
|
162
|
+
{ name: 'publicInputs', type: 'bytes32[]' },
|
|
163
|
+
{ name: 'email', type: 'string' },
|
|
164
|
+
{ name: 'sessionKey', type: 'address' },
|
|
165
|
+
{ name: 'sub', type: 'string' },
|
|
166
|
+
],
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
[p],
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/// One call, ready to send or to wrap.
|
|
174
|
+
export interface Call {
|
|
175
|
+
to: Address
|
|
176
|
+
data: Hex
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/// Bind a proven account to the caller.
|
|
180
|
+
///
|
|
181
|
+
/// `publishName` also stores the handle as a string, so a contract can read the
|
|
182
|
+
/// reverse direction on chain. The event carries the plaintext either way, so
|
|
183
|
+
/// an indexer never needs it — say true only when something on chain must
|
|
184
|
+
/// display the name. For Google the handle is an email address, which is worth
|
|
185
|
+
/// a thought before publishing it.
|
|
186
|
+
export function bindCall(names: Address, platformId: Hex, proof: Hex, publishName: boolean): Call {
|
|
187
|
+
return {
|
|
188
|
+
to: names,
|
|
189
|
+
data: encodeFunctionData({
|
|
190
|
+
abi: identityNamesAbi,
|
|
191
|
+
functionName: 'bind',
|
|
192
|
+
args: [platformId, proof, publishName],
|
|
193
|
+
}),
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/// Withdraw a published handle. The binding itself stays: this stops the chain
|
|
198
|
+
/// displaying the string, and needs no proof, because withdrawing what you
|
|
199
|
+
/// chose to show must not depend on being able to log in again.
|
|
200
|
+
export function unpublishCall(names: Address, platformId: Hex): Call {
|
|
201
|
+
return {
|
|
202
|
+
to: names,
|
|
203
|
+
data: encodeFunctionData({
|
|
204
|
+
abi: identityNamesAbi,
|
|
205
|
+
functionName: 'unpublish',
|
|
206
|
+
args: [platformId],
|
|
207
|
+
}),
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/// Turns a platform handle into the one form the identity system keys.
|
|
2
|
+
///
|
|
3
|
+
/// This mirrors `solidity/contracts/identity/HandleNormalizer.sol` and
|
|
4
|
+
/// `rust/identity/src/handle.rs` byte for byte. The three transforms
|
|
5
|
+
/// are hand written; the rules they run and the vectors they are checked
|
|
6
|
+
/// against are generated from `solidity/contracts/identity/handles.json`, so a
|
|
7
|
+
/// difference between them fails a test instead of looking up a key the chain
|
|
8
|
+
/// never wrote.
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
ALLOW_HYPHEN_GITHUB,
|
|
12
|
+
ALLOW_HYPHEN_GOOGLE,
|
|
13
|
+
ALLOW_HYPHEN_X,
|
|
14
|
+
ALLOW_UNDERSCORE_GITHUB,
|
|
15
|
+
ALLOW_UNDERSCORE_GOOGLE,
|
|
16
|
+
ALLOW_UNDERSCORE_X,
|
|
17
|
+
ERROR_BADCHARACTER,
|
|
18
|
+
ERROR_BADSHAPE,
|
|
19
|
+
ERROR_EMPTY,
|
|
20
|
+
ERROR_TOOLONG,
|
|
21
|
+
IS_EMAIL_GITHUB,
|
|
22
|
+
IS_EMAIL_GOOGLE,
|
|
23
|
+
IS_EMAIL_X,
|
|
24
|
+
MAX_LENGTH_GITHUB,
|
|
25
|
+
MAX_LENGTH_GOOGLE,
|
|
26
|
+
MAX_LENGTH_X,
|
|
27
|
+
STRIP_LEADING_AT_GITHUB,
|
|
28
|
+
STRIP_LEADING_AT_GOOGLE,
|
|
29
|
+
STRIP_LEADING_AT_X,
|
|
30
|
+
} from './handleVectors.js'
|
|
31
|
+
|
|
32
|
+
/// Why a handle was refused. The kinds match the Solidity errors and the Rust
|
|
33
|
+
/// ones, because the vector table names which refusal it expects.
|
|
34
|
+
export class HandleError extends Error {
|
|
35
|
+
constructor(
|
|
36
|
+
readonly kind: number,
|
|
37
|
+
message: string,
|
|
38
|
+
) {
|
|
39
|
+
super(message)
|
|
40
|
+
this.name = 'HandleError'
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const EMPTY = () => new HandleError(ERROR_EMPTY, 'the handle is empty')
|
|
45
|
+
const TOO_LONG = () => new HandleError(ERROR_TOOLONG, 'the handle is too long for this platform')
|
|
46
|
+
const BAD_CHARACTER = () =>
|
|
47
|
+
new HandleError(ERROR_BADCHARACTER, 'the handle has a character this platform does not allow')
|
|
48
|
+
const BAD_SHAPE = () =>
|
|
49
|
+
new HandleError(ERROR_BADSHAPE, 'the handle has an arrangement this platform does not allow')
|
|
50
|
+
|
|
51
|
+
/// What one platform accepts. Held per platform, so a new platform is
|
|
52
|
+
/// configuration rather than code.
|
|
53
|
+
export interface Rules {
|
|
54
|
+
/** Bytes allowed after trimming and the `@` strip. */
|
|
55
|
+
maxLength: number
|
|
56
|
+
/** Remove one leading `@`. X and GitHub do. An email keeps its own `@`. */
|
|
57
|
+
stripLeadingAt: boolean
|
|
58
|
+
/** Validate as an address instead of a bare handle. */
|
|
59
|
+
isEmail: boolean
|
|
60
|
+
/** Allowed by X, not by GitHub. */
|
|
61
|
+
allowUnderscore: boolean
|
|
62
|
+
/** A hyphen may not start or end the handle, and two may not touch. */
|
|
63
|
+
allowHyphen: boolean
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const RULES_X: Rules = {
|
|
67
|
+
maxLength: MAX_LENGTH_X,
|
|
68
|
+
stripLeadingAt: STRIP_LEADING_AT_X,
|
|
69
|
+
isEmail: IS_EMAIL_X,
|
|
70
|
+
allowUnderscore: ALLOW_UNDERSCORE_X,
|
|
71
|
+
allowHyphen: ALLOW_HYPHEN_X,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const RULES_GITHUB: Rules = {
|
|
75
|
+
maxLength: MAX_LENGTH_GITHUB,
|
|
76
|
+
stripLeadingAt: STRIP_LEADING_AT_GITHUB,
|
|
77
|
+
isEmail: IS_EMAIL_GITHUB,
|
|
78
|
+
allowUnderscore: ALLOW_UNDERSCORE_GITHUB,
|
|
79
|
+
allowHyphen: ALLOW_HYPHEN_GITHUB,
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const RULES_GOOGLE: Rules = {
|
|
83
|
+
maxLength: MAX_LENGTH_GOOGLE,
|
|
84
|
+
stripLeadingAt: STRIP_LEADING_AT_GOOGLE,
|
|
85
|
+
isEmail: IS_EMAIL_GOOGLE,
|
|
86
|
+
allowUnderscore: ALLOW_UNDERSCORE_GOOGLE,
|
|
87
|
+
allowHyphen: ALLOW_HYPHEN_GOOGLE,
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/// The rules for a platform key from the vector table.
|
|
91
|
+
export function rulesFor(platform: string): Rules | null {
|
|
92
|
+
if (platform === 'x') return RULES_X
|
|
93
|
+
if (platform === 'github') return RULES_GITHUB
|
|
94
|
+
if (platform === 'google') return RULES_GOOGLE
|
|
95
|
+
return null
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/// The normalized handle, or a `HandleError` naming what was wrong.
|
|
99
|
+
export function normalize(raw: string, rules: Rules): string {
|
|
100
|
+
// Work on bytes, not code units. A character above 0x7f is several bytes and
|
|
101
|
+
// must be refused as bytes, the way Solidity sees it.
|
|
102
|
+
const input = new TextEncoder().encode(raw)
|
|
103
|
+
|
|
104
|
+
// Trim ASCII spaces only. A tab or a newline is not whitespace to remove
|
|
105
|
+
// here; it is a byte the platform does not allow, and the character check
|
|
106
|
+
// below refuses it. Trimming it would accept "ali\tce" as "alice" here and
|
|
107
|
+
// refuse it on chain.
|
|
108
|
+
let start = 0
|
|
109
|
+
let end = input.length
|
|
110
|
+
while (start < end && input[start] === 0x20) start++
|
|
111
|
+
while (end > start && input[end - 1] === 0x20) end--
|
|
112
|
+
|
|
113
|
+
if (rules.stripLeadingAt && end > start && input[start] === 0x40) start++
|
|
114
|
+
|
|
115
|
+
const length = end - start
|
|
116
|
+
if (length === 0) throw EMPTY()
|
|
117
|
+
if (length > rules.maxLength) throw TOO_LONG()
|
|
118
|
+
|
|
119
|
+
const out = new Uint8Array(length)
|
|
120
|
+
for (let i = 0; i < length; i++) {
|
|
121
|
+
let c = input[start + i]
|
|
122
|
+
// Fold A-Z down. Nothing else changes, so two addresses that differ in more
|
|
123
|
+
// than case stay two identities.
|
|
124
|
+
if (c >= 0x41 && c <= 0x5a) c += 0x20
|
|
125
|
+
if (!allowed(c, rules)) throw BAD_CHARACTER()
|
|
126
|
+
out[i] = c
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (rules.isEmail) requireEmailShape(out)
|
|
130
|
+
else if (rules.allowHyphen) requireHyphenShape(out)
|
|
131
|
+
|
|
132
|
+
return new TextDecoder().decode(out)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/// One byte, after folding. Anything outside the platform's set is refused,
|
|
136
|
+
/// including every byte above 0x7f, so a multi-byte character never reaches a
|
|
137
|
+
/// key.
|
|
138
|
+
function allowed(c: number, rules: Rules): boolean {
|
|
139
|
+
if (c >= 0x61 && c <= 0x7a) return true // a-z
|
|
140
|
+
if (c >= 0x30 && c <= 0x39) return true // 0-9
|
|
141
|
+
if (rules.isEmail) {
|
|
142
|
+
// The set a Google address uses. The dot, the plus and the tag stay exactly
|
|
143
|
+
// as proved: this transform must never map two addresses onto one identity.
|
|
144
|
+
return c === 0x2e || c === 0x2b || c === 0x2d || c === 0x5f || c === 0x40
|
|
145
|
+
}
|
|
146
|
+
if (rules.allowUnderscore && c === 0x5f) return true
|
|
147
|
+
if (rules.allowHyphen && c === 0x2d) return true
|
|
148
|
+
return false
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/// Exactly one `@`, and not at either edge.
|
|
152
|
+
function requireEmailShape(value: Uint8Array): void {
|
|
153
|
+
let at = -1
|
|
154
|
+
for (let i = 0; i < value.length; i++) {
|
|
155
|
+
if (value[i] === 0x40) {
|
|
156
|
+
if (at !== -1) throw BAD_SHAPE() // a second one
|
|
157
|
+
at = i
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (at === -1) throw BAD_SHAPE() // none
|
|
161
|
+
if (at === 0 || at === value.length - 1) throw BAD_SHAPE() // an empty side
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/// A hyphen may not start or end the handle, and two may not touch.
|
|
165
|
+
function requireHyphenShape(value: Uint8Array): void {
|
|
166
|
+
if (value[0] === 0x2d || value[value.length - 1] === 0x2d) throw BAD_SHAPE()
|
|
167
|
+
for (let i = 1; i < value.length; i++) {
|
|
168
|
+
if (value[i] === 0x2d && value[i - 1] === 0x2d) throw BAD_SHAPE()
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
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_DOMAIN = 'dyaka.identity.platform.x'
|
|
17
|
+
/** keccak256 of this string is the platform id. */
|
|
18
|
+
export const PLATFORM_GITHUB_DOMAIN = 'dyaka.identity.platform.github'
|
|
19
|
+
/** keccak256 of this string is the platform id. */
|
|
20
|
+
export const PLATFORM_GOOGLE_DOMAIN = 'dyaka.identity.platform.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
|
+
/// 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
|
+
export const ERROR_EMPTY = 0
|
|
66
|
+
export const ERROR_TOOLONG = 1
|
|
67
|
+
export const ERROR_BADCHARACTER = 2
|
|
68
|
+
export const ERROR_BADSHAPE = 3
|
|
69
|
+
|
|
70
|
+
export const HANDLE_VECTORS: HandleVector[] = [
|
|
71
|
+
{ platform: "x", input: " @Alice_1 ", output: "alice_1", accepted: true, errorKind: 0 },
|
|
72
|
+
{ platform: "x", input: "alice", output: "alice", accepted: true, errorKind: 0 },
|
|
73
|
+
{ platform: "x", input: "@a", output: "a", accepted: true, errorKind: 0 },
|
|
74
|
+
{ platform: "x", input: "A1_b2", output: "a1_b2", accepted: true, errorKind: 0 },
|
|
75
|
+
{ platform: "x", input: "a12345678901234", output: "a12345678901234", accepted: true, errorKind: 0 },
|
|
76
|
+
{ platform: "x", input: "a123456789012345", output: "", accepted: false, errorKind: 1 },
|
|
77
|
+
{ platform: "x", input: "", output: "", accepted: false, errorKind: 0 },
|
|
78
|
+
{ platform: "x", input: " ", output: "", accepted: false, errorKind: 0 },
|
|
79
|
+
{ platform: "x", input: "@", output: "", accepted: false, errorKind: 0 },
|
|
80
|
+
{ platform: "x", input: "@@alice", output: "", accepted: false, errorKind: 2 },
|
|
81
|
+
{ platform: "x", input: "alice-1", output: "", accepted: false, errorKind: 2 },
|
|
82
|
+
{ platform: "x", input: "ali ce", output: "", accepted: false, errorKind: 2 },
|
|
83
|
+
{ platform: "x", input: "ali\tce", output: "", accepted: false, errorKind: 2 },
|
|
84
|
+
{ platform: "x", input: "ali\nce", output: "", accepted: false, errorKind: 2 },
|
|
85
|
+
{ platform: "x", input: "alic\u00e9", output: "", accepted: false, errorKind: 2 },
|
|
86
|
+
{ platform: "x", input: "\talice", output: "", accepted: false, errorKind: 2 },
|
|
87
|
+
{ platform: "x", input: "alice\t", output: "", accepted: false, errorKind: 2 },
|
|
88
|
+
{ platform: "x", input: "\nalice", output: "", accepted: false, errorKind: 2 },
|
|
89
|
+
{ platform: "x", input: " @ alice ", output: "", accepted: false, errorKind: 2 },
|
|
90
|
+
{ platform: "github", input: "@Octo-Cat", output: "octo-cat", accepted: true, errorKind: 0 },
|
|
91
|
+
{ platform: "github", input: "octocat", output: "octocat", accepted: true, errorKind: 0 },
|
|
92
|
+
{ platform: "github", input: " OctoCat ", output: "octocat", accepted: true, errorKind: 0 },
|
|
93
|
+
{ platform: "github", input: "a", output: "a", accepted: true, errorKind: 0 },
|
|
94
|
+
{ platform: "github", input: "o-c", output: "o-c", accepted: true, errorKind: 0 },
|
|
95
|
+
{ platform: "github", input: "-octocat", output: "", accepted: false, errorKind: 3 },
|
|
96
|
+
{ platform: "github", input: "octocat-", output: "", accepted: false, errorKind: 3 },
|
|
97
|
+
{ platform: "github", input: "octo--cat", output: "", accepted: false, errorKind: 3 },
|
|
98
|
+
{ platform: "github", input: "octo_cat", output: "", accepted: false, errorKind: 2 },
|
|
99
|
+
{ platform: "github", input: "-", output: "", accepted: false, errorKind: 3 },
|
|
100
|
+
{ platform: "github", input: "", output: "", accepted: false, errorKind: 0 },
|
|
101
|
+
{ platform: "github", input: "abcdefghijabcdefghijabcdefghijabcdefghi", output: "abcdefghijabcdefghijabcdefghijabcdefghi", accepted: true, errorKind: 0 },
|
|
102
|
+
{ platform: "github", input: "abcdefghijabcdefghijabcdefghijabcdefghij", output: "", accepted: false, errorKind: 1 },
|
|
103
|
+
{ platform: "github", input: "\n", output: "", accepted: false, errorKind: 2 },
|
|
104
|
+
{ platform: "google", input: "A.B+tag@Example.COM", output: "a.b+tag@example.com", accepted: true, errorKind: 0 },
|
|
105
|
+
{ platform: "google", input: "alice@example.com", output: "alice@example.com", accepted: true, errorKind: 0 },
|
|
106
|
+
{ platform: "google", input: " Alice@Example.com ", output: "alice@example.com", accepted: true, errorKind: 0 },
|
|
107
|
+
{ platform: "google", input: "@Alice@example.com", output: "", accepted: false, errorKind: 3 },
|
|
108
|
+
{ platform: "google", input: "alice", output: "", accepted: false, errorKind: 3 },
|
|
109
|
+
{ platform: "google", input: "@example.com", output: "", accepted: false, errorKind: 3 },
|
|
110
|
+
{ platform: "google", input: "alice@", output: "", accepted: false, errorKind: 3 },
|
|
111
|
+
{ platform: "google", input: "", output: "", accepted: false, errorKind: 0 },
|
|
112
|
+
{ platform: "google", input: "ali ce@example.com", output: "", accepted: false, errorKind: 2 },
|
|
113
|
+
{ platform: "google", input: "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij@example.com", output: "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij@example.com", accepted: true, errorKind: 0 },
|
|
114
|
+
{ platform: "google", input: "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijk@example.com", output: "", accepted: false, errorKind: 1 },
|
|
115
|
+
]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// The wallet-agnostic identity system, TypeScript half.
|
|
2
|
+
///
|
|
3
|
+
/// Handle normalization mirrors the on-chain normalizer byte for byte, the
|
|
4
|
+
/// bind encoders produce exactly what the verifiers decode, and the resolvers
|
|
5
|
+
/// wrap the `IdentityNames` view calls. Everything on-chain-shaped comes from
|
|
6
|
+
/// the generated ABIs in `../abis`, so this layer and the contracts cannot
|
|
7
|
+
/// drift apart silently.
|
|
8
|
+
|
|
9
|
+
export * from './bind.js'
|
|
10
|
+
export * from './handle.js'
|
|
11
|
+
export * from './handleVectors.js'
|
|
12
|
+
export * from './resolve.js'
|