@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.
Files changed (132) hide show
  1. package/README.md +96 -0
  2. package/dist/abis/adminFacet.d.ts +339 -0
  3. package/dist/abis/adminFacet.d.ts.map +1 -0
  4. package/dist/abis/adminFacet.js +442 -0
  5. package/dist/abis/adminFacet.js.map +1 -0
  6. package/dist/abis/bank.d.ts +916 -0
  7. package/dist/abis/bank.d.ts.map +1 -0
  8. package/dist/abis/bank.js +1184 -0
  9. package/dist/abis/bank.js.map +1 -0
  10. package/dist/abis/diamondLoupeFacet.d.ts +73 -0
  11. package/dist/abis/diamondLoupeFacet.d.ts.map +1 -0
  12. package/dist/abis/diamondLoupeFacet.js +100 -0
  13. package/dist/abis/diamondLoupeFacet.js.map +1 -0
  14. package/dist/abis/gitHubIdentityVerifier.d.ts +451 -0
  15. package/dist/abis/gitHubIdentityVerifier.d.ts.map +1 -0
  16. package/dist/abis/gitHubIdentityVerifier.js +586 -0
  17. package/dist/abis/gitHubIdentityVerifier.js.map +1 -0
  18. package/dist/abis/googleIdentityVerifier.d.ts +373 -0
  19. package/dist/abis/googleIdentityVerifier.d.ts.map +1 -0
  20. package/dist/abis/googleIdentityVerifier.js +485 -0
  21. package/dist/abis/googleIdentityVerifier.js.map +1 -0
  22. package/dist/abis/googleOidcVerifier.d.ts +743 -0
  23. package/dist/abis/googleOidcVerifier.d.ts.map +1 -0
  24. package/dist/abis/googleOidcVerifier.js +962 -0
  25. package/dist/abis/googleOidcVerifier.js.map +1 -0
  26. package/dist/abis/identityJwksRoots.d.ts +515 -0
  27. package/dist/abis/identityJwksRoots.d.ts.map +1 -0
  28. package/dist/abis/identityJwksRoots.js +669 -0
  29. package/dist/abis/identityJwksRoots.js.map +1 -0
  30. package/dist/abis/identityNames.d.ts +614 -0
  31. package/dist/abis/identityNames.d.ts.map +1 -0
  32. package/dist/abis/identityNames.js +798 -0
  33. package/dist/abis/identityNames.js.map +1 -0
  34. package/dist/abis/index.d.ts +19 -0
  35. package/dist/abis/index.d.ts.map +1 -0
  36. package/dist/abis/index.js +21 -0
  37. package/dist/abis/index.js.map +1 -0
  38. package/dist/abis/mockErc20.d.ts +262 -0
  39. package/dist/abis/mockErc20.d.ts.map +1 -0
  40. package/dist/abis/mockErc20.js +347 -0
  41. package/dist/abis/mockErc20.js.map +1 -0
  42. package/dist/abis/notaryRegistry.d.ts +272 -0
  43. package/dist/abis/notaryRegistry.d.ts.map +1 -0
  44. package/dist/abis/notaryRegistry.js +355 -0
  45. package/dist/abis/notaryRegistry.js.map +1 -0
  46. package/dist/abis/registry.d.ts +1166 -0
  47. package/dist/abis/registry.d.ts.map +1 -0
  48. package/dist/abis/registry.js +1506 -0
  49. package/dist/abis/registry.js.map +1 -0
  50. package/dist/abis/transferFacet.d.ts +814 -0
  51. package/dist/abis/transferFacet.d.ts.map +1 -0
  52. package/dist/abis/transferFacet.js +1035 -0
  53. package/dist/abis/transferFacet.js.map +1 -0
  54. package/dist/abis/vaultFacet.d.ts +306 -0
  55. package/dist/abis/vaultFacet.d.ts.map +1 -0
  56. package/dist/abis/vaultFacet.js +398 -0
  57. package/dist/abis/vaultFacet.js.map +1 -0
  58. package/dist/abis/walletFactory.d.ts +325 -0
  59. package/dist/abis/walletFactory.d.ts.map +1 -0
  60. package/dist/abis/walletFactory.js +424 -0
  61. package/dist/abis/walletFactory.js.map +1 -0
  62. package/dist/abis/webWallet.d.ts +523 -0
  63. package/dist/abis/webWallet.d.ts.map +1 -0
  64. package/dist/abis/webWallet.js +680 -0
  65. package/dist/abis/webWallet.js.map +1 -0
  66. package/dist/abis/wtia9.d.ts +233 -0
  67. package/dist/abis/wtia9.d.ts.map +1 -0
  68. package/dist/abis/wtia9.js +304 -0
  69. package/dist/abis/wtia9.js.map +1 -0
  70. package/dist/abis/xIdentityVerifier.d.ts +487 -0
  71. package/dist/abis/xIdentityVerifier.d.ts.map +1 -0
  72. package/dist/abis/xIdentityVerifier.js +631 -0
  73. package/dist/abis/xIdentityVerifier.js.map +1 -0
  74. package/dist/abis/xZkVerifier.d.ts +586 -0
  75. package/dist/abis/xZkVerifier.d.ts.map +1 -0
  76. package/dist/abis/xZkVerifier.js +760 -0
  77. package/dist/abis/xZkVerifier.js.map +1 -0
  78. package/dist/identity/bind.d.ts +60 -0
  79. package/dist/identity/bind.d.ts.map +1 -0
  80. package/dist/identity/bind.fixtures.d.ts +8 -0
  81. package/dist/identity/bind.fixtures.d.ts.map +1 -0
  82. package/dist/identity/bind.fixtures.js +57 -0
  83. package/dist/identity/bind.fixtures.js.map +1 -0
  84. package/dist/identity/bind.js +119 -0
  85. package/dist/identity/bind.js.map +1 -0
  86. package/dist/identity/handle.d.ts +22 -0
  87. package/dist/identity/handle.d.ts.map +1 -0
  88. package/dist/identity/handle.js +137 -0
  89. package/dist/identity/handle.js.map +1 -0
  90. package/dist/identity/handleVectors.d.ts +53 -0
  91. package/dist/identity/handleVectors.d.ts.map +1 -0
  92. package/dist/identity/handleVectors.js +99 -0
  93. package/dist/identity/handleVectors.js.map +1 -0
  94. package/dist/identity/index.d.ts +5 -0
  95. package/dist/identity/index.d.ts.map +1 -0
  96. package/dist/identity/index.js +12 -0
  97. package/dist/identity/index.js.map +1 -0
  98. package/dist/identity/resolve.d.ts +16 -0
  99. package/dist/identity/resolve.d.ts.map +1 -0
  100. package/dist/identity/resolve.js +90 -0
  101. package/dist/identity/resolve.js.map +1 -0
  102. package/dist/index.d.ts +3 -0
  103. package/dist/index.d.ts.map +1 -0
  104. package/dist/index.js +6 -0
  105. package/dist/index.js.map +1 -0
  106. package/package.json +53 -0
  107. package/src/abis/adminFacet.ts +444 -0
  108. package/src/abis/bank.ts +1186 -0
  109. package/src/abis/diamondLoupeFacet.ts +102 -0
  110. package/src/abis/gitHubIdentityVerifier.ts +588 -0
  111. package/src/abis/googleIdentityVerifier.ts +487 -0
  112. package/src/abis/googleOidcVerifier.ts +964 -0
  113. package/src/abis/identityJwksRoots.ts +671 -0
  114. package/src/abis/identityNames.ts +800 -0
  115. package/src/abis/index.ts +20 -0
  116. package/src/abis/mockErc20.ts +349 -0
  117. package/src/abis/notaryRegistry.ts +357 -0
  118. package/src/abis/registry.ts +1508 -0
  119. package/src/abis/transferFacet.ts +1037 -0
  120. package/src/abis/vaultFacet.ts +400 -0
  121. package/src/abis/walletFactory.ts +426 -0
  122. package/src/abis/webWallet.ts +682 -0
  123. package/src/abis/wtia9.ts +306 -0
  124. package/src/abis/xIdentityVerifier.ts +633 -0
  125. package/src/abis/xZkVerifier.ts +762 -0
  126. package/src/identity/bind.fixtures.ts +65 -0
  127. package/src/identity/bind.ts +209 -0
  128. package/src/identity/handle.ts +170 -0
  129. package/src/identity/handleVectors.ts +115 -0
  130. package/src/identity/index.ts +12 -0
  131. package/src/identity/resolve.ts +141 -0
  132. package/src/index.ts +6 -0
