@redditech/agent-protocol 0.0.0-stage → 0.2.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/CHANGELOG.md +89 -0
- package/LICENSE +21 -0
- package/README.md +394 -2
- package/dist/adl.d.ts +141 -0
- package/dist/adl.js +3601 -0
- package/dist/agent-stack-fixtures.d.ts +743 -0
- package/dist/agent-stack-fixtures.js +1554 -0
- package/dist/ai-catalog.d.ts +128 -0
- package/dist/ai-catalog.js +373 -0
- package/dist/attestation-reputation.d.ts +102 -0
- package/dist/attestation-reputation.js +279 -0
- package/dist/audd-rail-config.d.ts +102 -0
- package/dist/audd-rail-config.js +294 -0
- package/dist/browser-wallet-approval.d.ts +293 -0
- package/dist/browser-wallet-approval.js +1201 -0
- package/dist/discovery-source.d.ts +115 -0
- package/dist/discovery-source.js +251 -0
- package/dist/evidence-archive.d.ts +73 -0
- package/dist/evidence-archive.js +238 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +23 -0
- package/dist/mpp-tempo-receipt-shapes.d.ts +201 -0
- package/dist/mpp-tempo-receipt-shapes.js +330 -0
- package/dist/okf-adapter.d.ts +229 -0
- package/dist/okf-adapter.js +556 -0
- package/dist/okf-conformance.d.ts +208 -0
- package/dist/okf-conformance.js +651 -0
- package/dist/okf-instruction-safety.d.ts +192 -0
- package/dist/okf-instruction-safety.js +509 -0
- package/dist/onboarding-analyser-handoff.d.ts +391 -0
- package/dist/onboarding-analyser-handoff.js +959 -0
- package/dist/onboarding-state-machine.d.ts +228 -0
- package/dist/onboarding-state-machine.js +432 -0
- package/dist/payment-records.d.ts +181 -0
- package/dist/payment-records.js +599 -0
- package/dist/policy.d.ts +33 -0
- package/dist/policy.js +45 -0
- package/dist/provider-trust.d.ts +113 -0
- package/dist/provider-trust.js +346 -0
- package/dist/quasar-registry-compatibility.d.ts +113 -0
- package/dist/quasar-registry-compatibility.js +214 -0
- package/dist/ranking-explainability.d.ts +202 -0
- package/dist/ranking-explainability.js +302 -0
- package/dist/receipt-v2.d.ts +202 -0
- package/dist/receipt-v2.js +418 -0
- package/dist/repo-explorer-evidence-manifest.d.ts +387 -0
- package/dist/repo-explorer-evidence-manifest.js +1187 -0
- package/dist/source-diagnostics.d.ts +84 -0
- package/dist/source-diagnostics.js +193 -0
- package/dist/source-trust-conformance-matrix.d.ts +207 -0
- package/dist/source-trust-conformance-matrix.js +672 -0
- package/examples/ard-no-spend-ai-catalog.json +51 -0
- package/examples/ard-no-spend-demo.mjs +355 -0
- package/examples/interpretation-guide-scenarios.mjs +302 -0
- package/package.json +144 -4
|
@@ -0,0 +1,1201 @@
|
|
|
1
|
+
import { AUDD_ASSET, AUDD_DECIMALS, AUDD_DETERMINISTIC_FIXTURE_MINT, AUDD_OFFICIAL_SOLANA_MAINNET_MINT, AUDD_RAIL_CONFIG, SOLANA_DEVNET_CAIP2, SOLANA_MAINNET_BETA_CAIP2, SPL_TOKEN_PROGRAM_ID, getAuddRailEnvironmentConfig, } from './audd-rail-config.js';
|
|
2
|
+
export const BROWSER_WALLET_APPROVAL_SCHEMA_VERSION = 'reddi.browser-wallet.single-use-approval.v1';
|
|
3
|
+
export const BROWSER_WALLET_APPROVAL_VALIDATION_SCHEMA_VERSION = 'reddi.browser-wallet.approval-validation.v1';
|
|
4
|
+
export const BROWSER_WALLET_TIER1_LOCAL_HARNESS_SCHEMA_VERSION = 'reddi.browser-wallet.tier1-local-harness-contract.v1';
|
|
5
|
+
export const BROWSER_WALLET_IDENTITY_COPY_GUARD_SCHEMA_VERSION = 'reddi.browser-wallet.identity-copy-guard.v1';
|
|
6
|
+
export const CANONICAL_DEVNET_USDC_MINT = '4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU';
|
|
7
|
+
const OFFICIAL_SOLANA_MAINNET_USDC_MINT = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';
|
|
8
|
+
const REJECTED_MAINNET_MINTS = new Set([AUDD_OFFICIAL_SOLANA_MAINNET_MINT, OFFICIAL_SOLANA_MAINNET_USDC_MINT]);
|
|
9
|
+
const NON_LIVE_COPY_GUARD_RAIL_ENVIRONMENTS = new Set(['deterministic-fixture', 'local-test-mint', 'devnet-unverified']);
|
|
10
|
+
const SUPPORTED_DEVNET_BROWSER_WALLET_PROVIDERS = new Set(['Phantom']);
|
|
11
|
+
const BROWSER_WALLET_ALLOWED_ACTIONS = new Set(['connect-only', 'register-agent', 'x402-devnet-usdc-payment']);
|
|
12
|
+
const BROAD_STRING_PATTERN = /(^|[\s:/_-])(?:any|all|wildcard|default|latest|current|unknown|tbd|todo|production|prod|mainnet)([\s:/_-]|$)|\*/i;
|
|
13
|
+
const ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:@/-]{1,160}$/;
|
|
14
|
+
const HASH_PATTERN = /^sha256:[a-f0-9]{64}$/;
|
|
15
|
+
const NON_NEGATIVE_INTEGER_STRING = /^(0|[1-9]\d*)$/;
|
|
16
|
+
const LOOPBACK_DYNAMIC_SENTINEL = 'dynamic-loopback';
|
|
17
|
+
const DEFAULT_PLAYWRIGHT_FIXTURE_PUBLIC_KEY = '11111111111111111111111111111111';
|
|
18
|
+
const APPROVAL_TOP_LEVEL_KEYS = new Set([
|
|
19
|
+
'schemaVersion',
|
|
20
|
+
'status',
|
|
21
|
+
'approvalId',
|
|
22
|
+
'approver',
|
|
23
|
+
'approvedAt',
|
|
24
|
+
'expiresAt',
|
|
25
|
+
'usage',
|
|
26
|
+
'provider',
|
|
27
|
+
'browserProfile',
|
|
28
|
+
'wallet',
|
|
29
|
+
'network',
|
|
30
|
+
'uiAction',
|
|
31
|
+
'programs',
|
|
32
|
+
'funding',
|
|
33
|
+
'caps',
|
|
34
|
+
'retryPolicy',
|
|
35
|
+
'asset',
|
|
36
|
+
'evidence',
|
|
37
|
+
'rollback',
|
|
38
|
+
'boundaries',
|
|
39
|
+
]);
|
|
40
|
+
const USAGE_KEYS = new Set(['scope', 'approvedUseCount', 'consumedUseCount', 'nonce', 'reusePolicy']);
|
|
41
|
+
const PROVIDER_KEYS = new Set(['name', 'version', 'source', 'devnetSupport']);
|
|
42
|
+
const SOURCE_KEYS = new Set(['kind', 'url', 'retrievedAt', 'sha256']);
|
|
43
|
+
const BROWSER_PROFILE_KEYS = new Set([
|
|
44
|
+
'id',
|
|
45
|
+
'isolation',
|
|
46
|
+
'syncDisabled',
|
|
47
|
+
'primaryProfile',
|
|
48
|
+
'onlyApprovedExtension',
|
|
49
|
+
'automatedExtensionInstall',
|
|
50
|
+
'deleteAfterRun',
|
|
51
|
+
]);
|
|
52
|
+
const WALLET_KEYS = new Set(['publicKey', 'secretMaterial', 'productionSeedImported', 'custody']);
|
|
53
|
+
const NETWORK_KEYS = new Set(['rapAlias', 'caip2', 'cluster', 'rpcHttp', 'rpcWs']);
|
|
54
|
+
const UI_ACTION_KEYS = new Set(['route', 'action', 'executionMode', 'defaultOff', 'exactOnce', 'devnetActionAvailableByDefault']);
|
|
55
|
+
const PROGRAMS_KEYS = new Set(['target', 'framework', 'source', 'ids', 'submissionReady']);
|
|
56
|
+
const PROGRAM_IDS_KEYS = new Set(['escrow', 'registry', 'reputation', 'attestation']);
|
|
57
|
+
const FUNDING_KEYS = new Set(['source', 'sourceRef', 'humanApproved', 'aiFaucetUse', 'autoTopUp', 'maxBalanceSol']);
|
|
58
|
+
const CAPS_KEYS = new Set(['perActionBaseUnits', 'perSessionBaseUnits', 'maxFeeLamports', 'maxActions']);
|
|
59
|
+
const RETRY_POLICY_KEYS = new Set(['allowed', 'maxRetries', 'countsAgainstCaps']);
|
|
60
|
+
const ASSET_KEYS = new Set([
|
|
61
|
+
'symbol',
|
|
62
|
+
'railEnvironment',
|
|
63
|
+
'mint',
|
|
64
|
+
'tokenProgram',
|
|
65
|
+
'decimals',
|
|
66
|
+
'source',
|
|
67
|
+
'official',
|
|
68
|
+
'auddPartnerConfirmation',
|
|
69
|
+
'auddDevnetApprovalRef',
|
|
70
|
+
]);
|
|
71
|
+
const AUDD_PARTNER_CONFIRMATION_KEYS = new Set(['sourceUrl', 'sourceRetrievedAt', 'sourceSha256', 'confirmedMint', 'confirmedDecimals', 'confirmedTokenProgram']);
|
|
72
|
+
const EVIDENCE_KEYS = new Set(['destination', 'redaction']);
|
|
73
|
+
const REDACTION_KEYS = new Set([
|
|
74
|
+
'privateKeys',
|
|
75
|
+
'seedPhrases',
|
|
76
|
+
'signerArrays',
|
|
77
|
+
'authHeaders',
|
|
78
|
+
'cookies',
|
|
79
|
+
'rawPaymentPayloads',
|
|
80
|
+
'screenshots',
|
|
81
|
+
'includePublicKey',
|
|
82
|
+
'includeSignatures',
|
|
83
|
+
]);
|
|
84
|
+
const ROLLBACK_KEYS = new Set([
|
|
85
|
+
'owner',
|
|
86
|
+
'disconnectRevoke',
|
|
87
|
+
'deleteBrowserProfile',
|
|
88
|
+
'deleteLocalState',
|
|
89
|
+
'preserveRedactedEvidence',
|
|
90
|
+
'incidentSuspend',
|
|
91
|
+
'freshApprovalRequired',
|
|
92
|
+
]);
|
|
93
|
+
const BOUNDARY_KEYS = new Set([
|
|
94
|
+
'noMainnet',
|
|
95
|
+
'noProduction',
|
|
96
|
+
'noCustody',
|
|
97
|
+
'noSettlementFinality',
|
|
98
|
+
'noOfficialAuddDevnet',
|
|
99
|
+
'noLiveFunds',
|
|
100
|
+
'noAiFaucet',
|
|
101
|
+
'noPayShProduction',
|
|
102
|
+
'noAutomaticTopUp',
|
|
103
|
+
]);
|
|
104
|
+
const TIER1_CONTRACT_KEYS = new Set([
|
|
105
|
+
'schemaVersion',
|
|
106
|
+
'enabledByDefault',
|
|
107
|
+
'executionState',
|
|
108
|
+
'network',
|
|
109
|
+
'browserIdentity',
|
|
110
|
+
'asset',
|
|
111
|
+
'observation',
|
|
112
|
+
'railIdentity',
|
|
113
|
+
'cleanup',
|
|
114
|
+
'prohibitedActions',
|
|
115
|
+
]);
|
|
116
|
+
const TIER1_NETWORK_KEYS = new Set(['rapAlias', 'caip2', 'rpcHttp', 'rpcWs', 'dynamicPorts', 'loopbackOnly', 'remoteDatasource', 'startupAirdrop', 'transactionModeBlockProduction']);
|
|
117
|
+
const TIER1_BROWSER_IDENTITY_KEYS = new Set(['kind', 'scope', 'publicKeyOnly', 'productionSeedImported', 'secretStorage', 'profileIsolation']);
|
|
118
|
+
const TIER1_ASSET_KEYS = new Set(['label', 'environment', 'mint', 'mintSource', 'tokenProgram', 'decimals', 'grantEligibility']);
|
|
119
|
+
const TIER1_OBSERVATION_KEYS = new Set(['instruction', 'source', 'exactTransferChecked', 'exactlyOneMatchingTransfer', 'requiredFields', 'expectedTermsAreObservedEvidence']);
|
|
120
|
+
const TIER1_RAIL_IDENTITY_KEYS = new Set(['railEnvironment', 'networkAlias', 'caip2', 'asset', 'tokenProgram', 'decimals', 'observationSource', 'grantEligibility']);
|
|
121
|
+
const TIER1_CLEANUP_KEYS = new Set(['disconnectRevoke', 'deleteBrowserProfile', 'deleteLocalState', 'deleteKeyMaterial', 'redactEvidence', 'incidentSuspend', 'freshApprovalRequired']);
|
|
122
|
+
const COPY_GUARD_KEYS = new Set([
|
|
123
|
+
'schemaVersion',
|
|
124
|
+
'railEnvironment',
|
|
125
|
+
'assetLabel',
|
|
126
|
+
'networkAlias',
|
|
127
|
+
'caip2',
|
|
128
|
+
'mint',
|
|
129
|
+
'tokenProgram',
|
|
130
|
+
'decimals',
|
|
131
|
+
'observationSource',
|
|
132
|
+
'grantEligibility',
|
|
133
|
+
'x402Export',
|
|
134
|
+
'policy',
|
|
135
|
+
'receipt',
|
|
136
|
+
'copy',
|
|
137
|
+
]);
|
|
138
|
+
const X402_EXPORT_KEYS = new Set(['state', 'asset', 'networkAlias', 'caip2', 'mint', 'tokenProgram', 'decimals']);
|
|
139
|
+
const POLICY_KEYS = new Set(['grantEligibility', 'operatorApprovalRef', 'controlledLive']);
|
|
140
|
+
const RECEIPT_KEYS = new Set(['claim', 'observationStatus', 'settlementFinality', 'controlledLiveEvidence']);
|
|
141
|
+
const OBSERVATION_SOURCE_RANK = {
|
|
142
|
+
'expected-only': 0,
|
|
143
|
+
'parsed-transaction-fixture': 1,
|
|
144
|
+
'local-validator': 2,
|
|
145
|
+
'parsed-rpc-transaction': 3,
|
|
146
|
+
};
|
|
147
|
+
const RECEIPT_OBSERVATION_STATUS_RANK = {
|
|
148
|
+
'not-observed': 0,
|
|
149
|
+
'fixture-observed': 1,
|
|
150
|
+
'local-observed': 2,
|
|
151
|
+
'rpc-observed': 3,
|
|
152
|
+
};
|
|
153
|
+
const RAIL_MAX_OBSERVATION_SOURCE = {
|
|
154
|
+
'deterministic-fixture': 'parsed-transaction-fixture',
|
|
155
|
+
'local-test-mint': 'local-validator',
|
|
156
|
+
'devnet-unverified': 'expected-only',
|
|
157
|
+
};
|
|
158
|
+
const RECEIPT_CLAIM_RANK = {
|
|
159
|
+
'expected-only': 0,
|
|
160
|
+
'fixture-only': 0,
|
|
161
|
+
'observed-transfer-checked': 2,
|
|
162
|
+
'observed-settlement': 3,
|
|
163
|
+
};
|
|
164
|
+
const COPY_KEYS = new Set(['title', 'summary', 'badges', 'notes']);
|
|
165
|
+
const AUDD_IDENTITY_CLAIM_PATTERN = /official[\s_-]*AUDD|AUDD[\s_-]*official|official\s+Devnet\s+AUDD|AUDD\s+Devnet\s+official|AUDD[\s_-]*endorse(?:s|d|ment)?|endorse(?:d|ment)[\s_-]*(?:by|from)[\s_-]*AUDD/i;
|
|
166
|
+
const DIRECTLY_NEGATED_AUDD_IDENTITY_PATTERN = /(?<!\b(?:not|never|no|non)[\s_-]+)\b(?:not|never|no)\s+(?:an?\s+)?(?:official[\s_-]*AUDD|AUDD[\s_-]*official|AUDD[\s_-]*endorse(?:d|ment)|endorse(?:d|ment)[\s_-]*(?:by|from)[\s_-]*AUDD)/gi;
|
|
167
|
+
const TIER1_REQUIRED_OBSERVATION_FIELDS = [
|
|
168
|
+
'mint',
|
|
169
|
+
'tokenProgram',
|
|
170
|
+
'decimals',
|
|
171
|
+
'payee',
|
|
172
|
+
'destinationOwner',
|
|
173
|
+
'amount',
|
|
174
|
+
'memo',
|
|
175
|
+
'signature',
|
|
176
|
+
'instructionIndex',
|
|
177
|
+
];
|
|
178
|
+
const TIER1_PROHIBITED_ACTION_IDS = [
|
|
179
|
+
'no-mainnet',
|
|
180
|
+
'no-devnet-rpc',
|
|
181
|
+
'no-faucet-or-airdrop',
|
|
182
|
+
'no-committed-key-material',
|
|
183
|
+
'no-signature-generation',
|
|
184
|
+
'no-blockhash-generation',
|
|
185
|
+
'no-transaction-action',
|
|
186
|
+
'no-runtime-artifacts',
|
|
187
|
+
];
|
|
188
|
+
export const BROWSER_WALLET_TIER1_PROHIBITED_ACTION_EXPLANATIONS = {
|
|
189
|
+
'no-mainnet': 'no mainnet endpoint, wallet, token, transaction, or funding source',
|
|
190
|
+
'no-devnet-rpc': 'no Devnet RPC or hosted provider endpoint in Tier 1',
|
|
191
|
+
'no-faucet-or-airdrop': 'no Solana faucet request or startup airdrop',
|
|
192
|
+
'no-committed-key-material': 'no committed keypair, signer array, seed phrase, or reusable wallet file',
|
|
193
|
+
'no-signature-generation': 'no signature generation in this dormant contract task',
|
|
194
|
+
'no-blockhash-generation': 'no blockhash generation in this dormant contract task',
|
|
195
|
+
'no-transaction-action': 'no transaction creation, simulation, submission, or confirmation in this dormant contract task',
|
|
196
|
+
'no-runtime-artifacts': 'no token balance, mint address, validator state, or local ledger artifact generated by this contract',
|
|
197
|
+
};
|
|
198
|
+
export function validateBrowserWalletApprovalRecord(input, options = {}) {
|
|
199
|
+
const errors = [];
|
|
200
|
+
const warnings = [
|
|
201
|
+
'Validation is offline and default-off: it does not install extensions, inspect wallets, request faucet tokens, sign, simulate, submit, or observe transactions.',
|
|
202
|
+
];
|
|
203
|
+
if (!isPlainObject(input)) {
|
|
204
|
+
return { ok: false, errors: [error('malformed_browser_wallet_approval', '$', 'approval record must be an object')], warnings };
|
|
205
|
+
}
|
|
206
|
+
const record = input;
|
|
207
|
+
rejectUnknownKeys(record, '$', APPROVAL_TOP_LEVEL_KEYS, errors);
|
|
208
|
+
requireLiteral(record.schemaVersion, BROWSER_WALLET_APPROVAL_SCHEMA_VERSION, '$.schemaVersion', 'invalid_browser_wallet_approval_schema', errors);
|
|
209
|
+
requireLiteral(record.status, 'approved', '$.status', 'malformed_browser_wallet_approval', errors);
|
|
210
|
+
requireExactString(record.approvalId, '$.approvalId', errors);
|
|
211
|
+
requireExactString(record.approver, '$.approver', errors);
|
|
212
|
+
const approvedAtMs = validateTimestamp(record.approvedAt, '$.approvedAt', errors);
|
|
213
|
+
const expiresAtMs = validateTimestamp(record.expiresAt, '$.expiresAt', errors);
|
|
214
|
+
const nowMs = normalizeNow(options.now);
|
|
215
|
+
if (nowMs === undefined) {
|
|
216
|
+
errors.push(error('malformed_browser_wallet_approval', '$', 'the supplied evaluation instant must be one real canonical UTC ISO-8601 calendar instant'));
|
|
217
|
+
}
|
|
218
|
+
if (nowMs !== undefined && expiresAtMs !== undefined && expiresAtMs <= nowMs) {
|
|
219
|
+
errors.push(error('expired_browser_wallet_approval', '$.expiresAt', 'approval record is expired'));
|
|
220
|
+
}
|
|
221
|
+
if (nowMs !== undefined && approvedAtMs !== undefined && approvedAtMs > nowMs) {
|
|
222
|
+
errors.push(error('contradictory_browser_wallet_approval', '$.approvedAt', 'approval record is not valid before approvedAt'));
|
|
223
|
+
}
|
|
224
|
+
if (approvedAtMs !== undefined && expiresAtMs !== undefined && approvedAtMs >= expiresAtMs) {
|
|
225
|
+
errors.push(error('contradictory_browser_wallet_approval', '$.approvedAt', 'approvedAt must be earlier than expiresAt'));
|
|
226
|
+
}
|
|
227
|
+
validateUsage(record.usage, '$.usage', errors);
|
|
228
|
+
const providerSourceRetrievedAtMs = validateProvider(record.provider, '$.provider', errors);
|
|
229
|
+
if (providerSourceRetrievedAtMs !== undefined && approvedAtMs !== undefined && providerSourceRetrievedAtMs > approvedAtMs) {
|
|
230
|
+
errors.push(error('contradictory_browser_wallet_approval', '$.provider.source.retrievedAt', 'provider source retrievedAt must be no later than approvedAt'));
|
|
231
|
+
}
|
|
232
|
+
validateBrowserProfile(record.browserProfile, record.provider?.name, '$.browserProfile', errors);
|
|
233
|
+
validateWallet(record.wallet, '$.wallet', errors);
|
|
234
|
+
validateNetwork(record.network, options.trustedDevnetRpcEndpoints, '$.network', errors);
|
|
235
|
+
validateUiAction(record.uiAction, '$.uiAction', errors);
|
|
236
|
+
validatePrograms(record.programs, options.trustedDevnetProgramIds, '$.programs', errors);
|
|
237
|
+
validateFunding(record.funding, '$.funding', errors);
|
|
238
|
+
validateCaps(record.caps, '$.caps', errors);
|
|
239
|
+
validateRetryPolicy(record.retryPolicy, '$.retryPolicy', errors);
|
|
240
|
+
validateAsset(record.asset, record.uiAction?.action, Boolean(options.allowFuturePartnerConfirmedAuddDevnet), options.trustedFutureAuddDevnetIdentity, '$.asset', errors);
|
|
241
|
+
validateEvidence(record.evidence, '$.evidence', errors);
|
|
242
|
+
validateRollback(record.rollback, '$.rollback', errors);
|
|
243
|
+
validateBoundaries(record.boundaries, '$.boundaries', errors);
|
|
244
|
+
if (record.network?.rapAlias === 'solana-devnet' && record.network?.caip2 !== SOLANA_DEVNET_CAIP2) {
|
|
245
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.network.caip2', 'network CAIP-2 identity must match the canonical Solana Devnet reference'));
|
|
246
|
+
}
|
|
247
|
+
if (record.uiAction?.action === 'x402-devnet-usdc-payment' && record.asset?.symbol !== 'USDC') {
|
|
248
|
+
errors.push(error('contradictory_browser_wallet_approval', '$.uiAction.action', 'x402 Devnet USDC action must approve USDC only'));
|
|
249
|
+
}
|
|
250
|
+
return errors.length === 0 ? { ok: true, record, warnings } : { ok: false, errors: uniqueErrors(errors), warnings };
|
|
251
|
+
}
|
|
252
|
+
export function validateBrowserWalletTier1LocalHarnessContract(input) {
|
|
253
|
+
const errors = [];
|
|
254
|
+
const warnings = [
|
|
255
|
+
'Tier 1 local browser harness validation is a dormant contract check only: it creates no mint, keypair, signature, blockhash, transaction, validator state, or token balance.',
|
|
256
|
+
];
|
|
257
|
+
if (!isPlainObject(input)) {
|
|
258
|
+
return { ok: false, errors: [error('malformed_browser_wallet_approval', '$', 'Tier 1 contract must be an object')], warnings };
|
|
259
|
+
}
|
|
260
|
+
const contract = input;
|
|
261
|
+
rejectUnknownKeys(contract, '$', TIER1_CONTRACT_KEYS, errors);
|
|
262
|
+
requireLiteral(contract.schemaVersion, BROWSER_WALLET_TIER1_LOCAL_HARNESS_SCHEMA_VERSION, '$.schemaVersion', 'invalid_browser_wallet_approval_schema', errors);
|
|
263
|
+
requireLiteral(contract.enabledByDefault, false, '$.enabledByDefault', 'production_browser_wallet_rejected', errors);
|
|
264
|
+
requireLiteral(contract.executionState, 'dormant-contract-only', '$.executionState', 'production_browser_wallet_rejected', errors);
|
|
265
|
+
if (!isPlainObject(contract.network)) {
|
|
266
|
+
errors.push(error('missing_browser_wallet_approval_field', '$.network', 'Tier 1 network contract is required'));
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
rejectUnknownKeys(contract.network, '$.network', TIER1_NETWORK_KEYS, errors);
|
|
270
|
+
requireLiteral(contract.network.rapAlias, 'local-surfpool', '$.network.rapAlias', 'non_canonical_browser_wallet_identity', errors);
|
|
271
|
+
requireLiteral(contract.network.caip2, null, '$.network.caip2', 'non_canonical_browser_wallet_identity', errors);
|
|
272
|
+
requireLiteral(contract.network.rpcHttp, LOOPBACK_DYNAMIC_SENTINEL, '$.network.rpcHttp', 'non_canonical_browser_wallet_identity', errors);
|
|
273
|
+
requireLiteral(contract.network.rpcWs, LOOPBACK_DYNAMIC_SENTINEL, '$.network.rpcWs', 'non_canonical_browser_wallet_identity', errors);
|
|
274
|
+
requireLiteral(contract.network.dynamicPorts, true, '$.network.dynamicPorts', 'non_canonical_browser_wallet_identity', errors);
|
|
275
|
+
requireLiteral(contract.network.loopbackOnly, true, '$.network.loopbackOnly', 'mainnet_browser_wallet_rejected', errors);
|
|
276
|
+
requireLiteral(contract.network.remoteDatasource, false, '$.network.remoteDatasource', 'mainnet_browser_wallet_rejected', errors);
|
|
277
|
+
requireLiteral(contract.network.startupAirdrop, false, '$.network.startupAirdrop', 'ai_faucet_rejected', errors);
|
|
278
|
+
requireLiteral(contract.network.transactionModeBlockProduction, true, '$.network.transactionModeBlockProduction', 'non_canonical_browser_wallet_identity', errors);
|
|
279
|
+
}
|
|
280
|
+
if (!isPlainObject(contract.browserIdentity)) {
|
|
281
|
+
errors.push(error('missing_browser_wallet_approval_field', '$.browserIdentity', 'Tier 1 browser identity contract is required'));
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
rejectUnknownKeys(contract.browserIdentity, '$.browserIdentity', TIER1_BROWSER_IDENTITY_KEYS, errors);
|
|
285
|
+
requireLiteral(contract.browserIdentity.kind, 'disposable-local-browser-identity', '$.browserIdentity.kind', 'non_canonical_browser_wallet_identity', errors);
|
|
286
|
+
requireLiteral(contract.browserIdentity.scope, 'per-run', '$.browserIdentity.scope', 'non_single_use_browser_wallet_approval', errors);
|
|
287
|
+
requireLiteral(contract.browserIdentity.publicKeyOnly, true, '$.browserIdentity.publicKeyOnly', 'secret_material_rejected', errors);
|
|
288
|
+
requireLiteral(contract.browserIdentity.productionSeedImported, false, '$.browserIdentity.productionSeedImported', 'secret_material_rejected', errors);
|
|
289
|
+
requireLiteral(contract.browserIdentity.secretStorage, 'none-committed-public-prefixed-local-only-if-temporarily-used', '$.browserIdentity.secretStorage', 'secret_material_rejected', errors);
|
|
290
|
+
requireLiteral(contract.browserIdentity.profileIsolation, 'dedicated-disposable', '$.browserIdentity.profileIsolation', 'non_canonical_browser_wallet_identity', errors);
|
|
291
|
+
}
|
|
292
|
+
if (!isPlainObject(contract.asset)) {
|
|
293
|
+
errors.push(error('missing_browser_wallet_approval_field', '$.asset', 'Tier 1 asset contract is required'));
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
rejectUnknownKeys(contract.asset, '$.asset', TIER1_ASSET_KEYS, errors);
|
|
297
|
+
if (contract.asset.label !== 'AUDD_TEST' && contract.asset.label !== 'LOCAL_AUDD_TEST') {
|
|
298
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.asset.label', 'Tier 1 local mint label must be AUDD_TEST or LOCAL_AUDD_TEST'));
|
|
299
|
+
}
|
|
300
|
+
requireLiteral(contract.asset.environment, 'local-test-mint', '$.asset.environment', 'non_canonical_browser_wallet_identity', errors);
|
|
301
|
+
requireLiteral(contract.asset.mint, null, '$.asset.mint', 'non_canonical_browser_wallet_identity', errors);
|
|
302
|
+
requireLiteral(contract.asset.mintSource, 'per-run-generated-not-in-this-contract', '$.asset.mintSource', 'non_canonical_browser_wallet_identity', errors);
|
|
303
|
+
requireLiteral(contract.asset.tokenProgram, SPL_TOKEN_PROGRAM_ID, '$.asset.tokenProgram', 'non_canonical_browser_wallet_identity', errors);
|
|
304
|
+
requireLiteral(contract.asset.decimals, AUDD_DECIMALS, '$.asset.decimals', 'non_canonical_browser_wallet_identity', errors);
|
|
305
|
+
requireLiteral(contract.asset.grantEligibility, 'non_eligible', '$.asset.grantEligibility', 'non_canonical_browser_wallet_identity', errors);
|
|
306
|
+
}
|
|
307
|
+
if (!isPlainObject(contract.observation)) {
|
|
308
|
+
errors.push(error('missing_browser_wallet_approval_field', '$.observation', 'Tier 1 observation contract is required'));
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
rejectUnknownKeys(contract.observation, '$.observation', TIER1_OBSERVATION_KEYS, errors);
|
|
312
|
+
requireLiteral(contract.observation.instruction, 'TransferChecked', '$.observation.instruction', 'non_canonical_browser_wallet_identity', errors);
|
|
313
|
+
requireLiteral(contract.observation.source, 'local-validator', '$.observation.source', 'non_canonical_browser_wallet_identity', errors);
|
|
314
|
+
requireLiteral(contract.observation.exactTransferChecked, true, '$.observation.exactTransferChecked', 'non_canonical_browser_wallet_identity', errors);
|
|
315
|
+
requireLiteral(contract.observation.exactlyOneMatchingTransfer, true, '$.observation.exactlyOneMatchingTransfer', 'non_canonical_browser_wallet_identity', errors);
|
|
316
|
+
requireLiteral(contract.observation.expectedTermsAreObservedEvidence, false, '$.observation.expectedTermsAreObservedEvidence', 'settlement_finality_rejected', errors);
|
|
317
|
+
if (!hasExactStringSet(contract.observation.requiredFields, TIER1_REQUIRED_OBSERVATION_FIELDS)) {
|
|
318
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.observation.requiredFields', 'TransferChecked observation fields must exactly match the closed required-field identifiers without extras or duplicates'));
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (!isPlainObject(contract.railIdentity)) {
|
|
322
|
+
errors.push(error('missing_browser_wallet_approval_field', '$.railIdentity', 'Tier 1 rail identity contract is required'));
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
rejectUnknownKeys(contract.railIdentity, '$.railIdentity', TIER1_RAIL_IDENTITY_KEYS, errors);
|
|
326
|
+
requireLiteral(contract.railIdentity.railEnvironment, 'local-test-mint', '$.railIdentity.railEnvironment', 'non_canonical_browser_wallet_identity', errors);
|
|
327
|
+
requireLiteral(contract.railIdentity.networkAlias, 'local-surfpool', '$.railIdentity.networkAlias', 'non_canonical_browser_wallet_identity', errors);
|
|
328
|
+
requireLiteral(contract.railIdentity.caip2, null, '$.railIdentity.caip2', 'non_canonical_browser_wallet_identity', errors);
|
|
329
|
+
if (contract.railIdentity.asset !== 'AUDD_TEST' && contract.railIdentity.asset !== 'LOCAL_AUDD_TEST') {
|
|
330
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.railIdentity.asset', 'Tier 1 rail identity must use the local test AUDD label'));
|
|
331
|
+
}
|
|
332
|
+
requireLiteral(contract.railIdentity.tokenProgram, SPL_TOKEN_PROGRAM_ID, '$.railIdentity.tokenProgram', 'non_canonical_browser_wallet_identity', errors);
|
|
333
|
+
requireLiteral(contract.railIdentity.decimals, AUDD_DECIMALS, '$.railIdentity.decimals', 'non_canonical_browser_wallet_identity', errors);
|
|
334
|
+
requireLiteral(contract.railIdentity.observationSource, 'local-validator', '$.railIdentity.observationSource', 'non_canonical_browser_wallet_identity', errors);
|
|
335
|
+
requireLiteral(contract.railIdentity.grantEligibility, 'non_eligible', '$.railIdentity.grantEligibility', 'non_canonical_browser_wallet_identity', errors);
|
|
336
|
+
}
|
|
337
|
+
if (!isPlainObject(contract.cleanup)) {
|
|
338
|
+
errors.push(error('missing_browser_wallet_approval_field', '$.cleanup', 'Tier 1 cleanup contract is required'));
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
rejectUnknownKeys(contract.cleanup, '$.cleanup', TIER1_CLEANUP_KEYS, errors);
|
|
342
|
+
requireLiteral(contract.cleanup.disconnectRevoke, true, '$.cleanup.disconnectRevoke', 'custody_browser_wallet_rejected', errors);
|
|
343
|
+
requireLiteral(contract.cleanup.deleteBrowserProfile, true, '$.cleanup.deleteBrowserProfile', 'custody_browser_wallet_rejected', errors);
|
|
344
|
+
requireLiteral(contract.cleanup.deleteLocalState, true, '$.cleanup.deleteLocalState', 'custody_browser_wallet_rejected', errors);
|
|
345
|
+
requireLiteral(contract.cleanup.deleteKeyMaterial, true, '$.cleanup.deleteKeyMaterial', 'secret_material_rejected', errors);
|
|
346
|
+
requireLiteral(contract.cleanup.redactEvidence, true, '$.cleanup.redactEvidence', 'secret_material_rejected', errors);
|
|
347
|
+
requireLiteral(contract.cleanup.incidentSuspend, true, '$.cleanup.incidentSuspend', 'production_browser_wallet_rejected', errors);
|
|
348
|
+
requireLiteral(contract.cleanup.freshApprovalRequired, true, '$.cleanup.freshApprovalRequired', 'non_single_use_browser_wallet_approval', errors);
|
|
349
|
+
}
|
|
350
|
+
if (!hasExactStringSet(contract.prohibitedActions, TIER1_PROHIBITED_ACTION_IDS)) {
|
|
351
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.prohibitedActions', 'Tier 1 prohibited actions must exactly match the closed action identifiers without extras or duplicates'));
|
|
352
|
+
}
|
|
353
|
+
return errors.length === 0 ? { ok: true, record: contract, warnings } : { ok: false, errors: uniqueErrors(errors), warnings };
|
|
354
|
+
}
|
|
355
|
+
export function validateBrowserWalletIdentityCopyClaims(input) {
|
|
356
|
+
const errors = [];
|
|
357
|
+
const warnings = [
|
|
358
|
+
'Identity/copy validation is deterministic and offline: it inspects supplied evidence rows/copy only and never treats expected terms as observed evidence.',
|
|
359
|
+
];
|
|
360
|
+
if (!isPlainObject(input)) {
|
|
361
|
+
return { ok: false, errors: [error('malformed_browser_wallet_approval', '$', 'identity/copy guard input must be an object')], warnings };
|
|
362
|
+
}
|
|
363
|
+
const row = input;
|
|
364
|
+
rejectUnknownKeys(row, '$', COPY_GUARD_KEYS, errors);
|
|
365
|
+
requireLiteral(row.schemaVersion, BROWSER_WALLET_IDENTITY_COPY_GUARD_SCHEMA_VERSION, '$.schemaVersion', 'invalid_browser_wallet_approval_schema', errors);
|
|
366
|
+
const railEnvironment = typeof row.railEnvironment === 'string' ? row.railEnvironment : undefined;
|
|
367
|
+
const observationSource = typeof row.observationSource === 'string' ? row.observationSource : undefined;
|
|
368
|
+
if (railEnvironment === undefined) {
|
|
369
|
+
errors.push(error('malformed_browser_wallet_approval', '$.railEnvironment', 'rail environment must be one exact string value'));
|
|
370
|
+
}
|
|
371
|
+
else if (!NON_LIVE_COPY_GUARD_RAIL_ENVIRONMENTS.has(railEnvironment)) {
|
|
372
|
+
errors.push(error(isPaymentEnvironment(railEnvironment) ? 'mainnet_browser_wallet_rejected' : 'non_canonical_browser_wallet_identity', '$.railEnvironment', 'browser-wallet safety rows are non-live only: railEnvironment must be deterministic-fixture, local-test-mint, or devnet-unverified'));
|
|
373
|
+
}
|
|
374
|
+
requireExactString(row.assetLabel, '$.assetLabel', errors);
|
|
375
|
+
validateCopyGuardAssetLabel(row.assetLabel, railEnvironment, errors);
|
|
376
|
+
requireExactString(row.networkAlias, '$.networkAlias', errors);
|
|
377
|
+
validateOptionalExactString(row.mint, '$.mint', errors);
|
|
378
|
+
validateOptionalExactString(row.caip2, '$.caip2', errors);
|
|
379
|
+
validateCopyGuardRailIdentity(row, errors);
|
|
380
|
+
if (row.caip2 === SOLANA_MAINNET_BETA_CAIP2) {
|
|
381
|
+
errors.push(error('mainnet_browser_wallet_rejected', '$.caip2', 'browser-wallet safety rows must not name the Solana mainnet-beta chain identity'));
|
|
382
|
+
}
|
|
383
|
+
if (observationSource === undefined) {
|
|
384
|
+
errors.push(error('malformed_browser_wallet_approval', '$.observationSource', 'observation source must be one exact string value'));
|
|
385
|
+
}
|
|
386
|
+
else if (!['expected-only', 'parsed-transaction-fixture', 'local-validator', 'parsed-rpc-transaction'].includes(observationSource)) {
|
|
387
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.observationSource', 'observation source is not canonical'));
|
|
388
|
+
}
|
|
389
|
+
const railObservationCeiling = railEnvironment === undefined ? undefined : RAIL_MAX_OBSERVATION_SOURCE[railEnvironment];
|
|
390
|
+
if (railObservationCeiling !== undefined && observationSource !== undefined
|
|
391
|
+
&& (OBSERVATION_SOURCE_RANK[observationSource] ?? Number.MAX_SAFE_INTEGER) > OBSERVATION_SOURCE_RANK[railObservationCeiling]) {
|
|
392
|
+
errors.push(error('settlement_finality_rejected', '$.observationSource', 'observation source must not exceed the evidence the rail environment can produce'));
|
|
393
|
+
}
|
|
394
|
+
if (!isPaymentEligibility(row.grantEligibility)) {
|
|
395
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.grantEligibility', 'grant eligibility label is not canonical'));
|
|
396
|
+
}
|
|
397
|
+
validateCopyNested(row.x402Export, '$.x402Export', X402_EXPORT_KEYS, errors);
|
|
398
|
+
validateCopyNested(row.policy, '$.policy', POLICY_KEYS, errors);
|
|
399
|
+
validateCopyNested(row.receipt, '$.receipt', RECEIPT_KEYS, errors);
|
|
400
|
+
validateCopyNested(row.copy, '$.copy', COPY_KEYS, errors);
|
|
401
|
+
validateCopyGuardNestedShapes(row, errors);
|
|
402
|
+
if (row.x402Export)
|
|
403
|
+
validateCanonicalX402Export(row, errors);
|
|
404
|
+
if (row.policy) {
|
|
405
|
+
if (row.policy.grantEligibility !== row.grantEligibility) {
|
|
406
|
+
errors.push(error('contradictory_browser_wallet_approval', '$.policy.grantEligibility', 'policy grant eligibility must match the row label'));
|
|
407
|
+
}
|
|
408
|
+
if (row.policy.controlledLive) {
|
|
409
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.policy.controlledLive', 'browser-wallet safety rows must not carry a controlled-live policy claim'));
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
if (row.receipt)
|
|
413
|
+
validateReceiptBoundary(row, errors);
|
|
414
|
+
if (row.grantEligibility !== 'non_eligible') {
|
|
415
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.grantEligibility', 'browser-wallet safety rows must be non_eligible'));
|
|
416
|
+
}
|
|
417
|
+
if (String(row.assetLabel).toUpperCase() === AUDD_ASSET && row.railEnvironment !== 'deterministic-fixture' && row.railEnvironment !== 'devnet-unverified') {
|
|
418
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.assetLabel', 'local non-live rows must use AUDD_TEST or LOCAL_AUDD_TEST, not official AUDD'));
|
|
419
|
+
}
|
|
420
|
+
if (row.railEnvironment === 'local-test-mint' && !['AUDD_TEST', 'LOCAL_AUDD_TEST'].includes(String(row.assetLabel))) {
|
|
421
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.assetLabel', 'local-test-mint rows must use the local test AUDD label'));
|
|
422
|
+
}
|
|
423
|
+
if (row.railEnvironment === 'devnet-unverified' && String(row.assetLabel).toUpperCase() === AUDD_ASSET) {
|
|
424
|
+
errors.push(error('official_audd_devnet_unavailable', '$.assetLabel', 'official AUDD Devnet evidence is unavailable without partner confirmation and separate approval'));
|
|
425
|
+
}
|
|
426
|
+
if (typeof row.mint === 'string' && REJECTED_MAINNET_MINTS.has(row.mint)) {
|
|
427
|
+
errors.push(error('mainnet_browser_wallet_rejected', '$.mint', 'browser-wallet safety rows must not name an official Solana mainnet mint'));
|
|
428
|
+
}
|
|
429
|
+
if (row.railEnvironment === 'local-test-mint' && row.mint === AUDD_DETERMINISTIC_FIXTURE_MINT) {
|
|
430
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.mint', 'local test mint rows must not reuse the deterministic AUDD fixture mint'));
|
|
431
|
+
}
|
|
432
|
+
if (row.receipt?.claim === 'observed-settlement') {
|
|
433
|
+
errors.push(error('settlement_finality_rejected', '$.receipt', 'browser-wallet safety rows must not claim observed settlement'));
|
|
434
|
+
}
|
|
435
|
+
const copyText = collectCopyText(row.copy).join('\n');
|
|
436
|
+
if (copyText) {
|
|
437
|
+
validateUnambiguousCopyText(copyText, errors);
|
|
438
|
+
const forbidden = forbiddenCopyMatches(copyText.normalize('NFKC'));
|
|
439
|
+
for (const match of forbidden) {
|
|
440
|
+
errors.push(error(match.code, '$.copy', match.message));
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return errors.length === 0 ? { ok: true, record: row, warnings } : { ok: false, errors: uniqueErrors(errors), warnings };
|
|
444
|
+
}
|
|
445
|
+
export const DORMANT_TIER1_LOCAL_BROWSER_HARNESS_CONTRACT = {
|
|
446
|
+
schemaVersion: BROWSER_WALLET_TIER1_LOCAL_HARNESS_SCHEMA_VERSION,
|
|
447
|
+
enabledByDefault: false,
|
|
448
|
+
executionState: 'dormant-contract-only',
|
|
449
|
+
network: {
|
|
450
|
+
rapAlias: 'local-surfpool',
|
|
451
|
+
caip2: null,
|
|
452
|
+
rpcHttp: LOOPBACK_DYNAMIC_SENTINEL,
|
|
453
|
+
rpcWs: LOOPBACK_DYNAMIC_SENTINEL,
|
|
454
|
+
dynamicPorts: true,
|
|
455
|
+
loopbackOnly: true,
|
|
456
|
+
remoteDatasource: false,
|
|
457
|
+
startupAirdrop: false,
|
|
458
|
+
transactionModeBlockProduction: true,
|
|
459
|
+
},
|
|
460
|
+
browserIdentity: {
|
|
461
|
+
kind: 'disposable-local-browser-identity',
|
|
462
|
+
scope: 'per-run',
|
|
463
|
+
publicKeyOnly: true,
|
|
464
|
+
productionSeedImported: false,
|
|
465
|
+
secretStorage: 'none-committed-public-prefixed-local-only-if-temporarily-used',
|
|
466
|
+
profileIsolation: 'dedicated-disposable',
|
|
467
|
+
},
|
|
468
|
+
asset: {
|
|
469
|
+
label: 'AUDD_TEST',
|
|
470
|
+
environment: 'local-test-mint',
|
|
471
|
+
mint: null,
|
|
472
|
+
mintSource: 'per-run-generated-not-in-this-contract',
|
|
473
|
+
tokenProgram: SPL_TOKEN_PROGRAM_ID,
|
|
474
|
+
decimals: AUDD_DECIMALS,
|
|
475
|
+
grantEligibility: 'non_eligible',
|
|
476
|
+
},
|
|
477
|
+
observation: {
|
|
478
|
+
instruction: 'TransferChecked',
|
|
479
|
+
source: 'local-validator',
|
|
480
|
+
exactTransferChecked: true,
|
|
481
|
+
exactlyOneMatchingTransfer: true,
|
|
482
|
+
requiredFields: ['mint', 'tokenProgram', 'decimals', 'payee', 'destinationOwner', 'amount', 'memo', 'signature', 'instructionIndex'],
|
|
483
|
+
expectedTermsAreObservedEvidence: false,
|
|
484
|
+
},
|
|
485
|
+
railIdentity: {
|
|
486
|
+
railEnvironment: 'local-test-mint',
|
|
487
|
+
networkAlias: 'local-surfpool',
|
|
488
|
+
caip2: null,
|
|
489
|
+
asset: 'AUDD_TEST',
|
|
490
|
+
tokenProgram: SPL_TOKEN_PROGRAM_ID,
|
|
491
|
+
decimals: AUDD_DECIMALS,
|
|
492
|
+
observationSource: 'local-validator',
|
|
493
|
+
grantEligibility: 'non_eligible',
|
|
494
|
+
},
|
|
495
|
+
cleanup: {
|
|
496
|
+
disconnectRevoke: true,
|
|
497
|
+
deleteBrowserProfile: true,
|
|
498
|
+
deleteLocalState: true,
|
|
499
|
+
deleteKeyMaterial: true,
|
|
500
|
+
redactEvidence: true,
|
|
501
|
+
incidentSuspend: true,
|
|
502
|
+
freshApprovalRequired: true,
|
|
503
|
+
},
|
|
504
|
+
prohibitedActions: [...TIER1_PROHIBITED_ACTION_IDS],
|
|
505
|
+
};
|
|
506
|
+
function validateUsage(value, path, errors) {
|
|
507
|
+
if (!isPlainObject(value)) {
|
|
508
|
+
errors.push(error('missing_browser_wallet_approval_field', path, 'single-use metadata is required'));
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
rejectUnknownKeys(value, path, USAGE_KEYS, errors);
|
|
512
|
+
requireLiteral(value.scope, 'single-use', `${path}.scope`, 'non_single_use_browser_wallet_approval', errors);
|
|
513
|
+
requireLiteral(value.approvedUseCount, 1, `${path}.approvedUseCount`, 'non_single_use_browser_wallet_approval', errors);
|
|
514
|
+
requireLiteral(value.consumedUseCount, 0, `${path}.consumedUseCount`, 'non_single_use_browser_wallet_approval', errors);
|
|
515
|
+
requireExactString(value.nonce, `${path}.nonce`, errors);
|
|
516
|
+
requireLiteral(value.reusePolicy, 'fresh-approval-required', `${path}.reusePolicy`, 'non_single_use_browser_wallet_approval', errors);
|
|
517
|
+
}
|
|
518
|
+
function validateProvider(value, path, errors) {
|
|
519
|
+
if (!isPlainObject(value)) {
|
|
520
|
+
errors.push(error('missing_browser_wallet_approval_field', path, 'wallet provider metadata is required'));
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
rejectUnknownKeys(value, path, PROVIDER_KEYS, errors);
|
|
524
|
+
if (typeof value.name !== 'string' || !SUPPORTED_DEVNET_BROWSER_WALLET_PROVIDERS.has(value.name)) {
|
|
525
|
+
errors.push(error('unknown_browser_wallet_provider', `${path}.name`, 'provider is not in the current Devnet browser-wallet allowlist'));
|
|
526
|
+
}
|
|
527
|
+
requireExactString(value.version, `${path}.version`, errors);
|
|
528
|
+
if (value.devnetSupport !== 'verified-official-docs') {
|
|
529
|
+
errors.push(error('non_canonical_browser_wallet_identity', `${path}.devnetSupport`, 'provider Devnet support must be verified from official docs for this browser build'));
|
|
530
|
+
}
|
|
531
|
+
if (!isPlainObject(value.source)) {
|
|
532
|
+
errors.push(error('missing_browser_wallet_approval_field', `${path}.source`, 'provider source is required'));
|
|
533
|
+
return undefined;
|
|
534
|
+
}
|
|
535
|
+
rejectUnknownKeys(value.source, `${path}.source`, SOURCE_KEYS, errors);
|
|
536
|
+
if (typeof value.source.kind !== 'string' || !['official-docs', 'browser-extension-store', 'operator-ui'].includes(value.source.kind)) {
|
|
537
|
+
errors.push(error('non_canonical_browser_wallet_identity', `${path}.source.kind`, 'provider source kind is not canonical'));
|
|
538
|
+
}
|
|
539
|
+
requireHttpsUrl(value.source.url, `${path}.source.url`, errors);
|
|
540
|
+
const retrievedAtMs = validateTimestamp(value.source.retrievedAt, `${path}.source.retrievedAt`, errors);
|
|
541
|
+
validateOptionalHash(value.source.sha256, `${path}.source.sha256`, errors);
|
|
542
|
+
return retrievedAtMs;
|
|
543
|
+
}
|
|
544
|
+
function validateBrowserProfile(value, providerName, path, errors) {
|
|
545
|
+
if (!isPlainObject(value)) {
|
|
546
|
+
errors.push(error('missing_browser_wallet_approval_field', path, 'isolated browser profile metadata is required'));
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
rejectUnknownKeys(value, path, BROWSER_PROFILE_KEYS, errors);
|
|
550
|
+
if (typeof value.id !== 'string' || !value.id.startsWith('browser-profile:') || hasBroadString(value.id) || value.id.includes('..')) {
|
|
551
|
+
errors.push(error('non_canonical_browser_wallet_identity', `${path}.id`, 'browser profile id must be a dedicated non-broad identifier'));
|
|
552
|
+
}
|
|
553
|
+
requireLiteral(value.isolation, 'dedicated-disposable', `${path}.isolation`, 'non_canonical_browser_wallet_identity', errors);
|
|
554
|
+
requireLiteral(value.syncDisabled, true, `${path}.syncDisabled`, 'custody_browser_wallet_rejected', errors);
|
|
555
|
+
requireLiteral(value.primaryProfile, false, `${path}.primaryProfile`, 'custody_browser_wallet_rejected', errors);
|
|
556
|
+
requireLiteral(value.onlyApprovedExtension, providerName, `${path}.onlyApprovedExtension`, 'contradictory_browser_wallet_approval', errors);
|
|
557
|
+
requireLiteral(value.automatedExtensionInstall, false, `${path}.automatedExtensionInstall`, 'production_browser_wallet_rejected', errors);
|
|
558
|
+
requireLiteral(value.deleteAfterRun, true, `${path}.deleteAfterRun`, 'custody_browser_wallet_rejected', errors);
|
|
559
|
+
}
|
|
560
|
+
function validateWallet(value, path, errors) {
|
|
561
|
+
if (!isPlainObject(value)) {
|
|
562
|
+
errors.push(error('missing_browser_wallet_approval_field', path, 'wallet public identity metadata is required'));
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
rejectUnknownKeys(value, path, WALLET_KEYS, errors);
|
|
566
|
+
if (!isValidSolanaPublicKey(value.publicKey) || value.publicKey === DEFAULT_PLAYWRIGHT_FIXTURE_PUBLIC_KEY) {
|
|
567
|
+
errors.push(error('non_canonical_browser_wallet_identity', `${path}.publicKey`, 'wallet must provide one exact non-fixture Solana public key'));
|
|
568
|
+
}
|
|
569
|
+
requireLiteral(value.secretMaterial, false, `${path}.secretMaterial`, 'secret_material_rejected', errors);
|
|
570
|
+
requireLiteral(value.productionSeedImported, false, `${path}.productionSeedImported`, 'secret_material_rejected', errors);
|
|
571
|
+
requireLiteral(value.custody, 'human-controlled-devnet-only', `${path}.custody`, 'custody_browser_wallet_rejected', errors);
|
|
572
|
+
}
|
|
573
|
+
function validateNetwork(value, trustedDevnetRpcEndpoints, path, errors) {
|
|
574
|
+
if (!isPlainObject(value)) {
|
|
575
|
+
errors.push(error('missing_browser_wallet_approval_field', path, 'network identity is required'));
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
rejectUnknownKeys(value, path, NETWORK_KEYS, errors);
|
|
579
|
+
if (value.rapAlias === 'solana-mainnet-beta' || value.caip2 === SOLANA_MAINNET_BETA_CAIP2 || value.cluster === 'mainnet-beta') {
|
|
580
|
+
errors.push(error('mainnet_browser_wallet_rejected', path, 'mainnet browser-wallet approvals are not supported'));
|
|
581
|
+
}
|
|
582
|
+
requireLiteral(value.rapAlias, 'solana-devnet', `${path}.rapAlias`, 'non_canonical_browser_wallet_identity', errors);
|
|
583
|
+
requireLiteral(value.caip2, SOLANA_DEVNET_CAIP2, `${path}.caip2`, 'non_canonical_browser_wallet_identity', errors);
|
|
584
|
+
requireLiteral(value.cluster, 'devnet', `${path}.cluster`, 'non_canonical_browser_wallet_identity', errors);
|
|
585
|
+
requireHttpsUrl(value.rpcHttp, `${path}.rpcHttp`, errors, false);
|
|
586
|
+
validateOptionalWssUrl(value.rpcWs, `${path}.rpcWs`, errors, false);
|
|
587
|
+
if (!trustedDevnetRpcEndpoints) {
|
|
588
|
+
errors.push(error('missing_browser_wallet_approval_field', `${path}.rpcHttp`, 'trusted Devnet RPC identity context is required'));
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
requireLiteral(value.rpcHttp, trustedDevnetRpcEndpoints.rpcHttp, `${path}.rpcHttp`, 'non_canonical_browser_wallet_identity', errors);
|
|
592
|
+
requireLiteral(value.rpcWs ?? null, trustedDevnetRpcEndpoints.rpcWs ?? null, `${path}.rpcWs`, 'non_canonical_browser_wallet_identity', errors);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
function validateUiAction(value, path, errors) {
|
|
596
|
+
if (!isPlainObject(value)) {
|
|
597
|
+
errors.push(error('missing_browser_wallet_approval_field', path, 'exact UI action is required'));
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
rejectUnknownKeys(value, path, UI_ACTION_KEYS, errors);
|
|
601
|
+
if (typeof value.route !== 'string' || !value.route.startsWith('/') || hasBroadString(value.route) || value.route.includes('..')) {
|
|
602
|
+
errors.push(error('overly_broad_browser_wallet_approval', `${path}.route`, 'UI route must be one exact non-broad route'));
|
|
603
|
+
}
|
|
604
|
+
if (typeof value.action !== 'string' || !BROWSER_WALLET_ALLOWED_ACTIONS.has(value.action)) {
|
|
605
|
+
errors.push(error('non_canonical_browser_wallet_identity', `${path}.action`, 'UI action is not in the browser-wallet Devnet allowlist'));
|
|
606
|
+
}
|
|
607
|
+
requireLiteral(value.executionMode, 'manual-human-browser-wallet', `${path}.executionMode`, 'production_browser_wallet_rejected', errors);
|
|
608
|
+
requireLiteral(value.defaultOff, true, `${path}.defaultOff`, 'production_browser_wallet_rejected', errors);
|
|
609
|
+
requireLiteral(value.exactOnce, true, `${path}.exactOnce`, 'non_single_use_browser_wallet_approval', errors);
|
|
610
|
+
requireLiteral(value.devnetActionAvailableByDefault, false, `${path}.devnetActionAvailableByDefault`, 'production_browser_wallet_rejected', errors);
|
|
611
|
+
if (value.action === 'register-agent' && value.route !== '/register') {
|
|
612
|
+
errors.push(error('contradictory_browser_wallet_approval', `${path}.route`, 'register-agent action must target the /register route'));
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
function validatePrograms(value, trustedDevnetProgramIds, path, errors) {
|
|
616
|
+
if (!isPlainObject(value)) {
|
|
617
|
+
errors.push(error('missing_browser_wallet_approval_field', path, 'program identity metadata is required'));
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
rejectUnknownKeys(value, path, PROGRAMS_KEYS, errors);
|
|
621
|
+
requireLiteral(value.target, 'legacy-anchor', `${path}.target`, 'production_browser_wallet_rejected', errors);
|
|
622
|
+
requireLiteral(value.framework, 'anchor', `${path}.framework`, 'production_browser_wallet_rejected', errors);
|
|
623
|
+
requireLiteral(value.source, 'resolved-network-profile', `${path}.source`, 'non_canonical_browser_wallet_identity', errors);
|
|
624
|
+
requireLiteral(value.submissionReady, true, `${path}.submissionReady`, 'production_browser_wallet_rejected', errors);
|
|
625
|
+
if (!isPlainObject(value.ids)) {
|
|
626
|
+
errors.push(error('missing_browser_wallet_approval_field', `${path}.ids`, 'exact program ids are required'));
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
rejectUnknownKeys(value.ids, `${path}.ids`, PROGRAM_IDS_KEYS, errors);
|
|
630
|
+
for (const key of PROGRAM_IDS_KEYS) {
|
|
631
|
+
if (!isValidSolanaPublicKey(value.ids[key])) {
|
|
632
|
+
errors.push(error('non_canonical_browser_wallet_identity', `${path}.ids.${key}`, 'program id must be an exact 32-byte Solana public key'));
|
|
633
|
+
}
|
|
634
|
+
if (!trustedDevnetProgramIds) {
|
|
635
|
+
errors.push(error('missing_browser_wallet_approval_field', `${path}.ids.${key}`, 'trusted Devnet program identity context is required'));
|
|
636
|
+
}
|
|
637
|
+
else if (value.ids[key] !== trustedDevnetProgramIds[key]) {
|
|
638
|
+
errors.push(error('non_canonical_browser_wallet_identity', `${path}.ids.${key}`, 'program id must match the trusted resolved Devnet profile'));
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
function validateFunding(value, path, errors) {
|
|
643
|
+
if (!isPlainObject(value)) {
|
|
644
|
+
errors.push(error('missing_browser_wallet_approval_field', path, 'funding source and balance cap are required'));
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
rejectUnknownKeys(value, path, FUNDING_KEYS, errors);
|
|
648
|
+
requireLiteral(value.source, 'human-capped-devnet', `${path}.source`, 'ai_faucet_rejected', errors);
|
|
649
|
+
requireExactString(value.sourceRef, `${path}.sourceRef`, errors);
|
|
650
|
+
requireLiteral(value.humanApproved, true, `${path}.humanApproved`, 'ai_faucet_rejected', errors);
|
|
651
|
+
requireLiteral(value.aiFaucetUse, false, `${path}.aiFaucetUse`, 'ai_faucet_rejected', errors);
|
|
652
|
+
requireLiteral(value.autoTopUp, false, `${path}.autoTopUp`, 'ai_faucet_rejected', errors);
|
|
653
|
+
if (typeof value.maxBalanceSol !== 'number' || !Number.isFinite(value.maxBalanceSol) || value.maxBalanceSol <= 0 || value.maxBalanceSol > 2) {
|
|
654
|
+
errors.push(error('overly_broad_browser_wallet_approval', `${path}.maxBalanceSol`, 'maximum Devnet SOL balance at risk must be positive and capped at or below 2 SOL'));
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
function validateCaps(value, path, errors) {
|
|
658
|
+
if (!isPlainObject(value)) {
|
|
659
|
+
errors.push(error('missing_browser_wallet_approval_field', path, 'per-action and per-session caps are required'));
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
rejectUnknownKeys(value, path, CAPS_KEYS, errors);
|
|
663
|
+
const perAction = parseBaseUnits(value.perActionBaseUnits, `${path}.perActionBaseUnits`, errors);
|
|
664
|
+
const perSession = parseBaseUnits(value.perSessionBaseUnits, `${path}.perSessionBaseUnits`, errors);
|
|
665
|
+
parseBaseUnits(value.maxFeeLamports, `${path}.maxFeeLamports`, errors);
|
|
666
|
+
requireLiteral(value.maxActions, 1, `${path}.maxActions`, 'non_single_use_browser_wallet_approval', errors);
|
|
667
|
+
if (perAction !== undefined && perSession !== undefined && perSession < perAction) {
|
|
668
|
+
errors.push(error('contradictory_browser_wallet_approval', `${path}.perSessionBaseUnits`, 'session cap must be greater than or equal to per-action cap'));
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
function validateRetryPolicy(value, path, errors) {
|
|
672
|
+
if (!isPlainObject(value)) {
|
|
673
|
+
errors.push(error('missing_browser_wallet_approval_field', path, 'retry policy is required'));
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
rejectUnknownKeys(value, path, RETRY_POLICY_KEYS, errors);
|
|
677
|
+
if (typeof value.allowed !== 'boolean') {
|
|
678
|
+
errors.push(error('malformed_browser_wallet_approval', `${path}.allowed`, 'retry allowed flag must be boolean'));
|
|
679
|
+
}
|
|
680
|
+
const maxRetries = value.maxRetries;
|
|
681
|
+
if (!Number.isInteger(maxRetries) || typeof maxRetries !== 'number' || maxRetries < 0) {
|
|
682
|
+
errors.push(error('malformed_browser_wallet_approval', `${path}.maxRetries`, 'retry count must be a non-negative integer'));
|
|
683
|
+
}
|
|
684
|
+
else if (value.allowed === false && maxRetries !== 0) {
|
|
685
|
+
errors.push(error('contradictory_browser_wallet_approval', `${path}.maxRetries`, 'disabled retries must have maxRetries set to 0'));
|
|
686
|
+
}
|
|
687
|
+
else if (value.allowed === true && (maxRetries < 1 || maxRetries > 2)) {
|
|
688
|
+
errors.push(error('overly_broad_browser_wallet_approval', `${path}.maxRetries`, 'enabled retries must be explicitly bounded to one or two attempts'));
|
|
689
|
+
}
|
|
690
|
+
requireLiteral(value.countsAgainstCaps, true, `${path}.countsAgainstCaps`, 'contradictory_browser_wallet_approval', errors);
|
|
691
|
+
}
|
|
692
|
+
function validateAsset(value, action, allowFuturePartnerConfirmedAuddDevnet, trustedFutureAuddDevnetIdentity, path, errors) {
|
|
693
|
+
if (!isPlainObject(value)) {
|
|
694
|
+
errors.push(error('missing_browser_wallet_approval_field', path, 'asset identity is required'));
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
rejectUnknownKeys(value, path, ASSET_KEYS, errors);
|
|
698
|
+
if (typeof value.mint === 'string' && REJECTED_MAINNET_MINTS.has(value.mint)) {
|
|
699
|
+
errors.push(error('mainnet_browser_wallet_rejected', `${path}.mint`, 'official Solana mainnet mints are never valid for a Devnet browser-wallet approval'));
|
|
700
|
+
}
|
|
701
|
+
if (typeof value.symbol !== 'string' || !['SOL', 'USDC', 'AUDD', 'AUDD_TEST', 'LOCAL_AUDD_TEST'].includes(value.symbol)) {
|
|
702
|
+
errors.push(error('non_canonical_browser_wallet_identity', `${path}.symbol`, 'asset symbol is not canonical for browser-wallet approval'));
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
if (value.symbol === 'SOL') {
|
|
706
|
+
requireLiteral(value.railEnvironment, 'devnet-unverified', `${path}.railEnvironment`, 'non_canonical_browser_wallet_identity', errors);
|
|
707
|
+
requireLiteral(value.mint, null, `${path}.mint`, 'non_canonical_browser_wallet_identity', errors);
|
|
708
|
+
requireLiteral(value.tokenProgram, null, `${path}.tokenProgram`, 'non_canonical_browser_wallet_identity', errors);
|
|
709
|
+
requireLiteral(value.decimals, 9, `${path}.decimals`, 'non_canonical_browser_wallet_identity', errors);
|
|
710
|
+
requireLiteral(value.source, 'devnet-sol-fee', `${path}.source`, 'non_canonical_browser_wallet_identity', errors);
|
|
711
|
+
requireLiteral(value.official, false, `${path}.official`, 'official_audd_devnet_unavailable', errors);
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
if (value.symbol === 'USDC') {
|
|
715
|
+
requireLiteral(value.railEnvironment, 'devnet-unverified', `${path}.railEnvironment`, 'non_canonical_browser_wallet_identity', errors);
|
|
716
|
+
if (value.mint !== CANONICAL_DEVNET_USDC_MINT) {
|
|
717
|
+
errors.push(error('non_canonical_browser_wallet_identity', `${path}.mint`, 'USDC approval must name the canonical Devnet USDC mint of the existing gated lane'));
|
|
718
|
+
}
|
|
719
|
+
requireLiteral(value.tokenProgram, SPL_TOKEN_PROGRAM_ID, `${path}.tokenProgram`, 'non_canonical_browser_wallet_identity', errors);
|
|
720
|
+
requireLiteral(value.decimals, 6, `${path}.decimals`, 'non_canonical_browser_wallet_identity', errors);
|
|
721
|
+
requireLiteral(value.source, 'existing-gated-devnet-usdc-lane', `${path}.source`, 'non_canonical_browser_wallet_identity', errors);
|
|
722
|
+
requireLiteral(value.official, false, `${path}.official`, 'official_audd_devnet_unavailable', errors);
|
|
723
|
+
if (action !== 'x402-devnet-usdc-payment') {
|
|
724
|
+
errors.push(error('contradictory_browser_wallet_approval', `${path}.symbol`, 'USDC asset requires the x402 Devnet USDC UI action'));
|
|
725
|
+
}
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
if (value.symbol === 'AUDD_TEST' || value.symbol === 'LOCAL_AUDD_TEST') {
|
|
729
|
+
errors.push(error('non_canonical_browser_wallet_identity', `${path}.symbol`, 'local AUDD test mints are Tier 1 only and cannot be approved for a Devnet browser-wallet action'));
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
// Official AUDD Devnet is deliberately unavailable by default. The dormant
|
|
733
|
+
// future shape below must still fail unless the caller deliberately enables a
|
|
734
|
+
// future partner-confirmed flow after a separate approval exists. Even then,
|
|
735
|
+
// the asset row must be bound exactly to the partner-confirmed Devnet rail
|
|
736
|
+
// identity so a mainnet or unrelated mint cannot be smuggled through.
|
|
737
|
+
const partnerConfirmation = isPlainObject(value.auddPartnerConfirmation) ? value.auddPartnerConfirmation : undefined;
|
|
738
|
+
const futureAuddShape = Boolean(partnerConfirmation)
|
|
739
|
+
&& typeof value.auddDevnetApprovalRef === 'string'
|
|
740
|
+
&& value.railEnvironment === 'devnet-unverified'
|
|
741
|
+
&& value.source === 'partner-confirmed-audd-devnet'
|
|
742
|
+
&& value.official === false;
|
|
743
|
+
if (!futureAuddShape || !allowFuturePartnerConfirmedAuddDevnet || !trustedFutureAuddDevnetIdentity) {
|
|
744
|
+
errors.push(error('official_audd_devnet_unavailable', path, 'official AUDD Devnet browser-wallet action is unavailable without trusted future partner confirmation and separate approval'));
|
|
745
|
+
}
|
|
746
|
+
if (partnerConfirmation) {
|
|
747
|
+
rejectUnknownKeys(partnerConfirmation, `${path}.auddPartnerConfirmation`, AUDD_PARTNER_CONFIRMATION_KEYS, errors);
|
|
748
|
+
requireHttpsUrl(partnerConfirmation.sourceUrl, `${path}.auddPartnerConfirmation.sourceUrl`, errors);
|
|
749
|
+
validateTimestamp(partnerConfirmation.sourceRetrievedAt, `${path}.auddPartnerConfirmation.sourceRetrievedAt`, errors);
|
|
750
|
+
validateOptionalHash(partnerConfirmation.sourceSha256, `${path}.auddPartnerConfirmation.sourceSha256`, errors);
|
|
751
|
+
if (!isValidSolanaPublicKey(partnerConfirmation.confirmedMint)) {
|
|
752
|
+
errors.push(error('non_canonical_browser_wallet_identity', `${path}.auddPartnerConfirmation.confirmedMint`, 'future AUDD Devnet partner confirmation must name an exact mint'));
|
|
753
|
+
}
|
|
754
|
+
else if (REJECTED_MAINNET_MINTS.has(partnerConfirmation.confirmedMint)) {
|
|
755
|
+
errors.push(error('mainnet_browser_wallet_rejected', `${path}.auddPartnerConfirmation.confirmedMint`, 'an official Solana mainnet mint is never a partner-confirmed Devnet mint'));
|
|
756
|
+
}
|
|
757
|
+
else if (partnerConfirmation.confirmedMint === CANONICAL_DEVNET_USDC_MINT) {
|
|
758
|
+
errors.push(error('non_canonical_browser_wallet_identity', `${path}.auddPartnerConfirmation.confirmedMint`, 'the canonical Devnet USDC mint is not an AUDD Devnet mint'));
|
|
759
|
+
}
|
|
760
|
+
requireLiteral(partnerConfirmation.confirmedDecimals, AUDD_DECIMALS, `${path}.auddPartnerConfirmation.confirmedDecimals`, 'non_canonical_browser_wallet_identity', errors);
|
|
761
|
+
requireLiteral(partnerConfirmation.confirmedTokenProgram, SPL_TOKEN_PROGRAM_ID, `${path}.auddPartnerConfirmation.confirmedTokenProgram`, 'non_canonical_browser_wallet_identity', errors);
|
|
762
|
+
}
|
|
763
|
+
requireExactString(value.auddDevnetApprovalRef, `${path}.auddDevnetApprovalRef`, errors);
|
|
764
|
+
if (trustedFutureAuddDevnetIdentity) {
|
|
765
|
+
requireLiteral(value.auddDevnetApprovalRef, trustedFutureAuddDevnetIdentity.approvalRef, `${path}.auddDevnetApprovalRef`, 'contradictory_browser_wallet_approval', errors);
|
|
766
|
+
requireLiteral(partnerConfirmation?.sourceUrl, trustedFutureAuddDevnetIdentity.sourceUrl, `${path}.auddPartnerConfirmation.sourceUrl`, 'contradictory_browser_wallet_approval', errors);
|
|
767
|
+
requireLiteral(partnerConfirmation?.sourceRetrievedAt, trustedFutureAuddDevnetIdentity.sourceRetrievedAt, `${path}.auddPartnerConfirmation.sourceRetrievedAt`, 'contradictory_browser_wallet_approval', errors);
|
|
768
|
+
requireLiteral(partnerConfirmation?.sourceSha256, trustedFutureAuddDevnetIdentity.sourceSha256, `${path}.auddPartnerConfirmation.sourceSha256`, 'contradictory_browser_wallet_approval', errors);
|
|
769
|
+
requireLiteral(partnerConfirmation?.confirmedMint, trustedFutureAuddDevnetIdentity.mint, `${path}.auddPartnerConfirmation.confirmedMint`, 'contradictory_browser_wallet_approval', errors);
|
|
770
|
+
requireLiteral(partnerConfirmation?.confirmedDecimals, trustedFutureAuddDevnetIdentity.decimals, `${path}.auddPartnerConfirmation.confirmedDecimals`, 'contradictory_browser_wallet_approval', errors);
|
|
771
|
+
requireLiteral(partnerConfirmation?.confirmedTokenProgram, trustedFutureAuddDevnetIdentity.tokenProgram, `${path}.auddPartnerConfirmation.confirmedTokenProgram`, 'contradictory_browser_wallet_approval', errors);
|
|
772
|
+
}
|
|
773
|
+
if (!isValidSolanaPublicKey(value.mint)) {
|
|
774
|
+
errors.push(error('non_canonical_browser_wallet_identity', `${path}.mint`, 'future AUDD Devnet asset must name the exact partner-confirmed Devnet mint'));
|
|
775
|
+
}
|
|
776
|
+
else if (value.mint === CANONICAL_DEVNET_USDC_MINT) {
|
|
777
|
+
errors.push(error('non_canonical_browser_wallet_identity', `${path}.mint`, 'the canonical Devnet USDC mint is not an AUDD Devnet mint'));
|
|
778
|
+
}
|
|
779
|
+
else if (partnerConfirmation && isValidSolanaPublicKey(partnerConfirmation.confirmedMint) && value.mint !== partnerConfirmation.confirmedMint) {
|
|
780
|
+
errors.push(error('contradictory_browser_wallet_approval', `${path}.mint`, 'future AUDD Devnet asset mint must exactly match the partner-confirmed mint'));
|
|
781
|
+
}
|
|
782
|
+
requireLiteral(value.railEnvironment, 'devnet-unverified', `${path}.railEnvironment`, 'non_canonical_browser_wallet_identity', errors);
|
|
783
|
+
requireLiteral(value.source, 'partner-confirmed-audd-devnet', `${path}.source`, 'non_canonical_browser_wallet_identity', errors);
|
|
784
|
+
requireLiteral(value.official, false, `${path}.official`, 'official_audd_devnet_unavailable', errors);
|
|
785
|
+
requireLiteral(value.tokenProgram, SPL_TOKEN_PROGRAM_ID, `${path}.tokenProgram`, 'non_canonical_browser_wallet_identity', errors);
|
|
786
|
+
requireLiteral(value.decimals, AUDD_DECIMALS, `${path}.decimals`, 'non_canonical_browser_wallet_identity', errors);
|
|
787
|
+
}
|
|
788
|
+
function validateEvidence(value, path, errors) {
|
|
789
|
+
if (!isPlainObject(value)) {
|
|
790
|
+
errors.push(error('missing_browser_wallet_approval_field', path, 'evidence destination and redaction policy are required'));
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
rejectUnknownKeys(value, path, EVIDENCE_KEYS, errors);
|
|
794
|
+
if (typeof value.destination !== 'string' || hasBroadString(value.destination) || value.destination.includes('..') || value.destination.startsWith('/')) {
|
|
795
|
+
errors.push(error('overly_broad_browser_wallet_approval', `${path}.destination`, 'evidence destination must be one exact repo-relative path'));
|
|
796
|
+
}
|
|
797
|
+
else if (!value.destination.startsWith('artifacts/browser-wallet-devnet/') && !value.destination.startsWith('.tmp/browser-wallet-devnet/')) {
|
|
798
|
+
errors.push(error('non_canonical_browser_wallet_identity', `${path}.destination`, 'browser wallet evidence must use the browser-wallet-devnet evidence namespace'));
|
|
799
|
+
}
|
|
800
|
+
if (!isPlainObject(value.redaction)) {
|
|
801
|
+
errors.push(error('missing_browser_wallet_approval_field', `${path}.redaction`, 'evidence redaction policy is required'));
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
rejectUnknownKeys(value.redaction, `${path}.redaction`, REDACTION_KEYS, errors);
|
|
805
|
+
requireLiteral(value.redaction.privateKeys, 'forbidden', `${path}.redaction.privateKeys`, 'secret_material_rejected', errors);
|
|
806
|
+
requireLiteral(value.redaction.seedPhrases, 'forbidden', `${path}.redaction.seedPhrases`, 'secret_material_rejected', errors);
|
|
807
|
+
requireLiteral(value.redaction.signerArrays, 'forbidden', `${path}.redaction.signerArrays`, 'secret_material_rejected', errors);
|
|
808
|
+
requireLiteral(value.redaction.authHeaders, 'redact', `${path}.redaction.authHeaders`, 'secret_material_rejected', errors);
|
|
809
|
+
requireLiteral(value.redaction.cookies, 'redact', `${path}.redaction.cookies`, 'secret_material_rejected', errors);
|
|
810
|
+
requireLiteral(value.redaction.rawPaymentPayloads, 'redact', `${path}.redaction.rawPaymentPayloads`, 'secret_material_rejected', errors);
|
|
811
|
+
requireLiteral(value.redaction.screenshots, 'redacted-only', `${path}.redaction.screenshots`, 'secret_material_rejected', errors);
|
|
812
|
+
requireLiteral(value.redaction.includePublicKey, true, `${path}.redaction.includePublicKey`, 'non_canonical_browser_wallet_identity', errors);
|
|
813
|
+
requireLiteral(value.redaction.includeSignatures, 'devnet-only', `${path}.redaction.includeSignatures`, 'non_canonical_browser_wallet_identity', errors);
|
|
814
|
+
}
|
|
815
|
+
function validateRollback(value, path, errors) {
|
|
816
|
+
if (!isPlainObject(value)) {
|
|
817
|
+
errors.push(error('missing_browser_wallet_approval_field', path, 'rollback owner and actions are required'));
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
rejectUnknownKeys(value, path, ROLLBACK_KEYS, errors);
|
|
821
|
+
requireExactString(value.owner, `${path}.owner`, errors);
|
|
822
|
+
requireLiteral(value.disconnectRevoke, true, `${path}.disconnectRevoke`, 'custody_browser_wallet_rejected', errors);
|
|
823
|
+
requireLiteral(value.deleteBrowserProfile, true, `${path}.deleteBrowserProfile`, 'custody_browser_wallet_rejected', errors);
|
|
824
|
+
requireLiteral(value.deleteLocalState, true, `${path}.deleteLocalState`, 'custody_browser_wallet_rejected', errors);
|
|
825
|
+
requireLiteral(value.preserveRedactedEvidence, true, `${path}.preserveRedactedEvidence`, 'secret_material_rejected', errors);
|
|
826
|
+
requireLiteral(value.incidentSuspend, true, `${path}.incidentSuspend`, 'production_browser_wallet_rejected', errors);
|
|
827
|
+
requireLiteral(value.freshApprovalRequired, true, `${path}.freshApprovalRequired`, 'non_single_use_browser_wallet_approval', errors);
|
|
828
|
+
}
|
|
829
|
+
function validateBoundaries(value, path, errors) {
|
|
830
|
+
if (!isPlainObject(value)) {
|
|
831
|
+
errors.push(error('missing_browser_wallet_approval_field', path, 'explicit claim boundaries are required'));
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
rejectUnknownKeys(value, path, BOUNDARY_KEYS, errors);
|
|
835
|
+
requireLiteral(value.noMainnet, true, `${path}.noMainnet`, 'mainnet_browser_wallet_rejected', errors);
|
|
836
|
+
requireLiteral(value.noProduction, true, `${path}.noProduction`, 'production_browser_wallet_rejected', errors);
|
|
837
|
+
requireLiteral(value.noCustody, true, `${path}.noCustody`, 'custody_browser_wallet_rejected', errors);
|
|
838
|
+
requireLiteral(value.noSettlementFinality, true, `${path}.noSettlementFinality`, 'settlement_finality_rejected', errors);
|
|
839
|
+
requireLiteral(value.noOfficialAuddDevnet, true, `${path}.noOfficialAuddDevnet`, 'official_audd_devnet_unavailable', errors);
|
|
840
|
+
requireLiteral(value.noLiveFunds, true, `${path}.noLiveFunds`, 'production_browser_wallet_rejected', errors);
|
|
841
|
+
requireLiteral(value.noAiFaucet, true, `${path}.noAiFaucet`, 'ai_faucet_rejected', errors);
|
|
842
|
+
requireLiteral(value.noPayShProduction, true, `${path}.noPayShProduction`, 'production_browser_wallet_rejected', errors);
|
|
843
|
+
requireLiteral(value.noAutomaticTopUp, true, `${path}.noAutomaticTopUp`, 'ai_faucet_rejected', errors);
|
|
844
|
+
}
|
|
845
|
+
function copyGuardRailConfig(railEnvironment) {
|
|
846
|
+
return typeof railEnvironment === 'string' && NON_LIVE_COPY_GUARD_RAIL_ENVIRONMENTS.has(railEnvironment)
|
|
847
|
+
? getAuddRailEnvironmentConfig(railEnvironment)
|
|
848
|
+
: undefined;
|
|
849
|
+
}
|
|
850
|
+
function validateCopyGuardRailIdentity(row, errors) {
|
|
851
|
+
const requireCopyLiteral = (value, expected, path, message) => {
|
|
852
|
+
if (value !== expected)
|
|
853
|
+
errors.push(error('non_canonical_browser_wallet_identity', path, message));
|
|
854
|
+
};
|
|
855
|
+
const rail = copyGuardRailConfig(row.railEnvironment);
|
|
856
|
+
if (rail?.environment === 'deterministic-fixture') {
|
|
857
|
+
requireCopyLiteral(row.networkAlias, rail.networkAlias, '$.networkAlias', 'deterministic fixture rows must use the Solana Devnet network alias');
|
|
858
|
+
requireCopyLiteral(row.caip2, rail.caip2, '$.caip2', 'deterministic fixture rows must use the canonical Solana Devnet CAIP-2 identity');
|
|
859
|
+
requireCopyLiteral(row.mint, rail.mint, '$.mint', 'deterministic fixture rows must use the fixture sentinel mint');
|
|
860
|
+
}
|
|
861
|
+
else if (rail?.environment === 'local-test-mint') {
|
|
862
|
+
requireCopyLiteral(row.networkAlias, rail.networkAlias, '$.networkAlias', 'local test mint rows must use the local-surfpool network alias');
|
|
863
|
+
requireCopyLiteral(row.caip2, null, '$.caip2', 'local test mint rows must not claim a live CAIP-2 chain identity');
|
|
864
|
+
if (!isValidSolanaPublicKey(row.mint)) {
|
|
865
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.mint', 'local test mint rows require one exact 32-byte Solana public key'));
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
else if (rail?.environment === 'devnet-unverified') {
|
|
869
|
+
requireCopyLiteral(row.networkAlias, rail.networkAlias, '$.networkAlias', 'unverified Devnet rows must use the Solana Devnet network alias');
|
|
870
|
+
requireCopyLiteral(row.caip2, rail.caip2, '$.caip2', 'unverified Devnet rows must use the canonical Solana Devnet CAIP-2 identity');
|
|
871
|
+
if (!isValidSolanaPublicKey(row.mint)) {
|
|
872
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.mint', 'unverified Devnet token rows require one exact 32-byte Solana public key'));
|
|
873
|
+
}
|
|
874
|
+
if (row.assetLabel === 'USDC' && row.mint !== CANONICAL_DEVNET_USDC_MINT) {
|
|
875
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.mint', 'Devnet USDC rows must use the canonical Devnet USDC mint'));
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
if (row.assetLabel === 'USDC' && row.railEnvironment !== 'devnet-unverified') {
|
|
879
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.assetLabel', 'USDC copy rows are valid only on the canonical unverified Devnet rail'));
|
|
880
|
+
}
|
|
881
|
+
if (row.assetLabel !== 'USDC' && row.mint === CANONICAL_DEVNET_USDC_MINT) {
|
|
882
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.mint', 'the canonical Devnet USDC mint must not be labelled as an AUDD-family asset'));
|
|
883
|
+
}
|
|
884
|
+
requireCopyLiteral(row.tokenProgram, rail?.tokenProgram ?? AUDD_RAIL_CONFIG.tokenPrograms.splToken, '$.tokenProgram', 'browser-wallet token rows must use the canonical SPL Token program');
|
|
885
|
+
requireCopyLiteral(row.decimals, rail?.decimals ?? AUDD_RAIL_CONFIG.decimals, '$.decimals', 'browser-wallet AUDD-family and USDC rows must use six decimals');
|
|
886
|
+
}
|
|
887
|
+
function validateCopyGuardNestedShapes(row, errors) {
|
|
888
|
+
const x402 = row.x402Export;
|
|
889
|
+
if (x402) {
|
|
890
|
+
if (x402.state !== 'expected' && x402.state !== 'fixture-observed' && x402.state !== 'observed')
|
|
891
|
+
errors.push(error('malformed_browser_wallet_approval', '$.x402Export.state', 'x402 export state is invalid'));
|
|
892
|
+
requireExactString(x402.asset, '$.x402Export.asset', errors);
|
|
893
|
+
requireExactString(x402.networkAlias, '$.x402Export.networkAlias', errors);
|
|
894
|
+
validateOptionalExactString(x402.caip2, '$.x402Export.caip2', errors);
|
|
895
|
+
validateOptionalExactString(x402.mint, '$.x402Export.mint', errors);
|
|
896
|
+
if (x402.tokenProgram !== undefined && x402.tokenProgram !== null)
|
|
897
|
+
requireLiteral(x402.tokenProgram, SPL_TOKEN_PROGRAM_ID, '$.x402Export.tokenProgram', 'non_canonical_browser_wallet_identity', errors);
|
|
898
|
+
if (x402.decimals !== undefined && x402.decimals !== null && x402.decimals !== AUDD_DECIMALS)
|
|
899
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.x402Export.decimals', 'x402 export decimals must match the row AUDD-family identity'));
|
|
900
|
+
}
|
|
901
|
+
const policy = row.policy;
|
|
902
|
+
if (policy) {
|
|
903
|
+
if (!isPaymentEligibility(policy.grantEligibility))
|
|
904
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.policy.grantEligibility', 'policy grant eligibility is invalid'));
|
|
905
|
+
validateOptionalExactString(policy.operatorApprovalRef, '$.policy.operatorApprovalRef', errors);
|
|
906
|
+
if (typeof policy.controlledLive !== 'boolean')
|
|
907
|
+
errors.push(error('malformed_browser_wallet_approval', '$.policy.controlledLive', 'policy controlledLive flag must be boolean'));
|
|
908
|
+
}
|
|
909
|
+
const receipt = row.receipt;
|
|
910
|
+
if (receipt) {
|
|
911
|
+
if (typeof receipt.claim !== 'string' || !['expected-only', 'fixture-only', 'observed-transfer-checked', 'observed-settlement'].includes(receipt.claim))
|
|
912
|
+
errors.push(error('malformed_browser_wallet_approval', '$.receipt.claim', 'receipt claim is invalid'));
|
|
913
|
+
if (typeof receipt.observationStatus !== 'string' || !['not-observed', 'fixture-observed', 'local-observed', 'rpc-observed'].includes(receipt.observationStatus))
|
|
914
|
+
errors.push(error('malformed_browser_wallet_approval', '$.receipt.observationStatus', 'receipt observation status is invalid'));
|
|
915
|
+
if (typeof receipt.settlementFinality !== 'boolean')
|
|
916
|
+
errors.push(error('malformed_browser_wallet_approval', '$.receipt.settlementFinality', 'receipt settlementFinality flag must be boolean'));
|
|
917
|
+
if (typeof receipt.controlledLiveEvidence !== 'boolean')
|
|
918
|
+
errors.push(error('malformed_browser_wallet_approval', '$.receipt.controlledLiveEvidence', 'receipt controlledLiveEvidence flag must be boolean'));
|
|
919
|
+
}
|
|
920
|
+
const copy = row.copy;
|
|
921
|
+
if (copy) {
|
|
922
|
+
if (copy.title !== undefined && typeof copy.title !== 'string')
|
|
923
|
+
errors.push(error('malformed_browser_wallet_approval', '$.copy.title', 'copy title must be a string'));
|
|
924
|
+
if (copy.summary !== undefined && typeof copy.summary !== 'string')
|
|
925
|
+
errors.push(error('malformed_browser_wallet_approval', '$.copy.summary', 'copy summary must be a string'));
|
|
926
|
+
validateStringArray(copy.badges, '$.copy.badges', errors);
|
|
927
|
+
validateStringArray(copy.notes, '$.copy.notes', errors);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
function validateCanonicalX402Export(row, errors) {
|
|
931
|
+
const x402 = row.x402Export;
|
|
932
|
+
if (!x402)
|
|
933
|
+
return;
|
|
934
|
+
if (x402.asset !== row.assetLabel || x402.networkAlias !== row.networkAlias || x402.caip2 !== row.caip2 || x402.mint !== row.mint || x402.tokenProgram !== row.tokenProgram || x402.decimals !== row.decimals) {
|
|
935
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.x402Export', 'x402 export identity must exactly match the row identity'));
|
|
936
|
+
}
|
|
937
|
+
if (x402.state === 'fixture-observed' && (row.railEnvironment !== 'deterministic-fixture' || row.observationSource !== 'parsed-transaction-fixture')) {
|
|
938
|
+
errors.push(error('settlement_finality_rejected', '$.x402Export.state', 'fixture-observed exports require parsed deterministic fixture evidence'));
|
|
939
|
+
}
|
|
940
|
+
if (x402.state === 'observed' && (row.observationSource === 'expected-only' || row.railEnvironment === 'deterministic-fixture')) {
|
|
941
|
+
errors.push(error('settlement_finality_rejected', '$.x402Export.state', 'expected or deterministic fixture terms cannot be exported as observed evidence'));
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
function validateReceiptBoundary(row, errors) {
|
|
945
|
+
const receipt = row.receipt;
|
|
946
|
+
if (!receipt)
|
|
947
|
+
return;
|
|
948
|
+
const sourceRank = (typeof row.observationSource === 'string' ? OBSERVATION_SOURCE_RANK[row.observationSource] : undefined) ?? -1;
|
|
949
|
+
if (((typeof receipt.claim === 'string' ? RECEIPT_CLAIM_RANK[receipt.claim] : undefined) ?? Number.MAX_SAFE_INTEGER) > sourceRank) {
|
|
950
|
+
errors.push(error('settlement_finality_rejected', '$.receipt.claim', 'receipt claim must not exceed the evidence the row observation source provides'));
|
|
951
|
+
}
|
|
952
|
+
if (((typeof receipt.observationStatus === 'string' ? RECEIPT_OBSERVATION_STATUS_RANK[receipt.observationStatus] : undefined) ?? Number.MAX_SAFE_INTEGER) > sourceRank) {
|
|
953
|
+
errors.push(error('settlement_finality_rejected', '$.receipt.observationStatus', 'receipt observation status must not exceed the row observation source'));
|
|
954
|
+
}
|
|
955
|
+
if (receipt.settlementFinality) {
|
|
956
|
+
errors.push(error('settlement_finality_rejected', '$.receipt.settlementFinality', 'settlement finality is not available in browser-wallet safety rows'));
|
|
957
|
+
}
|
|
958
|
+
if (receipt.controlledLiveEvidence) {
|
|
959
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.receipt.controlledLiveEvidence', 'browser-wallet safety rows must not carry controlled-live evidence'));
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
function validateCopyNested(value, path, allowed, errors) {
|
|
963
|
+
if (value === undefined)
|
|
964
|
+
return;
|
|
965
|
+
if (!isPlainObject(value)) {
|
|
966
|
+
errors.push(error('malformed_browser_wallet_approval', path, 'nested copy guard object is malformed'));
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
rejectUnknownKeys(value, path, allowed, errors);
|
|
970
|
+
}
|
|
971
|
+
function validateCopyGuardAssetLabel(value, railEnvironment, errors) {
|
|
972
|
+
if (typeof value !== 'string')
|
|
973
|
+
return;
|
|
974
|
+
const normalized = value.normalize('NFKC');
|
|
975
|
+
if (normalized !== value || /[^\x20-\x7e]/u.test(value)) {
|
|
976
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.assetLabel', 'asset label must use unambiguous canonical ASCII without Unicode normalization'));
|
|
977
|
+
return;
|
|
978
|
+
}
|
|
979
|
+
const compact = value.toUpperCase().replace(/[^A-Z0-9]/g, '');
|
|
980
|
+
const reservedDerivative = compact.includes('AUDD') || compact.includes('USDC');
|
|
981
|
+
const allowed = railEnvironment === 'deterministic-fixture'
|
|
982
|
+
? new Set(['AUDD'])
|
|
983
|
+
: railEnvironment === 'local-test-mint'
|
|
984
|
+
? new Set(['AUDD_TEST', 'LOCAL_AUDD_TEST'])
|
|
985
|
+
: railEnvironment === 'devnet-unverified'
|
|
986
|
+
? new Set(['USDC'])
|
|
987
|
+
: new Set();
|
|
988
|
+
if (reservedDerivative && !allowed.has(value)) {
|
|
989
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.assetLabel', 'reserved AUDD/USDC branding must exactly match a canonical label allowed for this rail'));
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
function validateUnambiguousCopyText(text, errors) {
|
|
993
|
+
const nonAsciiLetterNumberOrMark = [...text].some((character) => (character.codePointAt(0) ?? 0) > 0x7f && /[\p{L}\p{N}\p{M}]/u.test(character));
|
|
994
|
+
const disallowedControlOrFormat = /[\p{Default_Ignorable_Code_Point}\p{Cf}\p{Cs}]/u.test(text)
|
|
995
|
+
|| /\p{Cc}/u.test(text.replace(/[\t\n\r]/g, ''));
|
|
996
|
+
if (text.normalize('NFKC') !== text || nonAsciiLetterNumberOrMark || disallowedControlOrFormat) {
|
|
997
|
+
errors.push(error('non_canonical_browser_wallet_identity', '$.copy', 'copy must not use Unicode normalization, default-ignorable characters, non-ASCII letters/numbers/marks, format/surrogate characters, or controls other than plain whitespace'));
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
function forbiddenCopyMatches(text) {
|
|
1001
|
+
const matches = [];
|
|
1002
|
+
const clauses = splitCopyClaimClauses(text);
|
|
1003
|
+
if (clauses.some((clause) => hasUnnegatedClaim(clause, AUDD_IDENTITY_CLAIM_PATTERN, DIRECTLY_NEGATED_AUDD_IDENTITY_PATTERN))) {
|
|
1004
|
+
matches.push({ code: 'official_audd_devnet_unavailable', message: 'copy must not claim official AUDD identity or AUDD endorsement' });
|
|
1005
|
+
}
|
|
1006
|
+
if (clauses.some((clause) => hasUnnegatedClaim(clause, /grant[-\s]?eligible|eligible\s+for\s+grant|grant\s+volume/i, /(?<!\b(?:not|never|no|non)[\s_-]+)\b(?:not|never|no|non[_-])\s*grant[-\s]?eligible/gi))) {
|
|
1007
|
+
matches.push({ code: 'non_canonical_browser_wallet_identity', message: 'copy must not describe browser-wallet safety rows as grant-eligible' });
|
|
1008
|
+
}
|
|
1009
|
+
if (clauses.some((clause) => /observed\s+settlement|settlement\s+observed|settlement\s+finality|final\s+settlement|settled\s+on/i.test(clause))) {
|
|
1010
|
+
matches.push({ code: 'settlement_finality_rejected', message: 'copy must not upgrade expected or safety evidence into observed settlement/finality' });
|
|
1011
|
+
}
|
|
1012
|
+
if (clauses.some((clause) => /controlled[-\s]?live|controlled\s+live\s+evidence/i.test(clause))) {
|
|
1013
|
+
matches.push({ code: 'non_canonical_browser_wallet_identity', message: 'copy must not describe browser-wallet safety rows as controlled-live evidence' });
|
|
1014
|
+
}
|
|
1015
|
+
return matches;
|
|
1016
|
+
}
|
|
1017
|
+
function splitCopyClaimClauses(text) {
|
|
1018
|
+
return text
|
|
1019
|
+
.split(/[\n.;,]+|\s+[–—-]\s+/u)
|
|
1020
|
+
.map((clause) => clause.trim())
|
|
1021
|
+
.filter((clause) => clause.length > 0);
|
|
1022
|
+
}
|
|
1023
|
+
function hasUnnegatedClaim(text, claimPattern, negatedClaimPattern) {
|
|
1024
|
+
return claimPattern.test(text.replace(negatedClaimPattern, ' | '));
|
|
1025
|
+
}
|
|
1026
|
+
function rejectUnknownKeys(value, path, allowed, errors) {
|
|
1027
|
+
for (const key of Object.keys(value)) {
|
|
1028
|
+
if (!allowed.has(key)) {
|
|
1029
|
+
errors.push(error('unknown_browser_wallet_approval_field', `${path}.${key}`, 'field is not part of the canonical browser-wallet safety schema'));
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
function requireLiteral(value, expected, path, code, errors) {
|
|
1034
|
+
if (value !== expected)
|
|
1035
|
+
errors.push(error(code, path, 'field does not match the required literal value'));
|
|
1036
|
+
}
|
|
1037
|
+
function requireExactString(value, path, errors) {
|
|
1038
|
+
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
1039
|
+
errors.push(error('missing_browser_wallet_approval_field', path, 'required exact string is missing'));
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
if (!ID_PATTERN.test(value) || hasBroadString(value)) {
|
|
1043
|
+
errors.push(error('overly_broad_browser_wallet_approval', path, 'string must be exact and non-broad'));
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
function validateOptionalExactString(value, path, errors) {
|
|
1047
|
+
if (value === undefined || value === null)
|
|
1048
|
+
return;
|
|
1049
|
+
requireExactString(value, path, errors);
|
|
1050
|
+
}
|
|
1051
|
+
function validateStringArray(value, path, errors) {
|
|
1052
|
+
if (value === undefined)
|
|
1053
|
+
return;
|
|
1054
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== 'string')) {
|
|
1055
|
+
errors.push(error('malformed_browser_wallet_approval', path, 'field must be an array of strings when present'));
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
function requireHttpsUrl(value, path, errors, allowQuery = true) {
|
|
1059
|
+
if (typeof value !== 'string' || hasBroadString(value) || /\s/.test(value)) {
|
|
1060
|
+
errors.push(error('overly_broad_browser_wallet_approval', path, 'URL must be exact and non-broad'));
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
try {
|
|
1064
|
+
const url = new URL(value);
|
|
1065
|
+
if (url.protocol !== 'https:' || url.username || url.password || url.hash || (!allowQuery && url.search)) {
|
|
1066
|
+
errors.push(error('non_canonical_browser_wallet_identity', path, allowQuery
|
|
1067
|
+
? 'URL must be HTTPS without credentials or fragment'
|
|
1068
|
+
: 'RPC URL must be HTTPS without credentials, query, or fragment'));
|
|
1069
|
+
}
|
|
1070
|
+
if (/mainnet|production|prod/i.test(url.hostname)) {
|
|
1071
|
+
errors.push(error('mainnet_browser_wallet_rejected', path, 'mainnet/production endpoints are rejected'));
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
catch {
|
|
1075
|
+
errors.push(error('malformed_browser_wallet_approval', path, 'URL is malformed'));
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
function validateOptionalWssUrl(value, path, errors, allowQuery = true) {
|
|
1079
|
+
if (value === undefined || value === null)
|
|
1080
|
+
return;
|
|
1081
|
+
if (typeof value !== 'string' || hasBroadString(value) || /\s/.test(value)) {
|
|
1082
|
+
errors.push(error('overly_broad_browser_wallet_approval', path, 'WebSocket URL must be exact and non-broad'));
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1085
|
+
try {
|
|
1086
|
+
const url = new URL(value);
|
|
1087
|
+
if (url.protocol !== 'wss:' || url.username || url.password || url.hash || (!allowQuery && url.search)) {
|
|
1088
|
+
errors.push(error('non_canonical_browser_wallet_identity', path, allowQuery
|
|
1089
|
+
? 'WebSocket URL must be WSS without credentials or fragment'
|
|
1090
|
+
: 'RPC WebSocket URL must be WSS without credentials, query, or fragment'));
|
|
1091
|
+
}
|
|
1092
|
+
if (/mainnet|production|prod/i.test(url.hostname)) {
|
|
1093
|
+
errors.push(error('mainnet_browser_wallet_rejected', path, 'mainnet/production endpoints are rejected'));
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
catch {
|
|
1097
|
+
errors.push(error('malformed_browser_wallet_approval', path, 'WebSocket URL is malformed'));
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
function validateTimestamp(value, path, errors) {
|
|
1101
|
+
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
1102
|
+
errors.push(error('missing_browser_wallet_approval_field', path, 'timestamp is required'));
|
|
1103
|
+
return undefined;
|
|
1104
|
+
}
|
|
1105
|
+
const parsed = parseCanonicalUtcTimestamp(value);
|
|
1106
|
+
if (parsed === undefined) {
|
|
1107
|
+
errors.push(error('malformed_browser_wallet_approval', path, 'timestamp must be a real canonical UTC ISO-8601 calendar instant'));
|
|
1108
|
+
return undefined;
|
|
1109
|
+
}
|
|
1110
|
+
return parsed;
|
|
1111
|
+
}
|
|
1112
|
+
function validateOptionalHash(value, path, errors) {
|
|
1113
|
+
if (value === undefined)
|
|
1114
|
+
return;
|
|
1115
|
+
if (typeof value !== 'string' || !HASH_PATTERN.test(value)) {
|
|
1116
|
+
errors.push(error('malformed_browser_wallet_approval', path, 'hash must be sha256:<64 hex> when present'));
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
function parseBaseUnits(value, path, errors) {
|
|
1120
|
+
if (typeof value !== 'string' || !NON_NEGATIVE_INTEGER_STRING.test(value)) {
|
|
1121
|
+
errors.push(error('malformed_browser_wallet_approval', path, 'cap must be a non-negative integer string in base units'));
|
|
1122
|
+
return undefined;
|
|
1123
|
+
}
|
|
1124
|
+
return BigInt(value);
|
|
1125
|
+
}
|
|
1126
|
+
function normalizeNow(now) {
|
|
1127
|
+
if (now === undefined)
|
|
1128
|
+
return Date.now();
|
|
1129
|
+
if (now instanceof Date && Number.isFinite(now.getTime()))
|
|
1130
|
+
return now.getTime();
|
|
1131
|
+
return typeof now === 'string' ? parseCanonicalUtcTimestamp(now) : undefined;
|
|
1132
|
+
}
|
|
1133
|
+
function parseCanonicalUtcTimestamp(value) {
|
|
1134
|
+
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/.test(value))
|
|
1135
|
+
return undefined;
|
|
1136
|
+
const parsed = Date.parse(value);
|
|
1137
|
+
if (!Number.isFinite(parsed))
|
|
1138
|
+
return undefined;
|
|
1139
|
+
const canonical = new Date(parsed).toISOString();
|
|
1140
|
+
if (value === canonical)
|
|
1141
|
+
return parsed;
|
|
1142
|
+
return canonical.endsWith('.000Z') && value === canonical.replace('.000Z', 'Z') ? parsed : undefined;
|
|
1143
|
+
}
|
|
1144
|
+
function hasExactStringSet(value, expected) {
|
|
1145
|
+
if (!Array.isArray(value) || value.length !== expected.length || value.some((entry) => typeof entry !== 'string'))
|
|
1146
|
+
return false;
|
|
1147
|
+
const actual = new Set(value);
|
|
1148
|
+
return actual.size === expected.length && expected.every((entry) => actual.has(entry));
|
|
1149
|
+
}
|
|
1150
|
+
function hasBroadString(value) {
|
|
1151
|
+
return BROAD_STRING_PATTERN.test(value.trim());
|
|
1152
|
+
}
|
|
1153
|
+
function collectCopyText(copy) {
|
|
1154
|
+
if (!copy)
|
|
1155
|
+
return [];
|
|
1156
|
+
return [copy.title, copy.summary, ...(Array.isArray(copy.badges) ? copy.badges : []), ...(Array.isArray(copy.notes) ? copy.notes : [])]
|
|
1157
|
+
.filter((value) => typeof value === 'string' && value.length > 0);
|
|
1158
|
+
}
|
|
1159
|
+
function isPaymentEnvironment(value) {
|
|
1160
|
+
return typeof value === 'string' && ['deterministic-fixture', 'local-test-mint', 'devnet-unverified', 'mainnet-gated', 'controlled-live'].includes(value);
|
|
1161
|
+
}
|
|
1162
|
+
function isPaymentEligibility(value) {
|
|
1163
|
+
return typeof value === 'string' && ['non_eligible', 'pending_partner_acceptance', 'eligible', 'excluded'].includes(value);
|
|
1164
|
+
}
|
|
1165
|
+
function isPlainObject(value) {
|
|
1166
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
1167
|
+
return false;
|
|
1168
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1169
|
+
return prototype === Object.prototype || prototype === null;
|
|
1170
|
+
}
|
|
1171
|
+
function isValidSolanaPublicKey(value) {
|
|
1172
|
+
if (typeof value !== 'string' || value.length < 32 || value.length > 44)
|
|
1173
|
+
return false;
|
|
1174
|
+
let leadingZeroBytes = 0;
|
|
1175
|
+
while (leadingZeroBytes < value.length && value[leadingZeroBytes] === '1')
|
|
1176
|
+
leadingZeroBytes += 1;
|
|
1177
|
+
let decoded = 0n;
|
|
1178
|
+
for (const char of value) {
|
|
1179
|
+
const digit = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'.indexOf(char);
|
|
1180
|
+
if (digit < 0)
|
|
1181
|
+
return false;
|
|
1182
|
+
decoded = decoded * 58n + BigInt(digit);
|
|
1183
|
+
}
|
|
1184
|
+
let significantBytes = 0;
|
|
1185
|
+
for (let remaining = decoded; remaining > 0n; remaining >>= 8n)
|
|
1186
|
+
significantBytes += 1;
|
|
1187
|
+
return leadingZeroBytes + significantBytes === 32;
|
|
1188
|
+
}
|
|
1189
|
+
function uniqueErrors(errors) {
|
|
1190
|
+
const seen = new Set();
|
|
1191
|
+
return errors.filter((item) => {
|
|
1192
|
+
const key = `${item.code}\u0000${item.path}\u0000${item.message}`;
|
|
1193
|
+
if (seen.has(key))
|
|
1194
|
+
return false;
|
|
1195
|
+
seen.add(key);
|
|
1196
|
+
return true;
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
function error(code, path, message) {
|
|
1200
|
+
return { code, path, message };
|
|
1201
|
+
}
|