@insumermodel/wdk-protocol-wallet-auth 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/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
package/README.md ADDED
@@ -0,0 +1,136 @@
1
+ # @insumermodel/wdk-protocol-wallet-auth
2
+
3
+ > **Wallet auth for WDK wallets.** OAuth proves who you are. Wallet auth proves what you hold.
4
+
5
+ A [Wallet Development Kit](https://docs.wdk.tether.io/) protocol module that adds a new protocol category alongside Swap, Bridge, Lending, and Fiat: **pre-transaction, condition-based access.** Given a wallet and a set of on-chain conditions, it returns a cryptographically signed pass/fail (`attest`) or a multi-dimensional trust profile (`trust`). Results are ECDSA P-256 signed and verifiable offline against a public JWKS — no secrets, no identity-first, no static credentials.
6
+
7
+ Powered by [InsumerAPI](https://insumermodel.com). Supports 33 chains including all networks used by [tether.wallet](https://tether.wallet) and WDK-based wallets (Ethereum, Polygon, Arbitrum, Optimism, Base, Avalanche, BNB, Plasma, Solana, TRON, TON, Bitcoin, XRPL, and more).
8
+
9
+ ## Why this exists
10
+
11
+ WDK ships wallet modules and protocol modules (Swap, Bridge, Lending, Fiat) but has **no pre-transaction policy layer** — nothing to answer questions like "is this wallet allowed to receive this payment?" or "does this counterparty pass a sanctions and trust screen?" before signing.
12
+
13
+ This package fills that gap as a first-class WDK protocol:
14
+
15
+ ```js
16
+ import InsumerWalletAuthProtocol from '@insumermodel/wdk-protocol-wallet-auth'
17
+
18
+ const walletAuth = new InsumerWalletAuthProtocol({ apiKey: process.env.INSUMER_API_KEY })
19
+
20
+ // Before broadcasting a transaction, verify the counterparty:
21
+ const { passed, sig, kid } = await walletAuth.attest({
22
+ address: '0xCounterparty...',
23
+ conditions: [
24
+ { type: 'token_balance', contractAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', chainId: 1, threshold: 1000, decimals: 6, label: 'USDC >= 1000' }
25
+ ]
26
+ })
27
+
28
+ if (!passed) throw new Error('counterparty failed wallet auth check')
29
+ // `sig` and `kid` are the audit trail: anyone can verify this later against the JWKS.
30
+ ```
31
+
32
+ Use cases:
33
+
34
+ - **Agent-wallet guardrails.** WDK explicitly targets "humans, machines and AI agents." When an autonomous agent holds keys, the operator wants programmable constraints the agent can't argue its way around — and a cryptographic audit trail the operator can verify after the fact.
35
+ - **Receive-side trust display.** Before a creator accepts a payment, show a trust profile on the sending wallet. Native fit for products like Rumble Wallet.
36
+ - **Compliance cover for consumer apps built on WDK.** Drop-in Travel Rule / sanctions / counterparty-risk screen.
37
+
38
+ ## Install
39
+
40
+ ```bash
41
+ npm install @insumermodel/wdk-protocol-wallet-auth
42
+ ```
43
+
44
+ Get an API key at [insumermodel.com](https://insumermodel.com) (free tier available).
45
+
46
+ ### Buying credits
47
+
48
+ The free tier ships 100 attestation credits. When you need more, credits can be purchased on-chain with **USDC, USDT, or BTC** via `POST /v1/credits/buy` — no Stripe, no signup, no fiat. Supported payment rails:
49
+
50
+ - **USDC or USDT** on any major EVM chain (Ethereum, Polygon, Arbitrum, Optimism, Base, Avalanche, BNB, and more) — the endpoint auto-detects which stablecoin you sent.
51
+ - **USDC** on Solana.
52
+ - **BTC** on Bitcoin mainnet.
53
+
54
+ Send the transfer to the platform wallet for your chosen chain, then `POST /v1/credits/buy` with `{ txHash, chainId, amount }`. Credits post as soon as the transaction is verified on-chain. See the [OpenAPI spec](https://insumermodel.com/openapi.yaml) for the full request shape.
55
+
56
+ ## API
57
+
58
+ The package exports:
59
+
60
+ - `InsumerWalletAuthProtocol` (default export) — the InsumerAPI implementation
61
+ - `WalletAuthProtocol` — the abstract base class (implement your own backend)
62
+ - `IWalletAuthProtocol` — the interface
63
+
64
+ ### `new InsumerWalletAuthProtocol(options)`
65
+
66
+ | Option | Type | Description |
67
+ |-----------|-----------|-------------|
68
+ | `apiKey` | `string` | **Required.** InsumerAPI key. |
69
+ | `account` | `object` | Optional WDK wallet account. When bound, its `getAddress()` is used as the default subject. |
70
+ | `baseUrl` | `string` | Override the API base URL. Defaults to `https://api.insumermodel.com`. |
71
+ | `fetch` | `fetch` | Override the `fetch` implementation (useful in Bare / React Native runtimes). |
72
+
73
+ ### `attest(options)` → `Promise<AttestResult>`
74
+
75
+ Evaluates one to ten on-chain conditions against a wallet and returns a cryptographically signed pass/fail. Maps to [`POST /v1/attest`](https://insumermodel.com/openapi.yaml).
76
+
77
+ ```js
78
+ const result = await walletAuth.attest({
79
+ address: '0x1234...', // defaults to bound account
80
+ conditions: [
81
+ { type: 'token_balance', contractAddress: '0xA0b8...', chainId: 1, threshold: 1000, decimals: 6 },
82
+ { type: 'nft_ownership', contractAddress: '0xBC4C...', chainId: 1 }
83
+ ],
84
+ jwt: true, // optional: also return an ES256 JWT
85
+ merkleProof: true // optional: include EIP-1186 Merkle storage proofs (2 credits instead of 1)
86
+ })
87
+
88
+ // result.passed — true only if every condition is met
89
+ // result.attestation — full attestation object (per-condition results, block info, condition hash)
90
+ // result.sig / result.kid — ECDSA P-256 signature + key id (verify against JWKS)
91
+ // result.jwt — ES256 JWT form, when requested
92
+ // result.creditsRemaining — credits remaining on the API key
93
+ ```
94
+
95
+ Supported condition types: `token_balance`, `nft_ownership`, `eas_attestation`, `farcaster_id`. Supported chains: 30 EVM chains plus Solana, XRPL, and Bitcoin. See the [InsumerAPI OpenAPI spec](https://insumermodel.com/openapi.yaml) for the full schema.
96
+
97
+ ### `trust(options)` → `Promise<TrustResult>`
98
+
99
+ Returns a multi-dimensional trust profile: 36+ signed checks across stablecoins, governance, NFTs, staking, and (optionally) Solana, XRPL, and Bitcoin dimensions. Maps to [`POST /v1/trust`](https://insumermodel.com/openapi.yaml).
100
+
101
+ ```js
102
+ const { trust, sig, kid } = await walletAuth.trust({
103
+ address: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
104
+ solanaAddress: '...', // optional, adds Solana dimension
105
+ xrplAddress: '...', // optional, adds XRPL dimension
106
+ bitcoinAddress: '...' // optional, adds Bitcoin dimension
107
+ })
108
+
109
+ // trust.id — TRST-XXXXX profile id
110
+ // trust.dimensions — per-dimension checks (each individually signed)
111
+ // trust.summary — totalChecks, totalPassed, dimensionsWithActivity
112
+ ```
113
+
114
+ ## Verification
115
+
116
+ Every attestation and trust result is ECDSA P-256 signed. The signature (`sig`) and key id (`kid`) let any party verify the result offline, without calling the API, using the public JWKS:
117
+
118
+ ```
119
+ https://insumermodel.com/.well-known/jwks.json
120
+ ```
121
+
122
+ Use any standard JOSE/JWT library, or `npm install insumer-verify` for a convenience wrapper.
123
+
124
+ ## Supported environments
125
+
126
+ - Node.js ≥ 18 (uses the built-in `fetch`)
127
+ - Bare / React Native runtimes (pass a `fetch` implementation in the constructor)
128
+ - Browsers (CORS is enabled on `api.insumermodel.com`)
129
+
130
+ ## License
131
+
132
+ Apache-2.0. See [LICENSE](./LICENSE).
133
+
134
+ ## Maintainer
135
+
136
+ Built by [Douglas Borthwick](https://insumermodel.com). Issues and contributions welcome at the [GitHub repo](https://github.com/douglasborthwick-crypto/wdk-protocol-wallet-auth).
package/index.js ADDED
@@ -0,0 +1,25 @@
1
+ // Copyright 2026 Douglas Borthwick / InsumerAPI
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ 'use strict'
16
+
17
+ /** @typedef {import('./src/wallet-auth-protocol.js').AttestOptions} AttestOptions */
18
+ /** @typedef {import('./src/wallet-auth-protocol.js').AttestResult} AttestResult */
19
+ /** @typedef {import('./src/wallet-auth-protocol.js').TrustOptions} TrustOptions */
20
+ /** @typedef {import('./src/wallet-auth-protocol.js').TrustResult} TrustResult */
21
+ /** @typedef {import('./src/wallet-auth-protocol.js').Condition} Condition */
22
+
23
+ export { default as WalletAuthProtocol, IWalletAuthProtocol } from './src/wallet-auth-protocol.js'
24
+ export { default as InsumerWalletAuthProtocol } from './src/insumer-wallet-auth-protocol.js'
25
+ export { default } from './src/insumer-wallet-auth-protocol.js'
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@insumermodel/wdk-protocol-wallet-auth",
3
+ "version": "0.1.0",
4
+ "description": "WDK protocol module for wallet auth — cryptographically signed, pre-transaction condition-based access. OAuth proves who you are; wallet auth proves what you hold. Powered by InsumerAPI.",
5
+ "keywords": [
6
+ "wdk",
7
+ "protocol",
8
+ "wallet-auth",
9
+ "condition-based-access",
10
+ "attestation",
11
+ "trust",
12
+ "insumerapi"
13
+ ],
14
+ "author": "Douglas Borthwick <douglas@insumermodel.com>",
15
+ "license": "Apache-2.0",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/douglasborthwick-crypto/wdk-protocol-wallet-auth.git"
19
+ },
20
+ "homepage": "https://insumermodel.com/developers/wdk/",
21
+ "bugs": {
22
+ "url": "https://github.com/douglasborthwick-crypto/wdk-protocol-wallet-auth/issues"
23
+ },
24
+ "main": "index.js",
25
+ "type": "module",
26
+ "types": "./types",
27
+ "files": [
28
+ "index.js",
29
+ "src/",
30
+ "types/",
31
+ "README.md",
32
+ "LICENSE"
33
+ ],
34
+ "scripts": {
35
+ "test": "node --test tests/*.test.js",
36
+ "lint": "standard",
37
+ "lint:fix": "standard --fix"
38
+ },
39
+ "peerDependencies": {
40
+ "@tetherto/wdk-wallet": "^1.0.0-beta.1"
41
+ },
42
+ "peerDependenciesMeta": {
43
+ "@tetherto/wdk-wallet": {
44
+ "optional": true
45
+ }
46
+ },
47
+ "devDependencies": {
48
+ "standard": "^17.1.2"
49
+ },
50
+ "exports": {
51
+ ".": {
52
+ "types": "./types/index.d.ts",
53
+ "default": "./index.js"
54
+ },
55
+ "./package": {
56
+ "default": "./package.json"
57
+ }
58
+ },
59
+ "publishConfig": {
60
+ "access": "public",
61
+ "registry": "https://registry.npmjs.org/"
62
+ },
63
+ "engines": {
64
+ "node": ">=18"
65
+ }
66
+ }
@@ -0,0 +1,170 @@
1
+ // Copyright 2026 Douglas Borthwick / InsumerAPI
2
+ //
3
+ // Licensed under the Apache License, Version 2.0.
4
+
5
+ 'use strict'
6
+
7
+ import WalletAuthProtocol from './wallet-auth-protocol.js'
8
+
9
+ /** @typedef {import('./wallet-auth-protocol.js').AttestOptions} AttestOptions */
10
+ /** @typedef {import('./wallet-auth-protocol.js').AttestResult} AttestResult */
11
+ /** @typedef {import('./wallet-auth-protocol.js').TrustOptions} TrustOptions */
12
+ /** @typedef {import('./wallet-auth-protocol.js').TrustResult} TrustResult */
13
+
14
+ const DEFAULT_BASE_URL = 'https://api.insumermodel.com'
15
+
16
+ /**
17
+ * InsumerAPI implementation of the WDK Wallet Auth protocol.
18
+ *
19
+ * Wraps POST /v1/attest and POST /v1/trust. Results are ECDSA P-256 signed
20
+ * and verifiable offline against the JWKS at
21
+ * https://insumermodel.com/.well-known/jwks.json using any standard JWT or
22
+ * JOSE library (or the `insumer-verify` npm package).
23
+ */
24
+ export default class InsumerWalletAuthProtocol extends WalletAuthProtocol {
25
+ /**
26
+ * @param {Object} options
27
+ * @param {string} options.apiKey - InsumerAPI key. Get one at https://insumermodel.com/.
28
+ * @param {string} [options.baseUrl] - Override the API base URL. Defaults to https://api.insumermodel.com.
29
+ * @param {any} [options.account] - Optional wallet account to bind. When present, its getAddress() is used as the default subject.
30
+ * @param {typeof fetch} [options.fetch] - Override the fetch implementation (useful in Bare/React Native runtimes).
31
+ */
32
+ constructor (options = {}) {
33
+ super(options.account)
34
+ if (!options.apiKey || typeof options.apiKey !== 'string') {
35
+ throw new Error('InsumerWalletAuthProtocol: apiKey is required')
36
+ }
37
+ /** @private */
38
+ this._apiKey = options.apiKey
39
+ /** @private */
40
+ this._baseUrl = (options.baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, '')
41
+ /** @private */
42
+ this._fetch = options.fetch || globalThis.fetch
43
+ if (typeof this._fetch !== 'function') {
44
+ throw new Error('InsumerWalletAuthProtocol: no fetch implementation available. Pass { fetch } in the runtime environment.')
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Resolve the default subject address from the bound account, if any.
50
+ * @private
51
+ * @returns {Promise<string | undefined>}
52
+ */
53
+ async _defaultAddress () {
54
+ if (!this._account) return undefined
55
+ if (typeof this._account.getAddress === 'function') {
56
+ return await this._account.getAddress()
57
+ }
58
+ if (typeof this._account.address === 'string') {
59
+ return this._account.address
60
+ }
61
+ return undefined
62
+ }
63
+
64
+ /**
65
+ * POST to an InsumerAPI endpoint and unwrap the standard response envelope.
66
+ * @private
67
+ */
68
+ async _post (path, body) {
69
+ const res = await this._fetch(`${this._baseUrl}${path}`, {
70
+ method: 'POST',
71
+ headers: {
72
+ 'Content-Type': 'application/json',
73
+ 'X-API-Key': this._apiKey
74
+ },
75
+ body: JSON.stringify(body)
76
+ })
77
+
78
+ let payload
79
+ try {
80
+ payload = await res.json()
81
+ } catch (_e) {
82
+ throw new Error(`InsumerAPI ${path} returned non-JSON response (HTTP ${res.status})`)
83
+ }
84
+
85
+ if (!res.ok || payload?.ok !== true) {
86
+ const code = payload?.error?.code || `http_${res.status}`
87
+ const msg = payload?.error?.message || res.statusText || 'unknown error'
88
+ const err = new Error(`InsumerAPI ${path} failed: ${code} — ${msg}`)
89
+ err.status = res.status
90
+ err.code = code
91
+ err.response = payload
92
+ throw err
93
+ }
94
+
95
+ return payload
96
+ }
97
+
98
+ /**
99
+ * Evaluate one or more on-chain conditions against a wallet. Returns a
100
+ * signed pass/fail attestation.
101
+ *
102
+ * @param {AttestOptions} options
103
+ * @returns {Promise<AttestResult>}
104
+ */
105
+ async attest (options) {
106
+ if (!options || !Array.isArray(options.conditions) || options.conditions.length === 0) {
107
+ throw new Error('attest(options): conditions array is required (1-10 items)')
108
+ }
109
+ if (options.conditions.length > 10) {
110
+ throw new Error('attest(options): at most 10 conditions per call')
111
+ }
112
+
113
+ const address = options.address || await this._defaultAddress()
114
+
115
+ /** @type {Record<string, any>} */
116
+ const body = { conditions: options.conditions }
117
+ if (address) body.wallet = address
118
+ if (options.solanaAddress) body.solanaWallet = options.solanaAddress
119
+ if (options.xrplAddress) body.xrplWallet = options.xrplAddress
120
+ if (options.bitcoinAddress) body.bitcoinWallet = options.bitcoinAddress
121
+ if (options.jwt) body.format = 'jwt'
122
+ if (options.merkleProof) body.proof = 'merkle'
123
+
124
+ const payload = await this._post('/v1/attest', body)
125
+ const data = payload.data || {}
126
+ const meta = payload.meta || {}
127
+
128
+ return {
129
+ passed: data.attestation?.pass === true,
130
+ attestation: data.attestation,
131
+ sig: data.sig,
132
+ kid: data.kid,
133
+ jwt: data.jwt,
134
+ creditsRemaining: meta.creditsRemaining,
135
+ creditsCharged: meta.creditsCharged
136
+ }
137
+ }
138
+
139
+ /**
140
+ * Return a multi-dimensional trust profile for a wallet.
141
+ *
142
+ * @param {TrustOptions} [options]
143
+ * @returns {Promise<TrustResult>}
144
+ */
145
+ async trust (options = {}) {
146
+ const address = options.address || await this._defaultAddress()
147
+ if (!address) {
148
+ throw new Error('trust(options): address is required (pass options.address or bind a wallet account)')
149
+ }
150
+
151
+ /** @type {Record<string, any>} */
152
+ const body = { wallet: address }
153
+ if (options.solanaAddress) body.solanaWallet = options.solanaAddress
154
+ if (options.xrplAddress) body.xrplWallet = options.xrplAddress
155
+ if (options.bitcoinAddress) body.bitcoinWallet = options.bitcoinAddress
156
+ if (options.merkleProof) body.proof = 'merkle'
157
+
158
+ const payload = await this._post('/v1/trust', body)
159
+ const data = payload.data || {}
160
+ const meta = payload.meta || {}
161
+
162
+ return {
163
+ trust: data.trust,
164
+ sig: data.sig,
165
+ kid: data.kid,
166
+ creditsRemaining: meta.creditsRemaining,
167
+ creditsCharged: meta.creditsCharged
168
+ }
169
+ }
170
+ }
@@ -0,0 +1,150 @@
1
+ // Copyright 2026 Douglas Borthwick / InsumerAPI
2
+ //
3
+ // Licensed under the Apache License, Version 2.0.
4
+
5
+ 'use strict'
6
+
7
+ /**
8
+ * Abstract base class defining a new WDK protocol category: Wallet Auth.
9
+ *
10
+ * OAuth proves who you are. Wallet auth proves what you hold.
11
+ *
12
+ * Alongside WDK's existing Swap, Bridge, Lending, and Fiat protocols, this
13
+ * defines a pre-transaction verification protocol: given a wallet and a set
14
+ * of on-chain conditions, return a cryptographically signed pass/fail
15
+ * (attestation) or a multi-dimensional trust profile. The output is an
16
+ * ECDSA-signed credential the caller can verify offline; no secrets, no
17
+ * identity-first, no static credentials.
18
+ *
19
+ * Implementations (e.g. InsumerWalletAuthProtocol) call an external
20
+ * verification service and return signed results. The protocol itself never
21
+ * touches private keys or broadcasts transactions — it runs before, not
22
+ * during, the signing flow.
23
+ *
24
+ * Shape-compatible with upstream WDK protocol base classes and intended to
25
+ * be proposed for inclusion in @tetherto/wdk-wallet/protocols.
26
+ */
27
+
28
+ /** @typedef {import('@tetherto/wdk-wallet').IWalletAccountReadOnly} IWalletAccountReadOnly */
29
+ /** @typedef {import('@tetherto/wdk-wallet').IWalletAccount} IWalletAccount */
30
+
31
+ /**
32
+ * @typedef {Object} Condition
33
+ * @property {"token_balance"|"nft_ownership"|"eas_attestation"|"farcaster_id"} type
34
+ * @property {string} [contractAddress]
35
+ * @property {(number|string)} [chainId]
36
+ * @property {(number|string|bigint)} [threshold]
37
+ * @property {number} [decimals]
38
+ * @property {string} [tokenId]
39
+ * @property {string} [schemaId]
40
+ * @property {string} [attester]
41
+ * @property {string} [indexer]
42
+ * @property {string} [template]
43
+ * @property {string} [currency]
44
+ * @property {string} [label]
45
+ */
46
+
47
+ /**
48
+ * @typedef {Object} AttestOptions
49
+ * @property {Condition[]} conditions - One to ten on-chain conditions to evaluate.
50
+ * @property {string} [address] - Address to evaluate. Defaults to the attached account.
51
+ * @property {string} [solanaAddress] - Solana address, if different from the default EVM address.
52
+ * @property {string} [xrplAddress] - XRPL r-address.
53
+ * @property {string} [bitcoinAddress] - Bitcoin address.
54
+ * @property {boolean} [jwt] - If true, request an ES256 JWT alongside the attestation.
55
+ * @property {boolean} [merkleProof] - If true, request EIP-1186 Merkle storage proofs (costs 2 credits instead of 1).
56
+ */
57
+
58
+ /**
59
+ * @typedef {Object} AttestResult
60
+ * @property {boolean} passed - True if every condition is met.
61
+ * @property {Object} attestation - Raw attestation object (condition-by-condition results, block numbers, condition hash).
62
+ * @property {string} sig - ECDSA P-256 signature over the attestation (base64).
63
+ * @property {string} kid - Key ID identifying the signing key in the JWKS.
64
+ * @property {string} [jwt] - ES256 JWT form of the attestation, when requested.
65
+ * @property {number} creditsRemaining - Credits remaining on the API key after this call.
66
+ * @property {number} creditsCharged - Credits consumed by this call.
67
+ */
68
+
69
+ /**
70
+ * @typedef {Object} TrustOptions
71
+ * @property {string} [address] - EVM address to profile. Defaults to the attached account.
72
+ * @property {string} [solanaAddress] - Optional Solana address.
73
+ * @property {string} [xrplAddress] - Optional XRPL r-address.
74
+ * @property {string} [bitcoinAddress] - Optional Bitcoin address.
75
+ * @property {boolean} [merkleProof] - If true, request Merkle proofs (costs 6 credits instead of 3).
76
+ */
77
+
78
+ /**
79
+ * @typedef {Object} TrustResult
80
+ * @property {Object} trust - Full trust profile (dimensions, checks, summary, profile id).
81
+ * @property {string} sig - ECDSA P-256 signature over the trust object.
82
+ * @property {string} kid - Key ID identifying the signing key in the JWKS.
83
+ * @property {number} creditsRemaining
84
+ * @property {number} creditsCharged
85
+ */
86
+
87
+ /** @interface */
88
+ export class IWalletAuthProtocol {
89
+ /**
90
+ * Evaluate one or more on-chain conditions against a wallet and return a
91
+ * cryptographically signed pass/fail attestation. Runs server-side against
92
+ * live chain state and never exposes raw balances unless merkleProof is
93
+ * requested.
94
+ *
95
+ * @param {AttestOptions} options
96
+ * @returns {Promise<AttestResult>}
97
+ */
98
+ async attest (options) {
99
+ throw new Error('attest(options) not implemented')
100
+ }
101
+
102
+ /**
103
+ * Return a multi-dimensional trust profile for a wallet across stablecoins,
104
+ * governance, NFTs, and staking activity (plus optional Solana, XRPL, and
105
+ * Bitcoin dimensions). Each check is individually signed.
106
+ *
107
+ * @param {TrustOptions} [options]
108
+ * @returns {Promise<TrustResult>}
109
+ */
110
+ async trust (options) {
111
+ throw new Error('trust(options) not implemented')
112
+ }
113
+ }
114
+
115
+ /**
116
+ * @abstract
117
+ * @implements {IWalletAuthProtocol}
118
+ */
119
+ export default class WalletAuthProtocol {
120
+ /**
121
+ * @param {IWalletAccountReadOnly | IWalletAccount} [account] - Optional wallet
122
+ * account to bind. When present, its address is used as the default subject
123
+ * for attest() and trust() calls.
124
+ */
125
+ constructor (account) {
126
+ /**
127
+ * @protected
128
+ * @type {IWalletAccountReadOnly | IWalletAccount | undefined}
129
+ */
130
+ this._account = account
131
+ }
132
+
133
+ /**
134
+ * @abstract
135
+ * @param {AttestOptions} options
136
+ * @returns {Promise<AttestResult>}
137
+ */
138
+ async attest (options) {
139
+ throw new Error('attest(options) not implemented')
140
+ }
141
+
142
+ /**
143
+ * @abstract
144
+ * @param {TrustOptions} [options]
145
+ * @returns {Promise<TrustResult>}
146
+ */
147
+ async trust (options) {
148
+ throw new Error('trust(options) not implemented')
149
+ }
150
+ }