@antseed/node 0.2.27 → 0.2.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -13
- package/dist/buyer-request-handler.d.ts +41 -0
- package/dist/buyer-request-handler.d.ts.map +1 -0
- package/dist/buyer-request-handler.js +254 -0
- package/dist/buyer-request-handler.js.map +1 -0
- package/dist/discovery/announcer.d.ts +5 -4
- package/dist/discovery/announcer.d.ts.map +1 -1
- package/dist/discovery/announcer.js +11 -18
- package/dist/discovery/announcer.js.map +1 -1
- package/dist/discovery/index.d.ts +0 -1
- package/dist/discovery/index.d.ts.map +1 -1
- package/dist/discovery/index.js +0 -1
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/metadata-codec.d.ts +2 -2
- package/dist/discovery/metadata-codec.d.ts.map +1 -1
- package/dist/discovery/metadata-codec.js +47 -72
- package/dist/discovery/metadata-codec.js.map +1 -1
- package/dist/discovery/metadata-validator.js +6 -6
- package/dist/discovery/metadata-validator.js.map +1 -1
- package/dist/discovery/peer-lookup.d.ts.map +1 -1
- package/dist/discovery/peer-lookup.js +1 -2
- package/dist/discovery/peer-lookup.js.map +1 -1
- package/dist/discovery/peer-metadata.d.ts +3 -5
- package/dist/discovery/peer-metadata.d.ts.map +1 -1
- package/dist/discovery/peer-metadata.js +1 -1
- package/dist/discovery/reputation-verifier.d.ts +2 -25
- package/dist/discovery/reputation-verifier.d.ts.map +1 -1
- package/dist/discovery/reputation-verifier.js +2 -48
- package/dist/discovery/reputation-verifier.js.map +1 -1
- package/dist/discovery/stats-verifier.d.ts +27 -0
- package/dist/discovery/stats-verifier.d.ts.map +1 -0
- package/dist/discovery/stats-verifier.js +38 -0
- package/dist/discovery/stats-verifier.js.map +1 -0
- package/dist/index.d.ts +10 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -5
- package/dist/index.js.map +1 -1
- package/dist/metering/index.d.ts +1 -0
- package/dist/metering/index.d.ts.map +1 -1
- package/dist/metering/index.js +1 -0
- package/dist/metering/index.js.map +1 -1
- package/dist/metering/receipt-generator.d.ts +4 -4
- package/dist/metering/receipt-generator.d.ts.map +1 -1
- package/dist/metering/receipt-verifier.d.ts +6 -6
- package/dist/metering/receipt-verifier.d.ts.map +1 -1
- package/dist/metering/receipt-verifier.js +1 -1
- package/dist/metering/seller-session-tracker.d.ts +91 -0
- package/dist/metering/seller-session-tracker.d.ts.map +1 -0
- package/dist/metering/seller-session-tracker.js +261 -0
- package/dist/metering/seller-session-tracker.js.map +1 -0
- package/dist/metering/storage.d.ts +11 -5
- package/dist/metering/storage.d.ts.map +1 -1
- package/dist/metering/storage.js +28 -80
- package/dist/metering/storage.js.map +1 -1
- package/dist/node.d.ts +69 -117
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +240 -1269
- package/dist/node.js.map +1 -1
- package/dist/p2p/connection-auth.d.ts +2 -1
- package/dist/p2p/connection-auth.d.ts.map +1 -1
- package/dist/p2p/connection-auth.js +6 -6
- package/dist/p2p/connection-auth.js.map +1 -1
- package/dist/p2p/connection-manager.d.ts +3 -2
- package/dist/p2p/connection-manager.d.ts.map +1 -1
- package/dist/p2p/connection-manager.js +6 -6
- package/dist/p2p/connection-manager.js.map +1 -1
- package/dist/p2p/identity.d.ts +22 -15
- package/dist/p2p/identity.d.ts.map +1 -1
- package/dist/p2p/identity.js +66 -51
- package/dist/p2p/identity.js.map +1 -1
- package/dist/p2p/index.d.ts +1 -1
- package/dist/p2p/index.d.ts.map +1 -1
- package/dist/p2p/index.js +1 -1
- package/dist/p2p/index.js.map +1 -1
- package/dist/p2p/payment-codec.d.ts +4 -8
- package/dist/p2p/payment-codec.d.ts.map +1 -1
- package/dist/p2p/payment-codec.js +27 -57
- package/dist/p2p/payment-codec.js.map +1 -1
- package/dist/p2p/payment-mux.d.ts +4 -10
- package/dist/p2p/payment-mux.d.ts.map +1 -1
- package/dist/p2p/payment-mux.js +11 -33
- package/dist/p2p/payment-mux.js.map +1 -1
- package/dist/payments/balance-manager.d.ts +2 -2
- package/dist/payments/balance-manager.d.ts.map +1 -1
- package/dist/payments/balance-manager.js +5 -5
- package/dist/payments/balance-manager.js.map +1 -1
- package/dist/payments/buyer-payment-manager.d.ts +154 -21
- package/dist/payments/buyer-payment-manager.d.ts.map +1 -1
- package/dist/payments/buyer-payment-manager.js +540 -166
- package/dist/payments/buyer-payment-manager.js.map +1 -1
- package/dist/payments/buyer-payment-negotiator.d.ts +84 -0
- package/dist/payments/buyer-payment-negotiator.d.ts.map +1 -0
- package/dist/payments/buyer-payment-negotiator.js +624 -0
- package/dist/payments/buyer-payment-negotiator.js.map +1 -0
- package/dist/payments/chain-config.d.ts +10 -4
- package/dist/payments/chain-config.d.ts.map +1 -1
- package/dist/payments/chain-config.js +19 -9
- package/dist/payments/chain-config.js.map +1 -1
- package/dist/payments/channel-session-state.d.ts +13 -0
- package/dist/payments/channel-session-state.d.ts.map +1 -0
- package/dist/payments/channel-session-state.js +25 -0
- package/dist/payments/channel-session-state.js.map +1 -0
- package/dist/payments/channel-store.d.ts +87 -0
- package/dist/payments/channel-store.d.ts.map +1 -0
- package/dist/payments/channel-store.js +276 -0
- package/dist/payments/channel-store.js.map +1 -0
- package/dist/payments/evm/ants-token-client.d.ts +1 -1
- package/dist/payments/evm/ants-token-client.d.ts.map +1 -1
- package/dist/payments/evm/ants-token-client.js +3 -4
- package/dist/payments/evm/ants-token-client.js.map +1 -1
- package/dist/payments/evm/base-evm-client.d.ts +10 -1
- package/dist/payments/evm/base-evm-client.d.ts.map +1 -1
- package/dist/payments/evm/base-evm-client.js +34 -1
- package/dist/payments/evm/base-evm-client.js.map +1 -1
- package/dist/payments/evm/channels-client.d.ts +51 -0
- package/dist/payments/evm/channels-client.d.ts.map +1 -0
- package/dist/payments/evm/channels-client.js +101 -0
- package/dist/payments/evm/channels-client.js.map +1 -0
- package/dist/payments/evm/deposits-client.d.ts +30 -0
- package/dist/payments/evm/deposits-client.d.ts.map +1 -0
- package/dist/payments/evm/deposits-client.js +78 -0
- package/dist/payments/evm/deposits-client.js.map +1 -0
- package/dist/payments/evm/emissions-client.d.ts +3 -4
- package/dist/payments/evm/emissions-client.d.ts.map +1 -1
- package/dist/payments/evm/emissions-client.js +11 -30
- package/dist/payments/evm/emissions-client.js.map +1 -1
- package/dist/payments/evm/identity-client.d.ts +15 -23
- package/dist/payments/evm/identity-client.d.ts.map +1 -1
- package/dist/payments/evm/identity-client.js +68 -99
- package/dist/payments/evm/identity-client.js.map +1 -1
- package/dist/payments/evm/keypair.d.ts +3 -14
- package/dist/payments/evm/keypair.d.ts.map +1 -1
- package/dist/payments/evm/keypair.js +4 -20
- package/dist/payments/evm/keypair.js.map +1 -1
- package/dist/payments/evm/sessions-client.d.ts +30 -0
- package/dist/payments/evm/sessions-client.d.ts.map +1 -0
- package/dist/payments/evm/sessions-client.js +61 -0
- package/dist/payments/evm/sessions-client.js.map +1 -0
- package/dist/payments/evm/signatures.d.ts +43 -12
- package/dist/payments/evm/signatures.d.ts.map +1 -1
- package/dist/payments/evm/signatures.js +62 -45
- package/dist/payments/evm/signatures.js.map +1 -1
- package/dist/payments/evm/staking-client.d.ts +24 -0
- package/dist/payments/evm/staking-client.d.ts.map +1 -0
- package/dist/payments/evm/staking-client.js +54 -0
- package/dist/payments/evm/staking-client.js.map +1 -0
- package/dist/payments/evm/stats-client.d.ts +20 -0
- package/dist/payments/evm/stats-client.d.ts.map +1 -0
- package/dist/payments/evm/stats-client.js +25 -0
- package/dist/payments/evm/stats-client.js.map +1 -0
- package/dist/payments/index.d.ts +17 -10
- package/dist/payments/index.d.ts.map +1 -1
- package/dist/payments/index.js +15 -8
- package/dist/payments/index.js.map +1 -1
- package/dist/payments/pricing.d.ts +25 -0
- package/dist/payments/pricing.d.ts.map +1 -0
- package/dist/payments/pricing.js +33 -0
- package/dist/payments/pricing.js.map +1 -0
- package/dist/payments/readiness.d.ts +4 -3
- package/dist/payments/readiness.d.ts.map +1 -1
- package/dist/payments/readiness.js +11 -18
- package/dist/payments/readiness.js.map +1 -1
- package/dist/payments/seller-payment-manager.d.ts +72 -47
- package/dist/payments/seller-payment-manager.d.ts.map +1 -1
- package/dist/payments/seller-payment-manager.js +558 -275
- package/dist/payments/seller-payment-manager.js.map +1 -1
- package/dist/payments/session-store.d.ts +3 -0
- package/dist/payments/session-store.d.ts.map +1 -1
- package/dist/payments/session-store.js +31 -2
- package/dist/payments/session-store.js.map +1 -1
- package/dist/payments/types.d.ts +5 -3
- package/dist/payments/types.d.ts.map +1 -1
- package/dist/proxy/proxy-mux.d.ts.map +1 -1
- package/dist/proxy/proxy-mux.js +3 -2
- package/dist/proxy/proxy-mux.js.map +1 -1
- package/dist/proxy/request-codec.d.ts.map +1 -1
- package/dist/proxy/request-codec.js +3 -0
- package/dist/proxy/request-codec.js.map +1 -1
- package/dist/reputation/rating-manager.d.ts.map +1 -1
- package/dist/reputation/rating-manager.js +2 -4
- package/dist/reputation/rating-manager.js.map +1 -1
- package/dist/reputation/report-manager.d.ts.map +1 -1
- package/dist/reputation/report-manager.js +2 -4
- package/dist/reputation/report-manager.js.map +1 -1
- package/dist/routing/default-router.d.ts.map +1 -1
- package/dist/routing/default-router.js +4 -9
- package/dist/routing/default-router.js.map +1 -1
- package/dist/seller-request-handler.d.ts +54 -0
- package/dist/seller-request-handler.d.ts.map +1 -0
- package/dist/seller-request-handler.js +359 -0
- package/dist/seller-request-handler.js.map +1 -0
- package/dist/storage/migrate.d.ts +13 -0
- package/dist/storage/migrate.d.ts.map +1 -0
- package/dist/storage/migrate.js +28 -0
- package/dist/storage/migrate.js.map +1 -0
- package/dist/storage/migrations/channels/001_create_tables.d.ts +3 -0
- package/dist/storage/migrations/channels/001_create_tables.d.ts.map +1 -0
- package/dist/storage/migrations/channels/001_create_tables.js +45 -0
- package/dist/storage/migrations/channels/001_create_tables.js.map +1 -0
- package/dist/storage/migrations/channels/002_add_auth_sig_columns.d.ts +3 -0
- package/dist/storage/migrations/channels/002_add_auth_sig_columns.d.ts.map +1 -0
- package/dist/storage/migrations/channels/002_add_auth_sig_columns.js +19 -0
- package/dist/storage/migrations/channels/002_add_auth_sig_columns.js.map +1 -0
- package/dist/storage/migrations/channels/index.d.ts +3 -0
- package/dist/storage/migrations/channels/index.d.ts.map +1 -0
- package/dist/storage/migrations/channels/index.js +4 -0
- package/dist/storage/migrations/channels/index.js.map +1 -0
- package/dist/storage/migrations/metering/001_create_tables.d.ts +3 -0
- package/dist/storage/migrations/metering/001_create_tables.d.ts.map +1 -0
- package/dist/storage/migrations/metering/001_create_tables.js +80 -0
- package/dist/storage/migrations/metering/001_create_tables.js.map +1 -0
- package/dist/storage/migrations/metering/index.d.ts +3 -0
- package/dist/storage/migrations/metering/index.d.ts.map +1 -0
- package/dist/storage/migrations/metering/index.js +3 -0
- package/dist/storage/migrations/metering/index.js.map +1 -0
- package/dist/types/capability.d.ts +1 -1
- package/dist/types/metering.d.ts +1 -1
- package/dist/types/peer.d.ts +10 -11
- package/dist/types/peer.d.ts.map +1 -1
- package/dist/types/peer.js +7 -3
- package/dist/types/peer.js.map +1 -1
- package/dist/types/protocol.d.ts +22 -70
- package/dist/types/protocol.d.ts.map +1 -1
- package/dist/types/protocol.js +1 -3
- package/dist/types/protocol.js.map +1 -1
- package/dist/types/rating.d.ts +1 -1
- package/dist/types/rating.d.ts.map +1 -1
- package/dist/types/report.d.ts +1 -1
- package/dist/types/report.d.ts.map +1 -1
- package/dist/utils/response-usage.d.ts +10 -0
- package/dist/utils/response-usage.d.ts.map +1 -0
- package/dist/utils/response-usage.js +34 -0
- package/dist/utils/response-usage.js.map +1 -0
- package/package.json +3 -3
|
@@ -1,125 +1,94 @@
|
|
|
1
|
-
import { Contract
|
|
1
|
+
import { Contract } from 'ethers';
|
|
2
2
|
import { BaseEvmClient } from './base-evm-client.js';
|
|
3
|
-
const
|
|
3
|
+
const IDENTITY_REGISTRY_ABI = [
|
|
4
4
|
// Registration
|
|
5
|
-
'function register(
|
|
6
|
-
'function
|
|
7
|
-
'function updateMetadata(uint256 tokenId, string metadataURI) external',
|
|
5
|
+
'function register() external returns (uint256)',
|
|
6
|
+
'function register(string uri) external returns (uint256)',
|
|
8
7
|
// View — identity lookups
|
|
9
|
-
'function
|
|
10
|
-
'function
|
|
11
|
-
|
|
12
|
-
'function
|
|
13
|
-
|
|
14
|
-
'function
|
|
15
|
-
'function updateReputation(uint256 tokenId, tuple(uint8 updateType, uint256 tokenVolume) update) external',
|
|
16
|
-
// Feedback (ERC-8004)
|
|
17
|
-
'function giveFeedback(uint256 agentId, int128 value, uint8 valueDecimals, bytes32 tag1, bytes32 tag2) external',
|
|
18
|
-
'function getSummary(uint256 agentId, bytes32 tag) external view returns (uint256 count, int256 summaryValue, uint8 summaryValueDecimals)',
|
|
19
|
-
'function readFeedback(uint256 agentId, address client, uint256 index) external view returns (tuple(address client, int128 value, uint8 valueDecimals, bytes32 tag1, bytes32 tag2, uint64 timestamp, bool revoked))',
|
|
20
|
-
'function revokeFeedback(uint256 agentId, uint256 index) external',
|
|
21
|
-
'function getFeedbackCount(uint256 agentId, address client) external view returns (uint256)',
|
|
22
|
-
// Admin
|
|
23
|
-
'function setEscrowContract(address _escrow) external',
|
|
24
|
-
'function escrowContract() external view returns (address)',
|
|
25
|
-
'function owner() external view returns (address)',
|
|
8
|
+
'function ownerOf(uint256 agentId) external view returns (address)',
|
|
9
|
+
'function balanceOf(address owner) external view returns (uint256)',
|
|
10
|
+
// Metadata
|
|
11
|
+
'function setMetadata(uint256 agentId, string key, bytes value) external',
|
|
12
|
+
'function getMetadata(uint256 agentId, string key) external view returns (bytes)',
|
|
13
|
+
'function setAgentURI(uint256 agentId, string uri) external',
|
|
26
14
|
];
|
|
27
15
|
export class IdentityClient extends BaseEvmClient {
|
|
28
16
|
constructor(config) {
|
|
29
17
|
super(config.rpcUrl, config.contractAddress);
|
|
30
18
|
}
|
|
31
19
|
// ── Write methods ──────────────────────────────────────────────────
|
|
32
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Register a new agent identity via ERC-8004 IdentityRegistry.
|
|
22
|
+
* Returns the new agentId. The peerId is the signer's EVM address
|
|
23
|
+
* (ownerOf(agentId)), so no separate metadata storage is needed.
|
|
24
|
+
*/
|
|
25
|
+
async register(signer, metadataURI) {
|
|
33
26
|
const connected = this._ensureConnected(signer);
|
|
34
27
|
const signerAddress = await connected.getAddress();
|
|
35
|
-
const contract = new Contract(this._contractAddress,
|
|
28
|
+
const contract = new Contract(this._contractAddress, IDENTITY_REGISTRY_ABI, connected);
|
|
29
|
+
let tx;
|
|
36
30
|
const nonce = await this._reserveNonce(signerAddress);
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
if (metadataURI) {
|
|
32
|
+
tx = await contract.getFunction('register(string)')(metadataURI, { nonce });
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
tx = await contract.getFunction('register()')({ nonce });
|
|
36
|
+
}
|
|
39
37
|
const receipt = await tx.wait();
|
|
40
38
|
if (!receipt)
|
|
41
39
|
throw new Error('Transaction was dropped or replaced');
|
|
42
|
-
|
|
40
|
+
// Extract agentId from Transfer event (ERC-721 Transfer(address,address,uint256))
|
|
41
|
+
const transferTopic = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
|
|
42
|
+
const transferLog = receipt.logs.find((l) => l.topics?.[0] === transferTopic);
|
|
43
|
+
const rawAgentId = transferLog?.topics?.[3];
|
|
44
|
+
return rawAgentId ? Number(BigInt(rawAgentId)) : 0;
|
|
43
45
|
}
|
|
44
|
-
async
|
|
45
|
-
|
|
46
|
-
const signerAddress = await connected.getAddress();
|
|
47
|
-
const contract = new Contract(this._contractAddress, IDENTITY_ABI, connected);
|
|
48
|
-
const nonce = await this._reserveNonce(signerAddress);
|
|
49
|
-
const tx = await contract.getFunction('deregister')(tokenId, { nonce });
|
|
50
|
-
const receipt = await tx.wait();
|
|
51
|
-
if (!receipt)
|
|
52
|
-
throw new Error('Transaction was dropped or replaced');
|
|
53
|
-
return receipt.hash;
|
|
54
|
-
}
|
|
55
|
-
async updateMetadata(signer, tokenId, metadataURI) {
|
|
56
|
-
const connected = this._ensureConnected(signer);
|
|
57
|
-
const signerAddress = await connected.getAddress();
|
|
58
|
-
const contract = new Contract(this._contractAddress, IDENTITY_ABI, connected);
|
|
59
|
-
const nonce = await this._reserveNonce(signerAddress);
|
|
60
|
-
const tx = await contract.getFunction('updateMetadata')(tokenId, metadataURI, { nonce });
|
|
61
|
-
const receipt = await tx.wait();
|
|
62
|
-
if (!receipt)
|
|
63
|
-
throw new Error('Transaction was dropped or replaced');
|
|
64
|
-
return receipt.hash;
|
|
46
|
+
async setMetadata(signer, agentId, key, value) {
|
|
47
|
+
return this._execWrite(signer, IDENTITY_REGISTRY_ABI, 'setMetadata', agentId, key, value);
|
|
65
48
|
}
|
|
66
|
-
async
|
|
67
|
-
|
|
68
|
-
const signerAddress = await connected.getAddress();
|
|
69
|
-
const contract = new Contract(this._contractAddress, IDENTITY_ABI, connected);
|
|
70
|
-
const nonce = await this._reserveNonce(signerAddress);
|
|
71
|
-
const tagBytes = encodeBytes32String(tag);
|
|
72
|
-
const tx = await contract.getFunction('giveFeedback')(agentId, value, 0, tagBytes, tagBytes, { nonce });
|
|
73
|
-
const receipt = await tx.wait();
|
|
74
|
-
if (!receipt)
|
|
75
|
-
throw new Error('Transaction was dropped or replaced');
|
|
76
|
-
return receipt.hash;
|
|
49
|
+
async setAgentURI(signer, agentId, uri) {
|
|
50
|
+
return this._execWrite(signer, IDENTITY_REGISTRY_ABI, 'setAgentURI', agentId, uri);
|
|
77
51
|
}
|
|
78
52
|
// ── View methods ───────────────────────────────────────────────────
|
|
79
53
|
async isRegistered(address) {
|
|
80
|
-
const contract = new Contract(this._contractAddress,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
async getTokenId(address) {
|
|
84
|
-
const contract = new Contract(this._contractAddress, IDENTITY_ABI, this._provider);
|
|
85
|
-
const result = await contract.getFunction('getTokenId')(address);
|
|
86
|
-
return Number(result);
|
|
87
|
-
}
|
|
88
|
-
async getTokenIdByPeerId(peerId) {
|
|
89
|
-
const contract = new Contract(this._contractAddress, IDENTITY_ABI, this._provider);
|
|
90
|
-
const peerIdBytes = keccak256(toUtf8Bytes(peerId));
|
|
91
|
-
const result = await contract.getFunction('getTokenIdByPeerId')(peerIdBytes);
|
|
92
|
-
return Number(result);
|
|
93
|
-
}
|
|
94
|
-
async getPeerId(tokenId) {
|
|
95
|
-
const contract = new Contract(this._contractAddress, IDENTITY_ABI, this._provider);
|
|
96
|
-
return contract.getFunction('getPeerId')(tokenId);
|
|
54
|
+
const contract = new Contract(this._contractAddress, IDENTITY_REGISTRY_ABI, this._provider);
|
|
55
|
+
const balance = await contract.getFunction('balanceOf')(address);
|
|
56
|
+
return Number(balance) > 0;
|
|
97
57
|
}
|
|
98
|
-
async
|
|
99
|
-
const contract = new Contract(this._contractAddress,
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
firstSignCount: Number(result[0]),
|
|
103
|
-
qualifiedProvenSignCount: Number(result[1]),
|
|
104
|
-
unqualifiedProvenSignCount: Number(result[2]),
|
|
105
|
-
ghostCount: Number(result[3]),
|
|
106
|
-
totalQualifiedTokenVolume: result[4],
|
|
107
|
-
lastProvenAt: Number(result[5]),
|
|
108
|
-
};
|
|
58
|
+
async getAgentWallet(agentId) {
|
|
59
|
+
const contract = new Contract(this._contractAddress, IDENTITY_REGISTRY_ABI, this._provider);
|
|
60
|
+
return contract.getFunction('ownerOf')(agentId);
|
|
109
61
|
}
|
|
110
|
-
async
|
|
111
|
-
const
|
|
112
|
-
|
|
62
|
+
async getMetadata(agentId, key) {
|
|
63
|
+
const contract = new Contract(this._contractAddress, IDENTITY_REGISTRY_ABI, this._provider);
|
|
64
|
+
const result = await contract.getFunction('getMetadata')(agentId, key);
|
|
65
|
+
return new Uint8Array(Buffer.from(result.slice(2), 'hex'));
|
|
113
66
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Look up agentId for an owner address by scanning Transfer(0x0, owner, agentId) events.
|
|
69
|
+
* Returns 0 if not found.
|
|
70
|
+
*/
|
|
71
|
+
async getAgentIdByOwner(address) {
|
|
72
|
+
const transferTopic = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
|
|
73
|
+
const zeroAddress = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
74
|
+
const paddedAddress = '0x000000000000000000000000' + address.slice(2).toLowerCase();
|
|
75
|
+
// Query recent blocks in chunks (public RPCs limit to 10k blocks)
|
|
76
|
+
const latestBlock = await this._provider.getBlockNumber();
|
|
77
|
+
const chunkSize = 9999;
|
|
78
|
+
for (let to = latestBlock; to > 0; to -= chunkSize) {
|
|
79
|
+
const from = Math.max(0, to - chunkSize);
|
|
80
|
+
const logs = await this._provider.getLogs({
|
|
81
|
+
address: this._contractAddress,
|
|
82
|
+
topics: [transferTopic, zeroAddress, paddedAddress],
|
|
83
|
+
fromBlock: from,
|
|
84
|
+
toBlock: to,
|
|
85
|
+
});
|
|
86
|
+
if (logs.length > 0) {
|
|
87
|
+
const rawAgentId = logs[logs.length - 1].topics[3];
|
|
88
|
+
return rawAgentId ? Number(BigInt(rawAgentId)) : 0;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return 0;
|
|
123
92
|
}
|
|
124
93
|
}
|
|
125
94
|
//# sourceMappingURL=identity-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity-client.js","sourceRoot":"","sources":["../../../src/payments/evm/identity-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"identity-client.js","sourceRoot":"","sources":["../../../src/payments/evm/identity-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAuB,MAAM,QAAQ,CAAC;AAC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E,EAAE;aACZ,CAAC,CAAC;YACH,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACpB,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACpD,OAAO,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACrD,CAAC;QACH,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC;CACF"}
|
|
@@ -1,21 +1,10 @@
|
|
|
1
|
-
import { Wallet } from 'ethers';
|
|
2
1
|
import type { Identity } from '../../p2p/identity.js';
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
5
|
-
* Domain-separated to ensure the derived key is independent from the Ed25519 key.
|
|
6
|
-
*
|
|
7
|
-
* Derivation: keccak256(ed25519_seed || "evm-payment-key") → secp256k1 private key
|
|
8
|
-
*
|
|
9
|
-
* The Ed25519 seed (identity.privateKey) is 32 bytes. We append a fixed
|
|
10
|
-
* domain separator string to prevent the derived key from colliding with
|
|
11
|
-
* any other use of the same seed. keccak256 produces a 32-byte output
|
|
12
|
-
* which is a valid secp256k1 private key (the probability of hitting an
|
|
13
|
-
* invalid key is astronomically low: ~1/2^128).
|
|
3
|
+
* @deprecated Identity IS the EVM wallet now. Use identity.wallet directly.
|
|
14
4
|
*/
|
|
15
|
-
export declare function identityToEvmWallet(identity: Identity): Wallet;
|
|
5
|
+
export declare function identityToEvmWallet(identity: Identity): import("ethers").Wallet;
|
|
16
6
|
/**
|
|
17
|
-
*
|
|
18
|
-
* This is the address that appears on-chain as the buyer or seller.
|
|
7
|
+
* @deprecated Identity peerId IS the EVM address. Use `'0x' + identity.peerId` or `identity.wallet.address`.
|
|
19
8
|
*/
|
|
20
9
|
export declare function identityToEvmAddress(identity: Identity): string;
|
|
21
10
|
//# sourceMappingURL=keypair.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keypair.d.ts","sourceRoot":"","sources":["../../../src/payments/evm/keypair.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"keypair.d.ts","sourceRoot":"","sources":["../../../src/payments/evm/keypair.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,2BAErD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAE/D"}
|
|
@@ -1,29 +1,13 @@
|
|
|
1
|
-
import { Wallet, keccak256 } from 'ethers';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
* Domain-separated to ensure the derived key is independent from the Ed25519 key.
|
|
5
|
-
*
|
|
6
|
-
* Derivation: keccak256(ed25519_seed || "evm-payment-key") → secp256k1 private key
|
|
7
|
-
*
|
|
8
|
-
* The Ed25519 seed (identity.privateKey) is 32 bytes. We append a fixed
|
|
9
|
-
* domain separator string to prevent the derived key from colliding with
|
|
10
|
-
* any other use of the same seed. keccak256 produces a 32-byte output
|
|
11
|
-
* which is a valid secp256k1 private key (the probability of hitting an
|
|
12
|
-
* invalid key is astronomically low: ~1/2^128).
|
|
2
|
+
* @deprecated Identity IS the EVM wallet now. Use identity.wallet directly.
|
|
13
3
|
*/
|
|
14
4
|
export function identityToEvmWallet(identity) {
|
|
15
|
-
|
|
16
|
-
const combined = new Uint8Array(identity.privateKey.length + domainSeparator.length);
|
|
17
|
-
combined.set(identity.privateKey, 0);
|
|
18
|
-
combined.set(domainSeparator, identity.privateKey.length);
|
|
19
|
-
const privateKey = keccak256(combined);
|
|
20
|
-
return new Wallet(privateKey);
|
|
5
|
+
return identity.wallet;
|
|
21
6
|
}
|
|
22
7
|
/**
|
|
23
|
-
*
|
|
24
|
-
* This is the address that appears on-chain as the buyer or seller.
|
|
8
|
+
* @deprecated Identity peerId IS the EVM address. Use `'0x' + identity.peerId` or `identity.wallet.address`.
|
|
25
9
|
*/
|
|
26
10
|
export function identityToEvmAddress(identity) {
|
|
27
|
-
return
|
|
11
|
+
return identity.wallet.address;
|
|
28
12
|
}
|
|
29
13
|
//# sourceMappingURL=keypair.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keypair.js","sourceRoot":"","sources":["../../../src/payments/evm/keypair.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"keypair.js","sourceRoot":"","sources":["../../../src/payments/evm/keypair.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAkB;IACpD,OAAO,QAAQ,CAAC,MAAM,CAAC;AACzB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAkB;IACrD,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type AbstractSigner } from 'ethers';
|
|
2
|
+
import { BaseEvmClient } from './base-evm-client.js';
|
|
3
|
+
export interface SessionsClientConfig {
|
|
4
|
+
rpcUrl: string;
|
|
5
|
+
contractAddress: string;
|
|
6
|
+
}
|
|
7
|
+
export interface SessionInfo {
|
|
8
|
+
buyer: string;
|
|
9
|
+
seller: string;
|
|
10
|
+
deposit: bigint;
|
|
11
|
+
settled: bigint;
|
|
12
|
+
metadataHash: string;
|
|
13
|
+
deadline: bigint;
|
|
14
|
+
settledAt: bigint;
|
|
15
|
+
closeRequestedAt: bigint;
|
|
16
|
+
status: number;
|
|
17
|
+
}
|
|
18
|
+
export declare class SessionsClient extends BaseEvmClient {
|
|
19
|
+
constructor(config: SessionsClientConfig);
|
|
20
|
+
reserve(signer: AbstractSigner, buyer: string, salt: string, maxAmount: bigint, deadline: bigint, buyerSig: string): Promise<string>;
|
|
21
|
+
settle(signer: AbstractSigner, channelId: string, cumulativeAmount: bigint, metadata: string, buyerSig: string): Promise<string>;
|
|
22
|
+
close(signer: AbstractSigner, channelId: string, finalAmount: bigint, metadata: string, buyerSig: string): Promise<string>;
|
|
23
|
+
requestTimeout(signer: AbstractSigner, channelId: string): Promise<string>;
|
|
24
|
+
withdraw(signer: AbstractSigner, channelId: string): Promise<string>;
|
|
25
|
+
getSession(channelId: string): Promise<SessionInfo>;
|
|
26
|
+
domainSeparator(): Promise<string>;
|
|
27
|
+
getFirstSignCap(): Promise<bigint>;
|
|
28
|
+
computeChannelId(buyer: string, seller: string, salt: string): Promise<string>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=sessions-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessions-client.d.ts","sourceRoot":"","sources":["../../../src/payments/evm/sessions-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAY,MAAM,QAAQ,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;CAChB;AAcD,qBAAa,cAAe,SAAQ,aAAa;gBACnC,MAAM,EAAE,oBAAoB;IAIlC,OAAO,CACX,MAAM,EAAE,cAAc,EACtB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC;IAOZ,MAAM,CACV,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,MAAM,EACxB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC;IAOZ,KAAK,CACT,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC;IAOZ,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI1E,QAAQ,CAAC,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIpE,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAgBnD,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;IAKlC,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;IAKlC,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAIrF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Contract } from 'ethers';
|
|
2
|
+
import { BaseEvmClient } from './base-evm-client.js';
|
|
3
|
+
const SESSIONS_ABI = [
|
|
4
|
+
'function reserve(address buyer, bytes32 salt, uint128 maxAmount, uint256 deadline, bytes buyerSig) external',
|
|
5
|
+
'function settle(bytes32 channelId, uint128 cumulativeAmount, bytes metadata, bytes buyerSig) external',
|
|
6
|
+
'function close(bytes32 channelId, uint128 finalAmount, bytes metadata, bytes buyerSig) external',
|
|
7
|
+
'function requestTimeout(bytes32 channelId) external',
|
|
8
|
+
'function withdraw(bytes32 channelId) external',
|
|
9
|
+
'function sessions(bytes32 channelId) external view returns (address buyer, address seller, uint128 deposit, uint128 settled, bytes32 metadataHash, uint256 deadline, uint256 settledAt, uint256 closeRequestedAt, uint8 status)',
|
|
10
|
+
'function computeChannelId(address buyer, address seller, bytes32 salt) external pure returns (bytes32)',
|
|
11
|
+
'function domainSeparator() external view returns (bytes32)',
|
|
12
|
+
'function FIRST_SIGN_CAP() external view returns (uint256)',
|
|
13
|
+
];
|
|
14
|
+
export class SessionsClient extends BaseEvmClient {
|
|
15
|
+
constructor(config) {
|
|
16
|
+
super(config.rpcUrl, config.contractAddress);
|
|
17
|
+
}
|
|
18
|
+
async reserve(signer, buyer, salt, maxAmount, deadline, buyerSig) {
|
|
19
|
+
return this._execWrite(signer, SESSIONS_ABI, 'reserve', buyer, salt, maxAmount, deadline, buyerSig);
|
|
20
|
+
}
|
|
21
|
+
async settle(signer, channelId, cumulativeAmount, metadata, buyerSig) {
|
|
22
|
+
return this._execWrite(signer, SESSIONS_ABI, 'settle', channelId, cumulativeAmount, metadata, buyerSig);
|
|
23
|
+
}
|
|
24
|
+
async close(signer, channelId, finalAmount, metadata, buyerSig) {
|
|
25
|
+
return this._execWrite(signer, SESSIONS_ABI, 'close', channelId, finalAmount, metadata, buyerSig);
|
|
26
|
+
}
|
|
27
|
+
async requestTimeout(signer, channelId) {
|
|
28
|
+
return this._execWrite(signer, SESSIONS_ABI, 'requestTimeout', channelId);
|
|
29
|
+
}
|
|
30
|
+
async withdraw(signer, channelId) {
|
|
31
|
+
return this._execWrite(signer, SESSIONS_ABI, 'withdraw', channelId);
|
|
32
|
+
}
|
|
33
|
+
async getSession(channelId) {
|
|
34
|
+
const contract = new Contract(this._contractAddress, SESSIONS_ABI, this._provider);
|
|
35
|
+
const result = await contract.getFunction('sessions')(channelId);
|
|
36
|
+
return {
|
|
37
|
+
buyer: result[0],
|
|
38
|
+
seller: result[1],
|
|
39
|
+
deposit: result[2],
|
|
40
|
+
settled: result[3],
|
|
41
|
+
metadataHash: result[4],
|
|
42
|
+
deadline: result[5],
|
|
43
|
+
settledAt: result[6],
|
|
44
|
+
closeRequestedAt: result[7],
|
|
45
|
+
status: Number(result[8]),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async domainSeparator() {
|
|
49
|
+
const contract = new Contract(this._contractAddress, SESSIONS_ABI, this._provider);
|
|
50
|
+
return contract.getFunction('domainSeparator')();
|
|
51
|
+
}
|
|
52
|
+
async getFirstSignCap() {
|
|
53
|
+
const contract = new Contract(this._contractAddress, SESSIONS_ABI, this._provider);
|
|
54
|
+
return contract.getFunction('FIRST_SIGN_CAP')();
|
|
55
|
+
}
|
|
56
|
+
async computeChannelId(buyer, seller, salt) {
|
|
57
|
+
const contract = new Contract(this._contractAddress, SESSIONS_ABI, this._provider);
|
|
58
|
+
return contract.getFunction('computeChannelId')(buyer, seller, salt);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=sessions-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessions-client.js","sourceRoot":"","sources":["../../../src/payments/evm/sessions-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAmBrD,MAAM,YAAY,GAAG;IACnB,6GAA6G;IAC7G,uGAAuG;IACvG,iGAAiG;IACjG,qDAAqD;IACrD,+CAA+C;IAC/C,iOAAiO;IACjO,wGAAwG;IACxG,4DAA4D;IAC5D,2DAA2D;CACnD,CAAC;AAEX,MAAM,OAAO,cAAe,SAAQ,aAAa;IAC/C,YAAY,MAA4B;QACtC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,OAAO,CACX,MAAsB,EACtB,KAAa,EACb,IAAY,EACZ,SAAiB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/identity.js';
|
|
3
2
|
export declare const SPENDING_AUTH_TYPES: {
|
|
4
3
|
SpendingAuth: {
|
|
5
4
|
name: string;
|
|
6
5
|
type: string;
|
|
7
6
|
}[];
|
|
8
7
|
};
|
|
8
|
+
export declare const RESERVE_AUTH_TYPES: {
|
|
9
|
+
ReserveAuth: {
|
|
10
|
+
name: string;
|
|
11
|
+
type: string;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
export declare const SET_OPERATOR_TYPES: {
|
|
15
|
+
SetOperator: {
|
|
16
|
+
name: string;
|
|
17
|
+
type: string;
|
|
18
|
+
}[];
|
|
19
|
+
};
|
|
9
20
|
export interface SpendingAuthMessage {
|
|
10
|
-
|
|
11
|
-
|
|
21
|
+
channelId: string;
|
|
22
|
+
cumulativeAmount: bigint;
|
|
23
|
+
metadataHash: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ReserveAuthMessage {
|
|
26
|
+
channelId: string;
|
|
12
27
|
maxAmount: bigint;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
28
|
+
deadline: bigint;
|
|
29
|
+
}
|
|
30
|
+
export interface SetOperatorMessage {
|
|
31
|
+
operator: string;
|
|
32
|
+
nonce: bigint;
|
|
33
|
+
}
|
|
34
|
+
export interface SpendingAuthMetadata {
|
|
35
|
+
cumulativeInputTokens: bigint;
|
|
36
|
+
cumulativeOutputTokens: bigint;
|
|
37
|
+
cumulativeLatencyMs: bigint;
|
|
38
|
+
cumulativeRequestCount: bigint;
|
|
17
39
|
}
|
|
18
|
-
export declare
|
|
40
|
+
export declare const METADATA_VERSION = 1n;
|
|
41
|
+
export declare function encodeMetadata(metadata: SpendingAuthMetadata): string;
|
|
42
|
+
export declare function computeMetadataHash(metadata: SpendingAuthMetadata): string;
|
|
43
|
+
export declare const ZERO_METADATA: SpendingAuthMetadata;
|
|
44
|
+
export declare const ZERO_METADATA_HASH: string;
|
|
45
|
+
/**
|
|
46
|
+
* Compute the deterministic channelId.
|
|
47
|
+
* Must match: keccak256(abi.encode(buyer, seller, salt))
|
|
48
|
+
*/
|
|
49
|
+
export declare function computeChannelId(buyer: string, seller: string, salt: string): string;
|
|
50
|
+
export declare function makeChannelsDomain(chainId: number, contractAddress: string): TypedDataDomain;
|
|
51
|
+
export declare function makeDepositsDomain(chainId: number, contractAddress: string): TypedDataDomain;
|
|
19
52
|
export declare function signSpendingAuth(signer: AbstractSigner, domain: TypedDataDomain, msg: SpendingAuthMessage): Promise<string>;
|
|
20
|
-
export declare function
|
|
21
|
-
export declare function
|
|
22
|
-
export declare function signMessageEd25519(identity: Identity, message: Uint8Array): Promise<Uint8Array>;
|
|
23
|
-
export declare function verifyMessageEd25519(publicKey: Uint8Array, signature: Uint8Array, message: Uint8Array): Promise<boolean>;
|
|
53
|
+
export declare function signReserveAuth(signer: AbstractSigner, domain: TypedDataDomain, msg: ReserveAuthMessage): Promise<string>;
|
|
54
|
+
export declare function signSetOperator(signer: AbstractSigner, domain: TypedDataDomain, msg: SetOperatorMessage): Promise<string>;
|
|
24
55
|
//# sourceMappingURL=signatures.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signatures.d.ts","sourceRoot":"","sources":["../../../src/payments/evm/signatures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,
|
|
1
|
+
{"version":3,"file":"signatures.d.ts","sourceRoot":"","sources":["../../../src/payments/evm/signatures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAuB,MAAM,QAAQ,CAAC;AAMxF,eAAO,MAAM,mBAAmB;;;;;CAM/B,CAAC;AAEF,eAAO,MAAM,kBAAkB;;;;;CAM9B,CAAC;AAEF,eAAO,MAAM,kBAAkB;;;;;CAK9B,CAAC;AAMF,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,Y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AC,CAEjB;AAED,wBAAsB,eAAe,CACnC,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,eAAe,EACvB,GAAG,EAAE,kBAAkB,GACtB,OAAO,CAAC,MAAM,CAAC,CAEjB"}
|
|
@@ -1,65 +1,82 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbiCoder, keccak256 } from 'ethers';
|
|
2
2
|
// =========================================================================
|
|
3
|
-
// EIP-712
|
|
3
|
+
// EIP-712 Types — AntSeed SpendingAuth (cumulative payment authorization)
|
|
4
4
|
// =========================================================================
|
|
5
5
|
export const SPENDING_AUTH_TYPES = {
|
|
6
6
|
SpendingAuth: [
|
|
7
|
-
{ name: '
|
|
8
|
-
{ name: '
|
|
9
|
-
{ name: '
|
|
10
|
-
|
|
7
|
+
{ name: 'channelId', type: 'bytes32' },
|
|
8
|
+
{ name: 'cumulativeAmount', type: 'uint256' },
|
|
9
|
+
{ name: 'metadataHash', type: 'bytes32' },
|
|
10
|
+
],
|
|
11
|
+
};
|
|
12
|
+
export const RESERVE_AUTH_TYPES = {
|
|
13
|
+
ReserveAuth: [
|
|
14
|
+
{ name: 'channelId', type: 'bytes32' },
|
|
15
|
+
{ name: 'maxAmount', type: 'uint128' },
|
|
11
16
|
{ name: 'deadline', type: 'uint256' },
|
|
12
|
-
{ name: 'previousConsumption', type: 'uint256' },
|
|
13
|
-
{ name: 'previousSessionId', type: 'bytes32' },
|
|
14
17
|
],
|
|
15
18
|
};
|
|
16
|
-
export
|
|
19
|
+
export const SET_OPERATOR_TYPES = {
|
|
20
|
+
SetOperator: [
|
|
21
|
+
{ name: 'operator', type: 'address' },
|
|
22
|
+
{ name: 'nonce', type: 'uint256' },
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
export const METADATA_VERSION = 1n;
|
|
26
|
+
export function encodeMetadata(metadata) {
|
|
27
|
+
const coder = AbiCoder.defaultAbiCoder();
|
|
28
|
+
return coder.encode(['uint256', 'uint256', 'uint256', 'uint256', 'uint256'], [METADATA_VERSION, metadata.cumulativeInputTokens, metadata.cumulativeOutputTokens, metadata.cumulativeLatencyMs, metadata.cumulativeRequestCount]);
|
|
29
|
+
}
|
|
30
|
+
export function computeMetadataHash(metadata) {
|
|
31
|
+
return keccak256(encodeMetadata(metadata));
|
|
32
|
+
}
|
|
33
|
+
export const ZERO_METADATA = {
|
|
34
|
+
cumulativeInputTokens: 0n,
|
|
35
|
+
cumulativeOutputTokens: 0n,
|
|
36
|
+
cumulativeLatencyMs: 0n,
|
|
37
|
+
cumulativeRequestCount: 0n,
|
|
38
|
+
};
|
|
39
|
+
export const ZERO_METADATA_HASH = computeMetadataHash(ZERO_METADATA);
|
|
40
|
+
// =========================================================================
|
|
41
|
+
// Channel ID computation (must match AntseedChannels.computeChannelId)
|
|
42
|
+
// =========================================================================
|
|
43
|
+
/**
|
|
44
|
+
* Compute the deterministic channelId.
|
|
45
|
+
* Must match: keccak256(abi.encode(buyer, seller, salt))
|
|
46
|
+
*/
|
|
47
|
+
export function computeChannelId(buyer, seller, salt) {
|
|
48
|
+
const coder = AbiCoder.defaultAbiCoder();
|
|
49
|
+
return keccak256(coder.encode(['address', 'address', 'bytes32'], [buyer, seller, salt]));
|
|
50
|
+
}
|
|
51
|
+
// =========================================================================
|
|
52
|
+
// EIP-712 Domain helpers
|
|
53
|
+
// =========================================================================
|
|
54
|
+
export function makeChannelsDomain(chainId, contractAddress) {
|
|
17
55
|
return {
|
|
18
|
-
name: '
|
|
56
|
+
name: 'AntseedChannels',
|
|
19
57
|
version: '1',
|
|
20
58
|
chainId,
|
|
21
59
|
verifyingContract: contractAddress,
|
|
22
60
|
};
|
|
23
61
|
}
|
|
24
|
-
export
|
|
25
|
-
return
|
|
62
|
+
export function makeDepositsDomain(chainId, contractAddress) {
|
|
63
|
+
return {
|
|
64
|
+
name: 'AntseedDeposits',
|
|
65
|
+
version: '1',
|
|
66
|
+
chainId,
|
|
67
|
+
verifyingContract: contractAddress,
|
|
68
|
+
};
|
|
26
69
|
}
|
|
27
70
|
// =========================================================================
|
|
28
|
-
//
|
|
71
|
+
// Signing functions — EIP-712 (on-chain)
|
|
29
72
|
// =========================================================================
|
|
30
|
-
export function
|
|
31
|
-
|
|
32
|
-
throw new Error(`sessionId must be 32 bytes, got ${sessionId.length}`);
|
|
33
|
-
if (responseHash.length !== 32)
|
|
34
|
-
throw new Error(`responseHash must be 32 bytes, got ${responseHash.length}`);
|
|
35
|
-
const msg = new Uint8Array(76);
|
|
36
|
-
msg.set(sessionId, 0);
|
|
37
|
-
const totalBuf = new ArrayBuffer(8);
|
|
38
|
-
new DataView(totalBuf).setBigUint64(0, runningTotal, true);
|
|
39
|
-
msg.set(new Uint8Array(totalBuf), 32);
|
|
40
|
-
const countBuf = new ArrayBuffer(4);
|
|
41
|
-
new DataView(countBuf).setUint32(0, requestCount, true);
|
|
42
|
-
msg.set(new Uint8Array(countBuf), 40);
|
|
43
|
-
msg.set(responseHash, 44);
|
|
44
|
-
return msg;
|
|
45
|
-
}
|
|
46
|
-
export function buildAckMessage(sessionId, runningTotal, requestCount) {
|
|
47
|
-
if (sessionId.length !== 32)
|
|
48
|
-
throw new Error(`sessionId must be 32 bytes, got ${sessionId.length}`);
|
|
49
|
-
const msg = new Uint8Array(44);
|
|
50
|
-
msg.set(sessionId, 0);
|
|
51
|
-
const totalBuf = new ArrayBuffer(8);
|
|
52
|
-
new DataView(totalBuf).setBigUint64(0, runningTotal, true);
|
|
53
|
-
msg.set(new Uint8Array(totalBuf), 32);
|
|
54
|
-
const countBuf = new ArrayBuffer(4);
|
|
55
|
-
new DataView(countBuf).setUint32(0, requestCount, true);
|
|
56
|
-
msg.set(new Uint8Array(countBuf), 40);
|
|
57
|
-
return msg;
|
|
73
|
+
export async function signSpendingAuth(signer, domain, msg) {
|
|
74
|
+
return signer.signTypedData(domain, SPENDING_AUTH_TYPES, msg);
|
|
58
75
|
}
|
|
59
|
-
export async function
|
|
60
|
-
return
|
|
76
|
+
export async function signReserveAuth(signer, domain, msg) {
|
|
77
|
+
return signer.signTypedData(domain, RESERVE_AUTH_TYPES, msg);
|
|
61
78
|
}
|
|
62
|
-
export async function
|
|
63
|
-
return
|
|
79
|
+
export async function signSetOperator(signer, domain, msg) {
|
|
80
|
+
return signer.signTypedData(domain, SET_OPERATOR_TYPES, msg);
|
|
64
81
|
}
|
|
65
82
|
//# sourceMappingURL=signatures.js.map
|