@libid/contracts 0.18.0 → 0.19.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.
Files changed (49) hide show
  1. package/README.md +27 -16
  2. package/dist/abis/bindErrors.d.ts +4 -0
  3. package/dist/abis/bindErrors.d.ts.map +1 -1
  4. package/dist/abis/bindErrors.js +5 -0
  5. package/dist/abis/bindErrors.js.map +1 -1
  6. package/dist/abis/ceremonyProofVerifier.d.ts +0 -10
  7. package/dist/abis/ceremonyProofVerifier.d.ts.map +1 -1
  8. package/dist/abis/ceremonyProofVerifier.js +0 -13
  9. package/dist/abis/ceremonyProofVerifier.js.map +1 -1
  10. package/dist/abis/handleEscrow.d.ts +20 -20
  11. package/dist/abis/handleEscrow.js +25 -25
  12. package/dist/abis/handleEscrow.js.map +1 -1
  13. package/dist/abis/identityRegistry.d.ts +77 -33
  14. package/dist/abis/identityRegistry.d.ts.map +1 -1
  15. package/dist/abis/identityRegistry.js +97 -42
  16. package/dist/abis/identityRegistry.js.map +1 -1
  17. package/dist/calls/identityRegistry.d.ts +1 -0
  18. package/dist/calls/identityRegistry.d.ts.map +1 -1
  19. package/dist/calls/identityRegistry.js +6 -0
  20. package/dist/calls/identityRegistry.js.map +1 -1
  21. package/dist/identity/index.d.ts +0 -1
  22. package/dist/identity/index.d.ts.map +1 -1
  23. package/dist/identity/index.js +0 -1
  24. package/dist/identity/index.js.map +1 -1
  25. package/dist/identity/resolve.d.ts +5 -1
  26. package/dist/identity/resolve.d.ts.map +1 -1
  27. package/dist/identity/resolve.js +6 -7
  28. package/dist/identity/resolve.js.map +1 -1
  29. package/dist/platforms/index.d.ts +1 -0
  30. package/dist/platforms/index.d.ts.map +1 -1
  31. package/dist/platforms/index.js +4 -3
  32. package/dist/platforms/index.js.map +1 -1
  33. package/dist/{identity → platforms}/node.d.ts +3 -4
  34. package/dist/platforms/node.d.ts.map +1 -0
  35. package/dist/{identity → platforms}/node.js +14 -6
  36. package/dist/platforms/node.js.map +1 -0
  37. package/package.json +4 -1
  38. package/src/abis/bindErrors.ts +5 -0
  39. package/src/abis/ceremonyProofVerifier.ts +0 -13
  40. package/src/abis/handleEscrow.ts +25 -25
  41. package/src/abis/identityRegistry.ts +97 -42
  42. package/src/calls/identityRegistry.ts +7 -0
  43. package/src/identity/index.ts +0 -1
  44. package/src/identity/resolve.ts +18 -9
  45. package/src/platforms/index.ts +4 -3
  46. package/src/platforms/node.ts +41 -0
  47. package/dist/identity/node.d.ts.map +0 -1
  48. package/dist/identity/node.js.map +0 -1
  49. package/src/identity/node.ts +0 -32
@@ -407,31 +407,6 @@ export const handleEscrowAbi = [
407
407
  ],
408
408
  "anonymous": false
409
409
  },
410
- {
411
- "type": "event",
412
- "name": "DepositedToHandle",
413
- "inputs": [
414
- {
415
- "name": "handleNode",
416
- "type": "bytes32",
417
- "indexed": true,
418
- "internalType": "bytes32"
419
- },
420
- {
421
- "name": "platformId",
422
- "type": "bytes32",
423
- "indexed": true,
424
- "internalType": "bytes32"
425
- },
426
- {
427
- "name": "handle",
428
- "type": "string",
429
- "indexed": false,
430
- "internalType": "string"
431
- }
432
- ],
433
- "anonymous": false
434
- },
435
410
  {
436
411
  "type": "event",
437
412
  "name": "Forwarded",
@@ -475,6 +450,31 @@ export const handleEscrowAbi = [
475
450
  ],
476
451
  "anonymous": false
477
452
  },
