@libid/contracts 0.22.0 → 0.23.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 +12 -5
- package/dist/abis/bindErrors.d.ts +80 -0
- package/dist/abis/bindErrors.d.ts.map +1 -1
- package/dist/abis/bindErrors.js +109 -1
- package/dist/abis/bindErrors.js.map +1 -1
- package/dist/abis/ceremonyPayloads.d.ts +3 -3
- package/dist/abis/ceremonyPayloads.js +3 -3
- package/dist/abis/ceremonyPayloads.js.map +1 -1
- package/dist/abis/googleJwtRoots.d.ts +11 -7
- package/dist/abis/googleJwtRoots.d.ts.map +1 -1
- package/dist/abis/googleJwtRoots.js +14 -8
- package/dist/abis/googleJwtRoots.js.map +1 -1
- package/dist/abis/identityRegistry.d.ts +50 -0
- package/dist/abis/identityRegistry.d.ts.map +1 -1
- package/dist/abis/identityRegistry.js +64 -0
- package/dist/abis/identityRegistry.js.map +1 -1
- package/dist/abis/index.d.ts +1 -0
- package/dist/abis/index.d.ts.map +1 -1
- package/dist/abis/index.js +1 -0
- package/dist/abis/index.js.map +1 -1
- package/dist/abis/referralSplitter.d.ts +380 -0
- package/dist/abis/referralSplitter.d.ts.map +1 -0
- package/dist/abis/referralSplitter.js +494 -0
- package/dist/abis/referralSplitter.js.map +1 -0
- package/dist/calls/identityRegistry.d.ts +1 -0
- package/dist/calls/identityRegistry.d.ts.map +1 -1
- package/dist/calls/identityRegistry.js +7 -0
- package/dist/calls/identityRegistry.js.map +1 -1
- package/dist/calls/index.d.ts +1 -0
- package/dist/calls/index.d.ts.map +1 -1
- package/dist/calls/index.js +1 -0
- package/dist/calls/index.js.map +1 -1
- package/dist/calls/referralSplitter.d.ts +14 -0
- package/dist/calls/referralSplitter.d.ts.map +1 -0
- package/dist/calls/referralSplitter.js +42 -0
- package/dist/calls/referralSplitter.js.map +1 -0
- package/dist/ceremony/profiles.d.ts +21 -0
- package/dist/ceremony/profiles.d.ts.map +1 -1
- package/dist/ceremony/profiles.js +31 -1
- package/dist/ceremony/profiles.js.map +1 -1
- package/dist/payloads.d.ts +12 -10
- package/dist/payloads.d.ts.map +1 -1
- package/dist/payloads.js +21 -16
- package/dist/payloads.js.map +1 -1
- package/dist/platforms/handle.d.ts +1 -0
- package/dist/platforms/handle.d.ts.map +1 -1
- package/dist/platforms/handle.js +2 -1
- package/dist/platforms/handle.js.map +1 -1
- package/dist/platforms/platforms.d.ts +3 -0
- package/dist/platforms/platforms.d.ts.map +1 -1
- package/dist/platforms/platforms.js +15 -1
- package/dist/platforms/platforms.js.map +1 -1
- package/package.json +1 -1
- package/src/abis/bindErrors.ts +109 -1
- package/src/abis/ceremonyPayloads.ts +3 -3
- package/src/abis/googleJwtRoots.ts +14 -8
- package/src/abis/identityRegistry.ts +64 -0
- package/src/abis/index.ts +1 -0
- package/src/abis/referralSplitter.ts +496 -0
- package/src/calls/identityRegistry.ts +12 -0
- package/src/calls/index.ts +1 -0
- package/src/calls/referralSplitter.ts +73 -0
- package/src/ceremony/profiles.ts +33 -1
- package/src/payloads.ts +31 -23
- package/src/platforms/handle.ts +9 -1
- package/src/platforms/platforms.ts +15 -1
package/src/ceremony/profiles.ts
CHANGED
|
@@ -135,8 +135,20 @@ export const GITHUB: Profile = {
|
|
|
135
135
|
},
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
/**
|
|
139
|
+
* Like Google, the evidence is a token signed with the platform's published
|
|
140
|
+
* keys, so the profile notarizes nothing. The audience is the bot id the
|
|
141
|
+
* payload names, and any bot is admitted (REQ-COMMON-17C).
|
|
142
|
+
*/
|
|
143
|
+
export const TELEGRAM: Profile = {
|
|
144
|
+
platform: 'telegram',
|
|
145
|
+
ceremonyVersion: 1,
|
|
146
|
+
token: null,
|
|
147
|
+
identity: null,
|
|
148
|
+
}
|
|
149
|
+
|
|
138
150
|
/** The launch profiles. */
|
|
139
|
-
export const LAUNCH: readonly Profile[] = [GOOGLE, X, GITHUB]
|
|
151
|
+
export const LAUNCH: readonly Profile[] = [GOOGLE, X, GITHUB, TELEGRAM]
|
|
140
152
|
|
|
141
153
|
/** The launch profile for a platform name, or undefined. */
|
|
142
154
|
export function launch(platform: string): Profile | undefined {
|
|
@@ -224,3 +236,23 @@ export const MAX_FUTURE_ATTESTATION_SKEW_SECONDS_GITHUB = 300
|
|
|
224
236
|
* time on one scale.
|
|
225
237
|
*/
|
|
226
238
|
export const FUTURE_OBSERVATION_ALLOWANCE_SECONDS_GITHUB = 300
|
|
239
|
+
|
|
240
|
+
// The circuit exposes the signed `iat`. A token is accepted while
|
|
241
|
+
// Block Time is in [iat - 5 min, iat + 1 h): five minutes for clock
|
|
242
|
+
// skew. The observation is `iat` less five minutes, so an `iat` inside
|
|
243
|
+
// the skew cannot outrank a later binding.
|
|
244
|
+
/**
|
|
245
|
+
* `telegram/v1`: maximum age of the signed `iat`.
|
|
246
|
+
*/
|
|
247
|
+
export const PROOF_LIFETIME_SECONDS_TELEGRAM = 3600
|
|
248
|
+
/**
|
|
249
|
+
* `telegram/v1`: how far ahead of Block Time the signed `iat` may be
|
|
250
|
+
* dated.
|
|
251
|
+
*/
|
|
252
|
+
export const MAX_FUTURE_ATTESTATION_SKEW_SECONDS_TELEGRAM = 300
|
|
253
|
+
/**
|
|
254
|
+
* `telegram/v1`: how far ahead of Block Time the evidence time may
|
|
255
|
+
* run. The verifier subtracts it, so every version of a platform
|
|
256
|
+
* reports time on one scale.
|
|
257
|
+
*/
|
|
258
|
+
export const FUTURE_OBSERVATION_ALLOWANCE_SECONDS_TELEGRAM = 300
|
package/src/payloads.ts
CHANGED
|
@@ -25,13 +25,14 @@ function inputs<N extends PayloadName>(name: N): Inputs<N> {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const TLS_NOTARY_PROOF = inputs('tlsNotaryProof')
|
|
28
|
-
const
|
|
28
|
+
const OIDC_PROOF = inputs('oidcProof')
|
|
29
29
|
|
|
30
30
|
/// `TlsNotaryVerifierBase.TlsNotaryProof`: the `x/v1` and `github/v1` payload.
|
|
31
31
|
export type TlsNotaryProof = AbiParameterToPrimitiveType<(typeof TLS_NOTARY_PROOF)[0]>
|
|
32
32
|
|
|
33
|
-
/// `
|
|
34
|
-
|
|
33
|
+
/// `OidcPlatformVerifierBase.OidcProof`: the `google/v1` and `telegram/v1`
|
|
34
|
+
/// payload. `time` is Google's `exp` or Telegram's `iat`.
|
|
35
|
+
export type OidcProof = AbiParameterToPrimitiveType<(typeof OIDC_PROOF)[0]>
|
|
35
36
|
|
|
36
37
|
/// The `x/v1` or `github/v1` payload, as the verifier decodes it.
|
|
37
38
|
export function encodeTlsNotaryProof(payload: TlsNotaryProof): Hex {
|
|
@@ -43,48 +44,55 @@ export function decodeTlsNotaryProof(data: Hex): TlsNotaryProof {
|
|
|
43
44
|
return decodeAbiParameters(TLS_NOTARY_PROOF, data)[0]
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
/// The `google/v1` payload, as the verifier decodes it.
|
|
47
|
-
export function
|
|
48
|
-
return encodeAbiParameters(
|
|
47
|
+
/// The `google/v1` or `telegram/v1` payload, as the verifier decodes it.
|
|
48
|
+
export function encodeOidcProof(payload: OidcProof): Hex {
|
|
49
|
+
return encodeAbiParameters(OIDC_PROOF, [payload])
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
///
|
|
52
|
-
export function
|
|
53
|
-
return decodeAbiParameters(
|
|
52
|
+
/// An OIDC payload back into its fields. Throws on bytes that are not one.
|
|
53
|
+
export function decodeOidcProof(data: Hex): OidcProof {
|
|
54
|
+
return decodeAbiParameters(OIDC_PROOF, data)[0]
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
/// The
|
|
57
|
-
export type
|
|
57
|
+
/// The OIDC payload fields a verifier builds its public inputs from.
|
|
58
|
+
export type OidcProofFields = Pick<OidcProof, 'idNode' | 'handleNode' | 'time' | 'modulus'>
|
|
58
59
|
|
|
59
|
-
/// The
|
|
60
|
+
/// The OIDC public input that disagrees with the payload: the verifier
|
|
60
61
|
/// would fail the proof, so a client checks before sending.
|
|
61
|
-
export class
|
|
62
|
+
export class OidcPublicInputMismatch extends Error {
|
|
62
63
|
constructor(readonly field: 'count' | 'digest' | 'audience') {
|
|
63
64
|
super(
|
|
64
65
|
`the proof's ${field} public input${field === 'count' ? 's do' : ' does'} not match the payload`,
|
|
65
66
|
)
|
|
66
|
-
this.name = '
|
|
67
|
+
this.name = 'OidcPublicInputMismatch'
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
///
|
|
71
|
+
/// Another name for `OidcPublicInputMismatch`: `instanceof` matches, and
|
|
72
|
+
/// the thrown error's `.name` is `'OidcPublicInputMismatch'`.
|
|
73
|
+
/// @deprecated Use `OidcPublicInputMismatch`; code that compares `.name`
|
|
74
|
+
/// to `'GooglePublicInputMismatch'` no longer matches.
|
|
75
|
+
export const GooglePublicInputMismatch = OidcPublicInputMismatch
|
|
76
|
+
/// @deprecated Use `OidcPublicInputMismatch`.
|
|
77
|
+
export type GooglePublicInputMismatch = OidcPublicInputMismatch
|
|
78
|
+
|
|
79
|
+
/// The payload fields from the prover's 57 OIDC public inputs
|
|
71
80
|
/// (REQ-PLAT-16B), after checking the digest the token's `nonce` carried and
|
|
72
81
|
/// the audience against what the verifier builds them from.
|
|
73
|
-
export function
|
|
82
|
+
export function oidcProofFields(
|
|
74
83
|
publicInputs: readonly Hex[],
|
|
75
84
|
expected: { digest: Hex; clientIdentifier: Hex },
|
|
76
|
-
):
|
|
77
|
-
if (publicInputs.length !== 57) throw new
|
|
85
|
+
): OidcProofFields {
|
|
86
|
+
if (publicInputs.length !== 57) throw new OidcPublicInputMismatch('count')
|
|
78
87
|
const field = (i: number) => hexToBigInt(publicInputs[i] as Hex)
|
|
79
88
|
const node = (i: number) => numberToHex((field(i) << 128n) | field(i + 1), { size: 32 })
|
|
80
89
|
const digest = hexToBytes(expected.digest)
|
|
81
|
-
if (digest.some((b, i) => field(i) !== BigInt(b))) throw new
|
|
82
|
-
if (node(32) !== sha256(expected.clientIdentifier))
|
|
83
|
-
throw new GooglePublicInputMismatch('audience')
|
|
90
|
+
if (digest.some((b, i) => field(i) !== BigInt(b))) throw new OidcPublicInputMismatch('digest')
|
|
91
|
+
if (node(32) !== sha256(expected.clientIdentifier)) throw new OidcPublicInputMismatch('audience')
|
|
84
92
|
return {
|
|
85
93
|
idNode: node(34),
|
|
86
94
|
handleNode: node(36),
|
|
87
|
-
|
|
88
|
-
modulus: publicInputs.slice(39, 57) as unknown as
|
|
95
|
+
time: field(38),
|
|
96
|
+
modulus: publicInputs.slice(39, 57) as unknown as OidcProof['modulus'],
|
|
89
97
|
}
|
|
90
98
|
}
|
package/src/platforms/handle.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
/// Turns a typed handle into the form the identity circuits hash into a node.
|
|
2
2
|
/// Mirrors the circuits and Rust; all run the `handles.json` vectors.
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
HandleError,
|
|
6
|
+
PLATFORM_GITHUB,
|
|
7
|
+
PLATFORM_GOOGLE,
|
|
8
|
+
PLATFORM_TELEGRAM,
|
|
9
|
+
PLATFORM_X,
|
|
10
|
+
platform,
|
|
11
|
+
} from './platforms.js'
|
|
5
12
|
|
|
6
13
|
/// What one platform's circuit takes, generated from the circuits' `platforms.json`.
|
|
7
14
|
export interface Rules {
|
|
@@ -12,6 +19,7 @@ export interface Rules {
|
|
|
12
19
|
export const RULES_X: Rules = PLATFORM_X.rules
|
|
13
20
|
export const RULES_GITHUB: Rules = PLATFORM_GITHUB.rules
|
|
14
21
|
export const RULES_GOOGLE: Rules = PLATFORM_GOOGLE.rules
|
|
22
|
+
export const RULES_TELEGRAM: Rules = PLATFORM_TELEGRAM.rules
|
|
15
23
|
|
|
16
24
|
/// The rules for a platform key from the generated table.
|
|
17
25
|
export function rulesFor(platformKey: string): Rules | null {
|
|
@@ -26,6 +26,8 @@ export const PLATFORM_GOOGLE_KEY = 'google'
|
|
|
26
26
|
export const PLATFORM_X_KEY = 'x'
|
|
27
27
|
/** keccak256 of this string is the platform id. */
|
|
28
28
|
export const PLATFORM_GITHUB_KEY = 'github'
|
|
29
|
+
/** keccak256 of this string is the platform id. */
|
|
30
|
+
export const PLATFORM_TELEGRAM_KEY = 'telegram'
|
|
29
31
|
|
|
30
32
|
export const PLATFORM_GOOGLE: Platform = {
|
|
31
33
|
key: PLATFORM_GOOGLE_KEY,
|
|
@@ -63,9 +65,21 @@ export const PLATFORM_GITHUB: Platform = {
|
|
|
63
65
|
decimal: true,
|
|
64
66
|
},
|
|
65
67
|
}
|
|
68
|
+
export const PLATFORM_TELEGRAM: Platform = {
|
|
69
|
+
key: PLATFORM_TELEGRAM_KEY,
|
|
70
|
+
userIdTag: 'libid.telegram.user-id',
|
|
71
|
+
handleTag: 'libid.telegram.handle',
|
|
72
|
+
rules: {
|
|
73
|
+
maxLength: 32,
|
|
74
|
+
},
|
|
75
|
+
idRules: {
|
|
76
|
+
maxLength: 20,
|
|
77
|
+
decimal: true,
|
|
78
|
+
},
|
|
79
|
+
}
|
|
66
80
|
|
|
67
81
|
/** Every platform, in table order. */
|
|
68
|
-
export const PLATFORMS: readonly Platform[] = [PLATFORM_GOOGLE, PLATFORM_X, PLATFORM_GITHUB]
|
|
82
|
+
export const PLATFORMS: readonly Platform[] = [PLATFORM_GOOGLE, PLATFORM_X, PLATFORM_GITHUB, PLATFORM_TELEGRAM]
|
|
69
83
|
|
|
70
84
|
/** The platform with this key, if the table names it. */
|
|
71
85
|
export function platform(key: string): Platform | undefined {
|