@@ -0,0 +1,141 @@
1
+ /// Reading names from the chain.
2
+ ///
3
+ /// Everything here is a view call. Binding a name needs a proof and a wallet;
4
+ /// reading one needs neither, which is the point — any product can resolve a
5
+ /// name without touching the login that created it.
6
+ ///
7
+ /// The client and the contract address are arguments rather than imports. This
8
+ /// package ships separately from the repository it currently lives in, so it
9
+ /// carries no configuration of its own and reaches for nothing outside itself.
10
+
11
+ import { type Address, keccak256, type PublicClient, toHex, zeroAddress } from 'viem'
12
+
13
+ import { identityNamesAbi } from '../abis/identityNames.js'
14
+
15
+ /// A platform id is `keccak256` of its domain string. The domains are generated
16
+ /// from `handles.json`, so this and the contract agree by construction.
17
+ export function platformId(domain: string): `0x${string}` {
18
+ return keccak256(toHex(domain))
19
+ }
20
+
21
+ export interface NamesReader {
22
+ client: PublicClient
23
+ /// The deployed `IdentityNames` contract.
24
+ address: Address
25
+ }
26
+
27
+ /// One view call.
28
+ ///
29
+ /// Routed through a narrow cast for the same reason the wallet package does it:
30
+ /// viem's `PublicClient`, without its chain type parameters, types
31
+ /// `authorizationList` as required even for a read. The alternative is to
32
+ /// spread that noise across every call site here.
33
+ function read<T>(reader: NamesReader, functionName: string, args: readonly unknown[]): Promise<T> {
34
+ return (
35
+ reader.client as unknown as {
36
+ readContract: (request: Record<string, unknown>) => Promise<T>
37
+ }
38
+ ).readContract({
39
+ authorizationList: undefined,
40
+ address: reader.address,
41
+ abi: identityNamesAbi,
42
+ functionName,
43
+ args,
44
+ })
45
+ }
46
+
47
+ /// The wallet that proved this account id, or `null`.
48
+ export async function resolveId(
49
+ reader: NamesReader,
50
+ platform: `0x${string}`,
51
+ userId: string,
52
+ ): Promise<Address | null> {
53
+ const owner = await read<Address>(reader, 'resolveId', [platform, userId])
54
+ return owner === zeroAddress ? null : owner
55
+ }
56
+
57
+ /// The wallet that last proved this handle, or `null`.
58
+ ///
59
+ /// The handle is normalized on chain before it is looked up, so a caller may
60
+ /// pass what a user typed — including something that is not a handle at all.
61
+ /// The contract is total in the handle: a string no platform could hold answers
62
+ /// the zero address, which is the same answer as a handle nobody has proved,
63
+ /// and the one a search box wants.
64
+ ///
65
+ /// A revert propagates. `UnknownPlatform` in particular means the platform is
66
+ /// not configured, and answering "unowned" would bury a deployment mistake
67
+ /// under a plausible result.
68
+ export async function resolveHandle(
69
+ reader: NamesReader,
70
+ platform: `0x${string}`,
71
+ handle: string,
72
+ ): Promise<Address | null> {
73
+ const owner = await read<Address>(reader, 'resolveHandle', [platform, handle])
74
+ return owner === zeroAddress ? null : owner
75
+ }
76
+
77
+ /// The handle a wallet published, exactly as stored.
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`.
91
+ ///
92
+ /// Forward-checked on chain: empty once the stored handle resolves somewhere
93
+ /// else. ENS asks integrators to perform that check themselves and warns that
94
+ /// skipping it displays a name its holder no longer owns; here it cannot be
95
+ /// skipped, because the contract does it.
96
+ export async function primaryName(
97
+ reader: NamesReader,
98
+ wallet: Address,
99
+ platform: `0x${string}`,
100
+ ): Promise<string | null> {
101
+ const name = await read<string>(reader, 'primaryOf', [wallet, platform])
102
+ return name.length === 0 ? null : name
103
+ }
104
+
105
+ export interface PairResolution {
106
+ /// The current owner of the handle, or `null`.
107
+ wallet: Address | null
108
+ /// True only when the account id resolves to that same wallet.
109
+ ///
110
+ /// False means the caller's `(handle, id)` pair comes from two moments:
111
+ /// somebody proved the handle after the caller learned who held it. That is
112
+ /// staleness, not corruption.
113
+ idAgrees: boolean
114
+ }
115
+
116
+ /// Resolve a handle and report whether an account id still agrees with it.
117
+ ///
118
+ /// **Read this before signing, and do not let it block a transfer.** A name
119
+ /// that will not route is not a name: sending to a handle means sending to
120
+ /// whoever proved it last, which is what the handle now means. What the flag is
121
+ /// for is telling a user that the account they think they are paying is not the
122
+ /// one that holds the name today — a decision they can only make beforehand.
123
+ ///
124
+ /// Both halves are needed. A handle on its own has nothing to disagree with.
125
+ ///
126
+ /// A handle the platform's rules reject resolves to `{wallet: null, idAgrees:
127
+ /// false}`, the same as one nobody has proved — see `resolveHandle`.
128
+ export async function resolvePair(
129
+ reader: NamesReader,
130
+ platform: `0x${string}`,
131
+ handle: string,
132
+ userId: string,
133
+ ): Promise<PairResolution> {
134
+ const [wallet, idAgrees] = await read<[Address, boolean]>(reader, 'resolvePair', [
135
+ platform,
136
+ handle,
137
+ userId,
138
+ ])
139
+
140
+ return { wallet: wallet === zeroAddress ? null : wallet, idAgrees }
141
+ }
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ /// @libid/contracts — typed viem-ready ABIs for every contract, plus the
2
+ /// identity helper layer. Subpath imports work too: `@libid/contracts/abis`
3
+ /// and `@libid/contracts/identity`.
4
+
5
+ export * from './abis/index.js'
6
+ export * from './identity/index.js'