453
+ {
454
+ "type": "event",
455
+ "name": "HandleRevealed",
456
+ "inputs": [
457
+ {
458
+ "name": "platformId",
459
+ "type": "bytes32",
460
+ "indexed": true,
461
+ "internalType": "bytes32"
462
+ },
463
+ {
464
+ "name": "handleNode",
465
+ "type": "bytes32",
466
+ "indexed": true,
467
+ "internalType": "bytes32"
468
+ },
469
+ {
470
+ "name": "handle",
471
+ "type": "string",
472
+ "indexed": false,
473
+ "internalType": "string"
474
+ }
475
+ ],
476
+ "anonymous": false
477
+ },
478
478
  {
479
479
  "type": "event",
480
480
  "name": "Initialized",
@@ -84,6 +84,21 @@ export const identityRegistryAbi = [
84
84
  "name": "handle",
85
85
  "type": "string",
86
86
  "internalType": "string"
87
+ },
88
+ {
89
+ "name": "primary",
90
+ "type": "bool",
91
+ "internalType": "bool"
92
+ },
93
+ {
94
+ "name": "feeAmount",
95
+ "type": "uint256",
96
+ "internalType": "uint256"
97
+ },
98
+ {
99
+ "name": "feeReceiver",
100
+ "type": "address",
101
+ "internalType": "address"
87
102
  }
88
103
  ],
89
104
  "outputs": [],
@@ -107,6 +122,16 @@ export const identityRegistryAbi = [
107
122
  "name": "payload",
108
123
  "type": "bytes",
109
124
  "internalType": "bytes"
125
+ },
126
+ {
127
+ "name": "feeAmount",
128
+ "type": "uint256",
129
+ "internalType": "uint256"
130
+ },
131
+ {
132
+ "name": "feeReceiver",
133
+ "type": "address",
134
+ "internalType": "address"
110
135
  }
111
136
  ],
112
137
  "outputs": [],
@@ -325,6 +350,30 @@ export const identityRegistryAbi = [
325
350
  ],
326
351
  "stateMutability": "view"
327
352
  },
353
+ {
354
+ "type": "function",
355
+ "name": "primaryHandleOf",
356
+ "inputs": [
357
+ {
358
+ "name": "holder",
359
+ "type": "address",
360
+ "internalType": "address"
361
+ }
362
+ ],
363
+ "outputs": [
364
+ {
365
+ "name": "platformId",
366
+ "type": "bytes32",
367
+ "internalType": "bytes32"
368
+ },
369
+ {
370
+ "name": "handle",
371
+ "type": "string",
372
+ "internalType": "string"
373
+ }
374
+ ],
375
+ "stateMutability": "view"
376
+ },
328
377
  {
329
378
  "type": "function",
330
379
  "name": "proofVerifier",
@@ -369,30 +418,6 @@ export const identityRegistryAbi = [
369
418
  "outputs": [],
370
419
  "stateMutability": "nonpayable"
371
420
  },
372
- {
373
- "type": "function",
374
- "name": "publishedHandleOf",
375
- "inputs": [
376
- {
377
- "name": "holder",
378
- "type": "address",
379
- "internalType": "address"
380
- },
381
- {
382
- "name": "platformId",
383
- "type": "bytes32",
384
- "internalType": "bytes32"
385
- }
386
- ],
387
- "outputs": [
388
- {
389
- "name": "",
390
- "type": "string",
391
- "internalType": "string"
392
- }
393
- ],
394
- "stateMutability": "view"
395
- },
396
421
  {
397
422
  "type": "function",
398
423
  "name": "quoteBind",
@@ -535,6 +560,24 @@ export const identityRegistryAbi = [
535
560
  ],
536
561
  "stateMutability": "view"
537
562
  },
563
+ {
564
+ "type": "function",
565
+ "name": "reveal",
566
+ "inputs": [
567
+ {
568
+ "name": "platformId",
569
+ "type": "bytes32",
570
+ "internalType": "bytes32"
571
+ },
572
+ {
573
+ "name": "handle",
574
+ "type": "string",
575
+ "internalType": "string"
576
+ }
577
+ ],
578
+ "outputs": [],
579
+ "stateMutability": "nonpayable"
580
+ },
538
581
  {
539
582
  "type": "function",
540
583
  "name": "setProofVerifier",
@@ -564,13 +607,7 @@ export const identityRegistryAbi = [
564
607
  {
565
608
  "type": "function",
566
609
  "name": "unpublish",
567
- "inputs": [
568
- {
569
- "name": "platformId",
570
- "type": "bytes32",
571
- "internalType": "bytes32"
572
- }
573
- ],
610
+ "inputs": [],
574
611
  "outputs": [],
575
612
  "stateMutability": "nonpayable"
576
613
  },
@@ -669,12 +706,6 @@ export const identityRegistryAbi = [
669
706
  "type": "bytes32",
670
707
  "indexed": true,
671
708
  "internalType": "bytes32"
672
- },
673
- {
674
- "name": "handle",
675
- "type": "string",
676
- "indexed": false,
677
- "internalType": "string"
678
709
  }
679
710
  ],
680
711
  "anonymous": false
@@ -706,19 +737,38 @@ export const identityRegistryAbi = [
706
737
  },
707
738
  {
708
739
  "type": "event",
709
- "name": "HandleUnpublished",
740
+ "name": "HandleRevealed",
710
741
  "inputs": [
711
742
  {
712
- "name": "holder",
713
- "type": "address",
743
+ "name": "platformId",
744
+ "type": "bytes32",
714
745
  "indexed": true,
715
- "internalType": "address"
746
+ "internalType": "bytes32"
716
747
  },
717
748
  {
718
- "name": "platformId",
749
+ "name": "handleNode",
719
750
  "type": "bytes32",
720
751
  "indexed": true,
721
752
  "internalType": "bytes32"
753
+ },
754
+ {
755
+ "name": "handle",
756
+ "type": "string",
757
+ "indexed": false,
758
+ "internalType": "string"
759
+ }
760
+ ],
761
+ "anonymous": false
762
+ },
763
+ {
764
+ "type": "event",
765
+ "name": "HandleUnpublished",
766
+ "inputs": [
767
+ {
768
+ "name": "holder",
769
+ "type": "address",
770
+ "indexed": true,
771
+ "internalType": "address"
722
772
  }
723
773
  ],
724
774
  "anonymous": false
@@ -1030,6 +1080,11 @@ export const identityRegistryAbi = [
1030
1080
  }
1031
1081
  ]
1032
1082
  },
1083
+ {
1084
+ "type": "error",
1085
+ "name": "PrimaryWithoutHandle",
1086
+ "inputs": []
1087
+ },
1033
1088
  {
1034
1089
  "type": "error",
1035
1090
  "name": "ReentrancyGuardReentrantCall",
@@ -63,6 +63,13 @@ export function publish(to: Address, ...args: IdentityRegistryArgs<'publish'>):
63
63
  }
64
64
  }
65
65
 
66
+ export function reveal(to: Address, ...args: IdentityRegistryArgs<'reveal'>): Call {
67
+ return {
68
+ to,
69
+ data: encodeFunctionData({ abi: identityRegistryAbi, functionName: 'reveal', args }),
70
+ }
71
+ }
72
+
66
73
  export function setProofVerifier(
67
74
  to: Address,
68
75
  ...args: IdentityRegistryArgs<'setProofVerifier'>
@@ -5,5 +5,4 @@
5
5
  /// the chain only folds A-Z. Calldata for the writes is in `../calls`.
6
6
 
7
7
  export * from '../platforms/index.js'
8
- export * from './node.js'
9
8
  export * from './resolve.js'
@@ -6,8 +6,7 @@
6
6
  import { type Address, keccak256, type PublicClient, toHex, zeroAddress, zeroHash } from 'viem'
7
7
 
8
8
  import { identityRegistryAbi } from '../abis/identityRegistry.js'
9
- import { HandleError, PLATFORMS } from '../platforms/index.js'
10
- import { handleNode } from './node.js'
9
+ import { HandleError, handleNode, PLATFORMS } from '../platforms/index.js'
11
10
 
12
11
  /// A platform key (`'x'`, `'github'`, ...). A value typed as hex fails to
13
12
  /// compile: an id passed as a key would hash into a platform nothing binds.
@@ -107,15 +106,25 @@ export async function resolveHandle(
107
106
  return (await resolveHandleAndId(reader, platformId, handle, zeroHash)).holder
108
107
  }
109
108
 
110
- /// The handle to show for a holder, or `null`. Forward-checked on chain:
111
- /// empty once the stored handle resolves somewhere else.
112
- export async function publishedHandleOf(
109
+ /// The one handle a holder shows as its name, and the platform it is on.
110
+ export interface PrimaryHandle {
111
+ platformId: `0x${string}`
112
+ /// Folded, as the holder disclosed it.
113
+ handle: string
114
+ }
115
+
116
+ /// The handle to show for a holder, on whichever platform, or `null`.
117
+ /// Forward-checked on chain: none once the stored handle resolves somewhere else.
118
+ export async function primaryHandleOf(
113
119
  reader: RegistryReader,
114
120
  holder: Address,
115
- platformId: `0x${string}`,
116
- ): Promise<string | null> {
117
- const handle = await read<string>(reader, 'publishedHandleOf', [holder, platformId])
118
- return handle.length === 0 ? null : handle
121
+ ): Promise<PrimaryHandle | null> {
122
+ const [platformId, handle] = await read<readonly [`0x${string}`, string]>(
123
+ reader,
124
+ 'primaryHandleOf',
125
+ [holder],
126
+ )
127
+ return handle.length === 0 ? null : { platformId, handle }
119
128
  }
120
129
 
121
130
  /// One identity a holder proved, as the holder's list reports it.
@@ -1,7 +1,8 @@
1
- /// The platform table and the checks the identity circuits apply to handles
2
- /// and ids: normalization, the id check and the refusals they throw. Loads
3
- /// without viem; node hashing and the registry reads are in `../identity`.
1
+ /// The platform table, the checks the identity circuits apply to handles and
2
+ /// ids (normalization, the id check and the refusals they throw) and the node
3
+ /// derivation. Loads without viem; the registry reads are in `../identity`.
4
4
 
5
5
  export * from './handle.js'
6
6
  export * from './id.js'
7
+ export * from './node.js'
7
8
  export * from './platforms.js'
@@ -0,0 +1,41 @@
1
+ /// The keys a binding is stored under, `SHA256(tag || value)`, computed
2
+ /// locally so the handle or id never reaches an RPC.
3
+
4
+ import { sha256 } from '@noble/hashes/sha2.js'
5
+ import { bytesToHex, concatBytes, utf8ToBytes } from '@noble/hashes/utils.js'
6
+
7
+ import { normalize } from './handle.js'
8
+ import { checkId } from './id.js'
9
+ import { type Platform, platform } from './platforms.js'
10
+
11
+ function keysOf(platformKey: string): Platform {
12
+ const keys = platform(platformKey)
13
+ if (keys === undefined) throw new Error(`unknown platform ${JSON.stringify(platformKey)}`)
14
+ return keys
15
+ }
16
+
17
+ /// `SHA256(tag || value)` as lowercase `0x` hex.
18
+ function nodeOf(tag: string, value: Uint8Array): `0x${string}` {
19
+ return `0x${bytesToHex(sha256(concatBytes(utf8ToBytes(tag), value)))}`
20
+ }
21
+
22
+ /// The node a typed handle is bound under: normalized, then hashed under
23
+ /// its handle tag. Throws `HandleError` for text no binding can have.
24
+ export function handleNode(platformKey: string, raw: string): `0x${string}` {
25
+ const keys = keysOf(platformKey)
26
+ return nodeOf(keys.handleTag, utf8ToBytes(normalize(raw, keys.rules)))
27
+ }
28
+
29
+ /// The node `depositToHandle` and the registry's `handleNodeOf` derive from
30
+ /// `text`: A-Z folded, nothing checked, so text no circuit hashes has one too.
31
+ export function foldedHandleNode(platformKey: string, text: string): `0x${string}` {
32
+ const bytes = utf8ToBytes(text).map((b) => (b >= 0x41 && b <= 0x5a ? b + 0x20 : b))
33
+ return nodeOf(keysOf(platformKey).handleTag, bytes)
34
+ }
35
+
36
+ /// The node an id is bound under: the id as given, under its user-id tag.
37
+ /// Throws `IdError` for an id no circuit hashes.
38
+ export function idNode(platformKey: string, id: string): `0x${string}` {
39
+ checkId(platformKey, id)
40
+ return nodeOf(keysOf(platformKey).userIdTag, utf8ToBytes(id))
41
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/identity/node.ts"],"names":[],"mappings":"AAGA,OAAO,EAAU,KAAK,GAAG,EAAiB,MAAM,MAAM,CAAA;AAYtD,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,GAAG,CAGhE;AAID,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,GAAG,CAGvE;AAGD,wBAAgB,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,EAAE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AAC,MAAM,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AAC7E,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,MAAM,CAAC,WAAmB,EAAE,EAAU;IACpD,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;IACxB,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;AAC1E,CAAC"}
@@ -1,32 +0,0 @@
1
- /// The keys a binding is stored under, `SHA256(tag || value)`, computed
2
- /// locally so the handle or id never reaches an RPC.
3
-
4
- import { concat, type Hex, sha256, toHex } from 'viem'
5
-
6
- import { checkId, normalize, type Platform, platform } from '../platforms/index.js'
7
-
8
- function keysOf(platformKey: string): Platform {
9
- const keys = platform(platformKey)
10
- if (keys === undefined) throw new Error(`unknown platform ${JSON.stringify(platformKey)}`)
11
- return keys
12
- }
13
-
14
- /// The node a typed handle is bound under: normalized, then hashed under
15
- /// its handle tag. Throws `HandleError` for text no binding can have.
16
- export function handleNode(platformKey: string, raw: string): Hex {
17
- const keys = keysOf(platformKey)
18
- return sha256(concat([toHex(keys.handleTag), toHex(normalize(raw, keys.rules))]))
19
- }
20
-
21
- /// The node `depositToHandle` and the registry's `handleNodeOf` derive from
22
- /// `text`: A-Z folded, nothing checked, so text no circuit hashes has one too.
23
- export function foldedHandleNode(platformKey: string, text: string): Hex {
24
- const bytes = new TextEncoder().encode(text).map((b) => (b >= 0x41 && b <= 0x5a ? b + 0x20 : b))
25
- return sha256(concat([toHex(keysOf(platformKey).handleTag), toHex(bytes)]))
26
- }
27
-
28
- /// The node an id is bound under: the id as given, under its user-id tag.
29
- export function idNode(platformKey: string, id: string): Hex {
30
- checkId(platformKey, id)
31
- return sha256(concat([toHex(keysOf(platformKey).userIdTag), toHex(id)]))
32
- }