@agirails/sdk 2.0.0-beta
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 +183 -0
- package/dist/ACTPClient.d.ts +52 -0
- package/dist/ACTPClient.d.ts.map +1 -0
- package/dist/ACTPClient.js +120 -0
- package/dist/ACTPClient.js.map +1 -0
- package/dist/abi/ACTPKernel.json +1340 -0
- package/dist/abi/ERC20.json +38 -0
- package/dist/abi/EscrowVault.json +64 -0
- package/dist/builders/DeliveryProofBuilder.d.ts +37 -0
- package/dist/builders/DeliveryProofBuilder.d.ts.map +1 -0
- package/dist/builders/DeliveryProofBuilder.js +165 -0
- package/dist/builders/DeliveryProofBuilder.js.map +1 -0
- package/dist/builders/QuoteBuilder.d.ts +68 -0
- package/dist/builders/QuoteBuilder.d.ts.map +1 -0
- package/dist/builders/QuoteBuilder.js +255 -0
- package/dist/builders/QuoteBuilder.js.map +1 -0
- package/dist/builders/index.d.ts +3 -0
- package/dist/builders/index.d.ts.map +1 -0
- package/dist/builders/index.js +10 -0
- package/dist/builders/index.js.map +1 -0
- package/dist/config/networks.d.ts +27 -0
- package/dist/config/networks.d.ts.map +1 -0
- package/dist/config/networks.js +103 -0
- package/dist/config/networks.js.map +1 -0
- package/dist/errors/index.d.ts +38 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +87 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol/ACTPKernel.d.ts +30 -0
- package/dist/protocol/ACTPKernel.d.ts.map +1 -0
- package/dist/protocol/ACTPKernel.js +261 -0
- package/dist/protocol/ACTPKernel.js.map +1 -0
- package/dist/protocol/EASHelper.d.ts +23 -0
- package/dist/protocol/EASHelper.d.ts.map +1 -0
- package/dist/protocol/EASHelper.js +106 -0
- package/dist/protocol/EASHelper.js.map +1 -0
- package/dist/protocol/EscrowVault.d.ts +24 -0
- package/dist/protocol/EscrowVault.d.ts.map +1 -0
- package/dist/protocol/EscrowVault.js +114 -0
- package/dist/protocol/EscrowVault.js.map +1 -0
- package/dist/protocol/EventMonitor.d.ts +18 -0
- package/dist/protocol/EventMonitor.d.ts.map +1 -0
- package/dist/protocol/EventMonitor.js +92 -0
- package/dist/protocol/EventMonitor.js.map +1 -0
- package/dist/protocol/MessageSigner.d.ts +23 -0
- package/dist/protocol/MessageSigner.d.ts.map +1 -0
- package/dist/protocol/MessageSigner.js +178 -0
- package/dist/protocol/MessageSigner.js.map +1 -0
- package/dist/protocol/ProofGenerator.d.ts +22 -0
- package/dist/protocol/ProofGenerator.d.ts.map +1 -0
- package/dist/protocol/ProofGenerator.js +64 -0
- package/dist/protocol/ProofGenerator.js.map +1 -0
- package/dist/protocol/QuoteBuilder.d.ts +2 -0
- package/dist/protocol/QuoteBuilder.d.ts.map +1 -0
- package/dist/protocol/QuoteBuilder.js +7 -0
- package/dist/protocol/QuoteBuilder.js.map +1 -0
- package/dist/types/eip712.d.ts +106 -0
- package/dist/types/eip712.d.ts.map +1 -0
- package/dist/types/eip712.js +84 -0
- package/dist/types/eip712.js.map +1 -0
- package/dist/types/escrow.d.ts +18 -0
- package/dist/types/escrow.d.ts.map +1 -0
- package/dist/types/escrow.js +3 -0
- package/dist/types/escrow.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +22 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/message.d.ts +109 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/message.js +3 -0
- package/dist/types/message.js.map +1 -0
- package/dist/types/state.d.ts +19 -0
- package/dist/types/state.d.ts.map +1 -0
- package/dist/types/state.js +49 -0
- package/dist/types/state.js.map +1 -0
- package/dist/types/transaction.d.ts +36 -0
- package/dist/types/transaction.d.ts.map +1 -0
- package/dist/types/transaction.js +3 -0
- package/dist/types/transaction.js.map +1 -0
- package/dist/utils/IPFSClient.d.ts +37 -0
- package/dist/utils/IPFSClient.d.ts.map +1 -0
- package/dist/utils/IPFSClient.js +128 -0
- package/dist/utils/IPFSClient.js.map +1 -0
- package/dist/utils/NonceManager.d.ts +34 -0
- package/dist/utils/NonceManager.d.ts.map +1 -0
- package/dist/utils/NonceManager.js +114 -0
- package/dist/utils/NonceManager.js.map +1 -0
- package/dist/utils/ReceivedNonceTracker.d.ts +35 -0
- package/dist/utils/ReceivedNonceTracker.d.ts.map +1 -0
- package/dist/utils/ReceivedNonceTracker.js +196 -0
- package/dist/utils/ReceivedNonceTracker.js.map +1 -0
- package/dist/utils/canonicalJson.d.ts +4 -0
- package/dist/utils/canonicalJson.d.ts.map +1 -0
- package/dist/utils/canonicalJson.js +21 -0
- package/dist/utils/canonicalJson.js.map +1 -0
- package/dist/utils/computeTypeHash.d.ts +3 -0
- package/dist/utils/computeTypeHash.d.ts.map +1 -0
- package/dist/utils/computeTypeHash.js +30 -0
- package/dist/utils/computeTypeHash.js.map +1 -0
- package/dist/utils/validation.d.ts +6 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +46 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +73 -0
- package/src/ACTPClient.ts +276 -0
- package/src/__tests__/ProofGenerator.test.ts +124 -0
- package/src/__tests__/QuoteBuilder.test.ts +516 -0
- package/src/__tests__/StateMachine.test.ts +82 -0
- package/src/__tests__/builders/DeliveryProofBuilder.test.ts +581 -0
- package/src/__tests__/integration/ACTPClient.test.ts +263 -0
- package/src/__tests__/integration.test.ts +289 -0
- package/src/__tests__/protocol/EASHelper.test.ts +472 -0
- package/src/__tests__/protocol/EventMonitor.test.ts +382 -0
- package/src/__tests__/security/ACTPKernel.security.test.ts +1167 -0
- package/src/__tests__/security/EscrowVault.security.test.ts +570 -0
- package/src/__tests__/security/MessageSigner.security.test.ts +286 -0
- package/src/__tests__/security/NonceReplay.security.test.ts +501 -0
- package/src/__tests__/security/validation.security.test.ts +376 -0
- package/src/__tests__/utils/IPFSClient.test.ts +262 -0
- package/src/__tests__/utils/NonceManager.test.ts +205 -0
- package/src/__tests__/utils/canonicalJson.test.ts +153 -0
- package/src/abi/ACTPKernel.json +1340 -0
- package/src/abi/ERC20.json +40 -0
- package/src/abi/EscrowVault.json +66 -0
- package/src/builders/DeliveryProofBuilder.ts +326 -0
- package/src/builders/QuoteBuilder.ts +483 -0
- package/src/builders/index.ts +17 -0
- package/src/config/networks.ts +165 -0
- package/src/errors/index.ts +130 -0
- package/src/index.ts +108 -0
- package/src/protocol/ACTPKernel.ts +625 -0
- package/src/protocol/EASHelper.ts +197 -0
- package/src/protocol/EscrowVault.ts +237 -0
- package/src/protocol/EventMonitor.ts +161 -0
- package/src/protocol/MessageSigner.ts +336 -0
- package/src/protocol/ProofGenerator.ts +119 -0
- package/src/protocol/QuoteBuilder.ts +15 -0
- package/src/types/eip712.ts +175 -0
- package/src/types/escrow.ts +26 -0
- package/src/types/index.ts +10 -0
- package/src/types/message.ts +145 -0
- package/src/types/state.ts +77 -0
- package/src/types/transaction.ts +54 -0
- package/src/utils/IPFSClient.ts +248 -0
- package/src/utils/NonceManager.ts +293 -0
- package/src/utils/ReceivedNonceTracker.ts +397 -0
- package/src/utils/canonicalJson.ts +38 -0
- package/src/utils/computeTypeHash.ts +50 -0
- package/src/utils/validation.ts +82 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventMonitor = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
class EventMonitor {
|
|
6
|
+
constructor(kernelContract, _escrowContract) {
|
|
7
|
+
this.kernelContract = kernelContract;
|
|
8
|
+
}
|
|
9
|
+
watchTransaction(txId, callback) {
|
|
10
|
+
const filter = this.kernelContract.filters.StateTransitioned(txId);
|
|
11
|
+
const listener = (_eventTxId, _from, to) => {
|
|
12
|
+
callback(to);
|
|
13
|
+
};
|
|
14
|
+
this.kernelContract.on(filter, listener);
|
|
15
|
+
return () => {
|
|
16
|
+
this.kernelContract.off(filter, listener);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
async waitForState(txId, targetState, timeoutMs = 60000) {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
const timer = setTimeout(() => {
|
|
22
|
+
cleanup();
|
|
23
|
+
reject(new Error(`Timeout waiting for state ${types_1.State[targetState]}`));
|
|
24
|
+
}, timeoutMs);
|
|
25
|
+
const cleanup = this.watchTransaction(txId, (state) => {
|
|
26
|
+
if (state === targetState) {
|
|
27
|
+
clearTimeout(timer);
|
|
28
|
+
cleanup();
|
|
29
|
+
resolve();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async getTransactionHistory(address, role = 'requester') {
|
|
35
|
+
const filter = role === 'requester'
|
|
36
|
+
? this.kernelContract.filters.TransactionCreated(null, null, address)
|
|
37
|
+
: this.kernelContract.filters.TransactionCreated(null, address, null);
|
|
38
|
+
const events = await this.kernelContract.queryFilter(filter);
|
|
39
|
+
return Promise.all(events.map(async (event) => {
|
|
40
|
+
if (!('args' in event)) {
|
|
41
|
+
throw new Error('Event does not contain args (not an EventLog)');
|
|
42
|
+
}
|
|
43
|
+
const txId = event.args?.transactionId;
|
|
44
|
+
const txData = await this.kernelContract.transactions(txId);
|
|
45
|
+
return {
|
|
46
|
+
txId: txData.transactionId,
|
|
47
|
+
requester: txData.requester,
|
|
48
|
+
provider: txData.provider,
|
|
49
|
+
amount: txData.amount,
|
|
50
|
+
state: txData.state,
|
|
51
|
+
createdAt: Number(txData.createdAt),
|
|
52
|
+
deadline: Number(txData.deadline),
|
|
53
|
+
disputeWindow: Number(txData.disputeWindow),
|
|
54
|
+
escrowContract: txData.escrowContract,
|
|
55
|
+
escrowId: txData.escrowId,
|
|
56
|
+
metadata: txData.serviceHash
|
|
57
|
+
};
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
onTransactionCreated(callback) {
|
|
61
|
+
const filter = this.kernelContract.filters.TransactionCreated();
|
|
62
|
+
const listener = async (txId, provider, requester, amount) => {
|
|
63
|
+
callback({ txId, provider, requester, amount });
|
|
64
|
+
};
|
|
65
|
+
this.kernelContract.on(filter, listener);
|
|
66
|
+
return () => {
|
|
67
|
+
this.kernelContract.off(filter, listener);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
onStateChanged(callback) {
|
|
71
|
+
const filter = this.kernelContract.filters.StateTransitioned();
|
|
72
|
+
const listener = (txId, from, to) => {
|
|
73
|
+
callback(txId, from, to);
|
|
74
|
+
};
|
|
75
|
+
this.kernelContract.on(filter, listener);
|
|
76
|
+
return () => {
|
|
77
|
+
this.kernelContract.off(filter, listener);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
onEscrowReleased(callback) {
|
|
81
|
+
const filter = this.kernelContract.filters.EscrowReleased();
|
|
82
|
+
const listener = (txId, amount) => {
|
|
83
|
+
callback(txId, amount);
|
|
84
|
+
};
|
|
85
|
+
this.kernelContract.on(filter, listener);
|
|
86
|
+
return () => {
|
|
87
|
+
this.kernelContract.off(filter, listener);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.EventMonitor = EventMonitor;
|
|
92
|
+
//# sourceMappingURL=EventMonitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventMonitor.js","sourceRoot":"","sources":["../../src/protocol/EventMonitor.ts"],"names":[],"mappings":";;;AACA,oCAA8C;AAK9C,MAAa,YAAY;IACvB,YACmB,cAAwB,EACzC,eAAyB;QADR,mBAAc,GAAd,cAAc,CAAU;IAExC,CAAC;IAMJ,gBAAgB,CAAC,IAAY,EAAE,QAAgC;QAC7D,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAEnE,MAAM,Q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,0 +1,23 @@
|
|
|
1
|
+
import { Signer } from 'ethers';
|
|
2
|
+
import { ACTPMessage, DeliveryProof } from '../types';
|
|
3
|
+
import { QuoteRequestData, QuoteResponseData, DeliveryProofData } from '../types/eip712';
|
|
4
|
+
import { IReceivedNonceTracker } from '../utils/ReceivedNonceTracker';
|
|
5
|
+
export declare class MessageSigner {
|
|
6
|
+
private readonly signer;
|
|
7
|
+
private readonly nonceTracker?;
|
|
8
|
+
private domain;
|
|
9
|
+
constructor(signer: Signer, nonceTracker?: IReceivedNonceTracker | undefined);
|
|
10
|
+
initDomain(kernelAddress: string, chainId?: number): Promise<void>;
|
|
11
|
+
signMessage(message: ACTPMessage): Promise<string>;
|
|
12
|
+
signQuoteRequest(data: QuoteRequestData): Promise<string>;
|
|
13
|
+
signQuoteResponse(data: QuoteResponseData): Promise<string>;
|
|
14
|
+
signDeliveryProof(data: DeliveryProofData): Promise<string>;
|
|
15
|
+
signGeneratedDeliveryProof(proof: DeliveryProof): Promise<string>;
|
|
16
|
+
verifySignature(message: ACTPMessage, signature: string): Promise<boolean>;
|
|
17
|
+
verifySignatureOrThrow(message: ACTPMessage, signature: string): Promise<void>;
|
|
18
|
+
private canonicalizePayload;
|
|
19
|
+
private recursiveSort;
|
|
20
|
+
private didToAddress;
|
|
21
|
+
addressToDID(address: string): string;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=MessageSigner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageSigner.d.ts","sourceRoot":"","sources":["../../src/protocol/MessageSigner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAoB,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEtD,OAAO,EAGL,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EAElB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAwBtE,qBAAa,aAAa;IAItB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IAJhC,OAAO,CAAC,MAAM,CAA6B;gBAGxB,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,qBAAqB,YAAA;IAQjD,UAAU,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoClE,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAqClD,gBAAgB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC;IAazD,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;IAa3D,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;IAa3D,0BAA0B,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC;IAWjE,eAAe,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAuD1E,sBAAsB,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiDpF,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,aAAa;IA8BrB,OAAO,CAAC,YAAY;IAgBpB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;CAOtC"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageSigner = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
const eip712_1 = require("../types/eip712");
|
|
7
|
+
class MessageSigner {
|
|
8
|
+
constructor(signer, nonceTracker) {
|
|
9
|
+
this.signer = signer;
|
|
10
|
+
this.nonceTracker = nonceTracker;
|
|
11
|
+
this.domain = null;
|
|
12
|
+
}
|
|
13
|
+
async initDomain(kernelAddress, chainId) {
|
|
14
|
+
let resolvedChainId;
|
|
15
|
+
if (chainId !== undefined) {
|
|
16
|
+
resolvedChainId = chainId;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
try {
|
|
20
|
+
if (this.signer.provider) {
|
|
21
|
+
const network = await this.signer.provider.getNetwork();
|
|
22
|
+
resolvedChainId = Number(network.chainId);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
resolvedChainId = 84532;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
resolvedChainId = 84532;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
this.domain = {
|
|
33
|
+
name: 'ACTP',
|
|
34
|
+
version: '1.0',
|
|
35
|
+
chainId: resolvedChainId,
|
|
36
|
+
verifyingContract: kernelAddress
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async signMessage(message) {
|
|
40
|
+
if (!this.domain) {
|
|
41
|
+
throw new Error('Domain not initialized. Call initDomain() first.');
|
|
42
|
+
}
|
|
43
|
+
const { type, version, from, to, timestamp, nonce, signature, ...payload } = message;
|
|
44
|
+
const abiCoder = ethers_1.AbiCoder.defaultAbiCoder();
|
|
45
|
+
const payloadBytes = abiCoder.encode(['string'], [this.canonicalizePayload(payload)]);
|
|
46
|
+
const typedMessage = {
|
|
47
|
+
type,
|
|
48
|
+
version,
|
|
49
|
+
from,
|
|
50
|
+
to,
|
|
51
|
+
timestamp,
|
|
52
|
+
nonce,
|
|
53
|
+
payload: payloadBytes
|
|
54
|
+
};
|
|
55
|
+
const messageTypes = (0, eip712_1.getMessageTypes)('default');
|
|
56
|
+
const signer = this.signer;
|
|
57
|
+
const sig = await signer.signTypedData(this.domain, messageTypes, typedMessage);
|
|
58
|
+
return sig;
|
|
59
|
+
}
|
|
60
|
+
async signQuoteRequest(data) {
|
|
61
|
+
if (!this.domain) {
|
|
62
|
+
throw new Error('Domain not initialized. Call initDomain() first.');
|
|
63
|
+
}
|
|
64
|
+
const messageTypes = (0, eip712_1.getMessageTypes)('quote.request');
|
|
65
|
+
const signer = this.signer;
|
|
66
|
+
return await signer.signTypedData(this.domain, messageTypes, data);
|
|
67
|
+
}
|
|
68
|
+
async signQuoteResponse(data) {
|
|
69
|
+
if (!this.domain) {
|
|
70
|
+
throw new Error('Domain not initialized. Call initDomain() first.');
|
|
71
|
+
}
|
|
72
|
+
const messageTypes = (0, eip712_1.getMessageTypes)('quote.response');
|
|
73
|
+
const signer = this.signer;
|
|
74
|
+
return await signer.signTypedData(this.domain, messageTypes, data);
|
|
75
|
+
}
|
|
76
|
+
async signDeliveryProof(data) {
|
|
77
|
+
if (!this.domain) {
|
|
78
|
+
throw new Error('Domain not initialized. Call initDomain() first.');
|
|
79
|
+
}
|
|
80
|
+
const messageTypes = (0, eip712_1.getMessageTypes)('delivery.proof');
|
|
81
|
+
const signer = this.signer;
|
|
82
|
+
return await signer.signTypedData(this.domain, messageTypes, data);
|
|
83
|
+
}
|
|
84
|
+
async signGeneratedDeliveryProof(proof) {
|
|
85
|
+
const typedData = (0, eip712_1.deliveryProofDataFromProof)(proof);
|
|
86
|
+
return await this.signDeliveryProof(typedData);
|
|
87
|
+
}
|
|
88
|
+
async verifySignature(message, signature) {
|
|
89
|
+
if (!this.domain) {
|
|
90
|
+
throw new Error('Domain not initialized. Call initDomain() first.');
|
|
91
|
+
}
|
|
92
|
+
const { type, version, from, to, timestamp, nonce, signature: _, ...payload } = message;
|
|
93
|
+
const abiCoder = ethers_1.AbiCoder.defaultAbiCoder();
|
|
94
|
+
const payloadBytes = abiCoder.encode(['string'], [this.canonicalizePayload(payload)]);
|
|
95
|
+
const typedMessage = {
|
|
96
|
+
type,
|
|
97
|
+
version,
|
|
98
|
+
from,
|
|
99
|
+
to,
|
|
100
|
+
timestamp,
|
|
101
|
+
nonce,
|
|
102
|
+
payload: payloadBytes
|
|
103
|
+
};
|
|
104
|
+
const messageTypes = (0, eip712_1.getMessageTypes)('default');
|
|
105
|
+
const recoveredAddress = ethers_1.ethers.verifyTypedData(this.domain, messageTypes, typedMessage, signature);
|
|
106
|
+
const expectedAddress = this.didToAddress(from);
|
|
107
|
+
if (recoveredAddress.toLowerCase() !== expectedAddress.toLowerCase()) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
if (this.nonceTracker) {
|
|
111
|
+
const nonceValidation = this.nonceTracker.validateAndRecord(from, type, nonce);
|
|
112
|
+
if (!nonceValidation.valid) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
async verifySignatureOrThrow(message, signature) {
|
|
119
|
+
if (!this.domain) {
|
|
120
|
+
throw new Error('Domain not initialized');
|
|
121
|
+
}
|
|
122
|
+
const { type, version, from, to, timestamp, nonce, signature: _, ...payload } = message;
|
|
123
|
+
const abiCoder = ethers_1.AbiCoder.defaultAbiCoder();
|
|
124
|
+
const payloadBytes = abiCoder.encode(['string'], [this.canonicalizePayload(payload)]);
|
|
125
|
+
const typedMessage = { type, version, from, to, timestamp, nonce, payload: payloadBytes };
|
|
126
|
+
const messageTypes = (0, eip712_1.getMessageTypes)('default');
|
|
127
|
+
const recoveredAddress = ethers_1.ethers.verifyTypedData(this.domain, messageTypes, typedMessage, signature);
|
|
128
|
+
const expectedAddress = this.didToAddress(from);
|
|
129
|
+
if (recoveredAddress.toLowerCase() !== expectedAddress.toLowerCase()) {
|
|
130
|
+
throw new errors_1.SignatureVerificationError(expectedAddress, recoveredAddress);
|
|
131
|
+
}
|
|
132
|
+
if (this.nonceTracker) {
|
|
133
|
+
const nonceValidation = this.nonceTracker.validateAndRecord(from, type, nonce);
|
|
134
|
+
if (!nonceValidation.valid) {
|
|
135
|
+
throw new Error(`Nonce replay attack detected: ${nonceValidation.reason}. ` +
|
|
136
|
+
`Received nonce: ${nonceValidation.receivedNonce}. ` +
|
|
137
|
+
(nonceValidation.expectedMinimum ? `Expected minimum: ${nonceValidation.expectedMinimum}` : ''));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
canonicalizePayload(payload) {
|
|
142
|
+
return JSON.stringify(this.recursiveSort(payload));
|
|
143
|
+
}
|
|
144
|
+
recursiveSort(obj) {
|
|
145
|
+
if (obj === null || obj === undefined) {
|
|
146
|
+
return obj;
|
|
147
|
+
}
|
|
148
|
+
if (Array.isArray(obj)) {
|
|
149
|
+
return obj.map((item) => this.recursiveSort(item));
|
|
150
|
+
}
|
|
151
|
+
if (typeof obj === 'object' && obj.constructor === Object) {
|
|
152
|
+
const sortedKeys = Object.keys(obj).sort();
|
|
153
|
+
const canonical = {};
|
|
154
|
+
for (const key of sortedKeys) {
|
|
155
|
+
canonical[key] = this.recursiveSort(obj[key]);
|
|
156
|
+
}
|
|
157
|
+
return canonical;
|
|
158
|
+
}
|
|
159
|
+
return obj;
|
|
160
|
+
}
|
|
161
|
+
didToAddress(did) {
|
|
162
|
+
if (did.startsWith('did:ethr:')) {
|
|
163
|
+
return did.replace('did:ethr:', '');
|
|
164
|
+
}
|
|
165
|
+
if (ethers_1.ethers.isAddress(did)) {
|
|
166
|
+
return did;
|
|
167
|
+
}
|
|
168
|
+
throw new Error(`Invalid DID format: ${did}`);
|
|
169
|
+
}
|
|
170
|
+
addressToDID(address) {
|
|
171
|
+
if (!ethers_1.ethers.isAddress(address)) {
|
|
172
|
+
throw new Error(`Invalid Ethereum address: ${address}`);
|
|
173
|
+
}
|
|
174
|
+
return `did:ethr:${address}`;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.MessageSigner = MessageSigner;
|
|
178
|
+
//# sourceMappingURL=MessageSigner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageSigner.js","sourceRoot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ytesLike } from 'ethers';
|
|
2
|
+
import { DeliveryProof } from '../types';
|
|
3
|
+
import { DeliveryProofData } from '../types/eip712';
|
|
4
|
+
export declare class ProofGenerator {
|
|
5
|
+
hashContent(content: string | Buffer): string;
|
|
6
|
+
generateDeliveryProof(params: {
|
|
7
|
+
txId: string;
|
|
8
|
+
deliverable: string | Buffer;
|
|
9
|
+
deliveryUrl?: string;
|
|
10
|
+
metadata?: Record<string, any>;
|
|
11
|
+
}): DeliveryProof;
|
|
12
|
+
toDeliveryProofTypedData(proof: DeliveryProof): DeliveryProofData;
|
|
13
|
+
encodeProof(proof: DeliveryProof): BytesLike;
|
|
14
|
+
decodeProof(proofData: BytesLike): {
|
|
15
|
+
txId: string;
|
|
16
|
+
contentHash: string;
|
|
17
|
+
timestamp: number;
|
|
18
|
+
};
|
|
19
|
+
verifyDeliverable(deliverable: string | Buffer, expectedHash: string): boolean;
|
|
20
|
+
hashFromUrl(url: string): Promise<string>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=ProofGenerator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProofGenerator.d.ts","sourceRoot":"","sources":["../../src/protocol/ProofGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,SAAS,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAA8B,MAAM,iBAAiB,CAAC;AAMhF,qBAAa,cAAc;IAKzB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;IAY7C,qBAAqB,CAAC,MAAM,EAAE;QAC5B,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;QAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAChC,GAAG,aAAa;IA8BjB,wBAAwB,CAAC,KAAK,EAAE,aAAa,GAAG,iBAAiB;IAOjE,WAAW,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS;IAW5C,WAAW,CAAC,SAAS,EAAE,SAAS,GAAG;QACjC,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;KACnB;IAiBD,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO;IAQxE,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAWhD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProofGenerator = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const eip712_1 = require("../types/eip712");
|
|
6
|
+
class ProofGenerator {
|
|
7
|
+
hashContent(content) {
|
|
8
|
+
const buffer = typeof content === 'string' ? (0, ethers_1.toUtf8Bytes)(content) : content;
|
|
9
|
+
return (0, ethers_1.keccak256)(buffer);
|
|
10
|
+
}
|
|
11
|
+
generateDeliveryProof(params) {
|
|
12
|
+
const { txId, deliverable, deliveryUrl, metadata = {} } = params;
|
|
13
|
+
const contentHash = this.hashContent(deliverable);
|
|
14
|
+
const size = typeof deliverable === 'string'
|
|
15
|
+
? Buffer.from(deliverable).length
|
|
16
|
+
: deliverable.length;
|
|
17
|
+
const { size: _ignoredSize, mimeType: _ignoredMimeType, ...userMetadata } = metadata;
|
|
18
|
+
return {
|
|
19
|
+
type: 'delivery.proof',
|
|
20
|
+
txId,
|
|
21
|
+
contentHash,
|
|
22
|
+
timestamp: Date.now(),
|
|
23
|
+
deliveryUrl,
|
|
24
|
+
metadata: {
|
|
25
|
+
...userMetadata,
|
|
26
|
+
size,
|
|
27
|
+
mimeType: metadata.mimeType || 'application/octet-stream'
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
toDeliveryProofTypedData(proof) {
|
|
32
|
+
return (0, eip712_1.deliveryProofDataFromProof)(proof);
|
|
33
|
+
}
|
|
34
|
+
encodeProof(proof) {
|
|
35
|
+
const abiCoder = ethers_1.AbiCoder.defaultAbiCoder();
|
|
36
|
+
return abiCoder.encode(['bytes32', 'bytes32', 'uint256'], [proof.txId, proof.contentHash, proof.timestamp]);
|
|
37
|
+
}
|
|
38
|
+
decodeProof(proofData) {
|
|
39
|
+
const abiCoder = ethers_1.AbiCoder.defaultAbiCoder();
|
|
40
|
+
const [txId, contentHash, timestamp] = abiCoder.decode(['bytes32', 'bytes32', 'uint256'], proofData);
|
|
41
|
+
return {
|
|
42
|
+
txId,
|
|
43
|
+
contentHash,
|
|
44
|
+
timestamp: Number(timestamp)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
verifyDeliverable(deliverable, expectedHash) {
|
|
48
|
+
const actualHash = this.hashContent(deliverable);
|
|
49
|
+
return actualHash.toLowerCase() === expectedHash.toLowerCase();
|
|
50
|
+
}
|
|
51
|
+
async hashFromUrl(url) {
|
|
52
|
+
try {
|
|
53
|
+
const response = await fetch(url);
|
|
54
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
55
|
+
const buffer = Buffer.from(arrayBuffer);
|
|
56
|
+
return this.hashContent(buffer);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
throw new Error(`Failed to fetch content from ${url}: ${error}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.ProofGenerator = ProofGenerator;
|
|
64
|
+
//# sourceMappingURL=ProofGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProofGenerator.js","sourceRoot":"","sources":["../../src/protocol/ProofGenerator.ts"],"names":[],"mappings":";;;AAAA,mCAAqE;AAErE,4CAAgF;AAMhF,MAAa,cAAc;I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AA0B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AIP2QuoteTypes = exports.QuoteBuilder = void 0;
|
|
4
|
+
var QuoteBuilder_1 = require("../builders/QuoteBuilder");
|
|
5
|
+
Object.defineProperty(exports, "QuoteBuilder", { enumerable: true, get: function () { return QuoteBuilder_1.QuoteBuilder; } });
|
|
6
|
+
Object.defineProperty(exports, "AIP2QuoteTypes", { enumerable: true, get: function () { return QuoteBuilder_1.AIP2QuoteTypes; } });
|
|
7
|
+
//# sourceMappingURL=QuoteBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QuoteBuilder.js","sourceRoot":"","sources":["../../src/protocol/QuoteBuilder.ts"],"names":[],"mappings":";;;AASA,yDAKkC;AAJhC,4GAAA,YAAY,OAAA;AAGZ,8GAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { DeliveryProof } from './message';
|
|
2
|
+
export interface EIP712Domain {
|
|
3
|
+
name: string;
|
|
4
|
+
version: string;
|
|
5
|
+
chainId: number;
|
|
6
|
+
verifyingContract: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const QuoteRequestTypes: {
|
|
9
|
+
QuoteRequest: {
|
|
10
|
+
name: string;
|
|
11
|
+
type: string;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
export interface QuoteRequestData {
|
|
15
|
+
from: string;
|
|
16
|
+
to: string;
|
|
17
|
+
timestamp: number;
|
|
18
|
+
nonce: string;
|
|
19
|
+
serviceType: string;
|
|
20
|
+
requirements: string;
|
|
21
|
+
deadline: number;
|
|
22
|
+
disputeWindow: number;
|
|
23
|
+
}
|
|
24
|
+
export declare const QuoteResponseTypes: {
|
|
25
|
+
QuoteResponse: {
|
|
26
|
+
name: string;
|
|
27
|
+
type: string;
|
|
28
|
+
}[];
|
|
29
|
+
};
|
|
30
|
+
export interface QuoteResponseData {
|
|
31
|
+
from: string;
|
|
32
|
+
to: string;
|
|
33
|
+
timestamp: number;
|
|
34
|
+
nonce: string;
|
|
35
|
+
requestId: string;
|
|
36
|
+
price: string;
|
|
37
|
+
currency: string;
|
|
38
|
+
deliveryTime: number;
|
|
39
|
+
terms: string;
|
|
40
|
+
}
|
|
41
|
+
export declare const DeliveryProofTypes: {
|
|
42
|
+
DeliveryProof: {
|
|
43
|
+
name: string;
|
|
44
|
+
type: string;
|
|
45
|
+
}[];
|
|
46
|
+
};
|
|
47
|
+
export interface DeliveryProofData {
|
|
48
|
+
txId: string;
|
|
49
|
+
contentHash: string;
|
|
50
|
+
timestamp: number;
|
|
51
|
+
deliveryUrl: string;
|
|
52
|
+
size: number;
|
|
53
|
+
mimeType: string;
|
|
54
|
+
}
|
|
55
|
+
export declare function deliveryProofDataFromProof(proof: DeliveryProof): DeliveryProofData;
|
|
56
|
+
export declare const AIP4DeliveryProofTypes: {
|
|
57
|
+
DeliveryProof: {
|
|
58
|
+
name: string;
|
|
59
|
+
type: string;
|
|
60
|
+
}[];
|
|
61
|
+
};
|
|
62
|
+
export interface AIP4DeliveryProofData {
|
|
63
|
+
txId: string;
|
|
64
|
+
provider: string;
|
|
65
|
+
consumer: string;
|
|
66
|
+
resultCID: string;
|
|
67
|
+
resultHash: string;
|
|
68
|
+
easAttestationUID: string;
|
|
69
|
+
deliveredAt: number;
|
|
70
|
+
chainId: number;
|
|
71
|
+
nonce: number;
|
|
72
|
+
}
|
|
73
|
+
export declare const ACTPMessageTypes: {
|
|
74
|
+
ACTPMessage: {
|
|
75
|
+
name: string;
|
|
76
|
+
type: string;
|
|
77
|
+
}[];
|
|
78
|
+
};
|
|
79
|
+
export declare const MESSAGE_TYPES: {
|
|
80
|
+
'quote.request': {
|
|
81
|
+
QuoteRequest: {
|
|
82
|
+
name: string;
|
|
83
|
+
type: string;
|
|
84
|
+
}[];
|
|
85
|
+
};
|
|
86
|
+
'quote.response': {
|
|
87
|
+
QuoteResponse: {
|
|
88
|
+
name: string;
|
|
89
|
+
type: string;
|
|
90
|
+
}[];
|
|
91
|
+
};
|
|
92
|
+
'delivery.proof': {
|
|
93
|
+
DeliveryProof: {
|
|
94
|
+
name: string;
|
|
95
|
+
type: string;
|
|
96
|
+
}[];
|
|
97
|
+
};
|
|
98
|
+
default: {
|
|
99
|
+
ACTPMessage: {
|
|
100
|
+
name: string;
|
|
101
|
+
type: string;
|
|
102
|
+
}[];
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
export declare function getMessageTypes(messageType: string): Record<string, any>;
|
|
106
|
+
//# sourceMappingURL=eip712.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eip712.d.ts","sourceRoot":"","sources":["../../src/types/eip712.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAY1C,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAMD,eAAO,MAAM,iBAAiB;;;;;CAW7B,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;CACvB;AAMD,eAAO,MAAM,kBAAkB;;;;;CAY9B,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf;AAMD,eAAO,MAAM,kBAAkB;;;;;CAS9B,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,aAAa,GAAG,iBAAiB,CASlF;AAMD,eAAO,MAAM,sBAAsB;;;;;CAYlC,CAAC;AAEF,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAKD,eAAO,MAAM,gBAAgB;;;;;CAU5B,CAAC;AAKF,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;CAMzB,CAAC;AAKF,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAExE"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MESSAGE_TYPES = exports.ACTPMessageTypes = exports.AIP4DeliveryProofTypes = exports.DeliveryProofTypes = exports.QuoteResponseTypes = exports.QuoteRequestTypes = void 0;
|
|
4
|
+
exports.deliveryProofDataFromProof = deliveryProofDataFromProof;
|
|
5
|
+
exports.getMessageTypes = getMessageTypes;
|
|
6
|
+
exports.QuoteRequestTypes = {
|
|
7
|
+
QuoteRequest: [
|
|
8
|
+
{ name: 'from', type: 'string' },
|
|
9
|
+
{ name: 'to', type: 'string' },
|
|
10
|
+
{ name: 'timestamp', type: 'uint256' },
|
|
11
|
+
{ name: 'nonce', type: 'bytes32' },
|
|
12
|
+
{ name: 'serviceType', type: 'string' },
|
|
13
|
+
{ name: 'requirements', type: 'string' },
|
|
14
|
+
{ name: 'deadline', type: 'uint256' },
|
|
15
|
+
{ name: 'disputeWindow', type: 'uint256' }
|
|
16
|
+
]
|
|
17
|
+
};
|
|
18
|
+
exports.QuoteResponseTypes = {
|
|
19
|
+
QuoteResponse: [
|
|
20
|
+
{ name: 'from', type: 'string' },
|
|
21
|
+
{ name: 'to', type: 'string' },
|
|
22
|
+
{ name: 'timestamp', type: 'uint256' },
|
|
23
|
+
{ name: 'nonce', type: 'bytes32' },
|
|
24
|
+
{ name: 'requestId', type: 'bytes32' },
|
|
25
|
+
{ name: 'price', type: 'uint256' },
|
|
26
|
+
{ name: 'currency', type: 'address' },
|
|
27
|
+
{ name: 'deliveryTime', type: 'uint256' },
|
|
28
|
+
{ name: 'terms', type: 'string' }
|
|
29
|
+
]
|
|
30
|
+
};
|
|
31
|
+
exports.DeliveryProofTypes = {
|
|
32
|
+
DeliveryProof: [
|
|
33
|
+
{ name: 'txId', type: 'bytes32' },
|
|
34
|
+
{ name: 'contentHash', type: 'bytes32' },
|
|
35
|
+
{ name: 'timestamp', type: 'uint256' },
|
|
36
|
+
{ name: 'deliveryUrl', type: 'string' },
|
|
37
|
+
{ name: 'size', type: 'uint256' },
|
|
38
|
+
{ name: 'mimeType', type: 'string' }
|
|
39
|
+
]
|
|
40
|
+
};
|
|
41
|
+
function deliveryProofDataFromProof(proof) {
|
|
42
|
+
return {
|
|
43
|
+
txId: proof.txId,
|
|
44
|
+
contentHash: proof.contentHash,
|
|
45
|
+
timestamp: proof.timestamp,
|
|
46
|
+
deliveryUrl: proof.deliveryUrl || '',
|
|
47
|
+
size: proof.metadata.size,
|
|
48
|
+
mimeType: proof.metadata.mimeType
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
exports.AIP4DeliveryProofTypes = {
|
|
52
|
+
DeliveryProof: [
|
|
53
|
+
{ name: 'txId', type: 'bytes32' },
|
|
54
|
+
{ name: 'provider', type: 'string' },
|
|
55
|
+
{ name: 'consumer', type: 'string' },
|
|
56
|
+
{ name: 'resultCID', type: 'string' },
|
|
57
|
+
{ name: 'resultHash', type: 'bytes32' },
|
|
58
|
+
{ name: 'easAttestationUID', type: 'bytes32' },
|
|
59
|
+
{ name: 'deliveredAt', type: 'uint256' },
|
|
60
|
+
{ name: 'chainId', type: 'uint256' },
|
|
61
|
+
{ name: 'nonce', type: 'uint256' }
|
|
62
|
+
]
|
|
63
|
+
};
|
|
64
|
+
exports.ACTPMessageTypes = {
|
|
65
|
+
ACTPMessage: [
|
|
66
|
+
{ name: 'type', type: 'string' },
|
|
67
|
+
{ name: 'version', type: 'string' },
|
|
68
|
+
{ name: 'from', type: 'string' },
|
|
69
|
+
{ name: 'to', type: 'string' },
|
|
70
|
+
{ name: 'timestamp', type: 'uint256' },
|
|
71
|
+
{ name: 'nonce', type: 'bytes32' },
|
|
72
|
+
{ name: 'payload', type: 'bytes' }
|
|
73
|
+
]
|
|
74
|
+
};
|
|
75
|
+
exports.MESSAGE_TYPES = {
|
|
76
|
+
'quote.request': exports.QuoteRequestTypes,
|
|
77
|
+
'quote.response': exports.QuoteResponseTypes,
|
|
78
|
+
'delivery.proof': exports.DeliveryProofTypes,
|
|
79
|
+
default: exports.ACTPMessageTypes
|
|
80
|
+
};
|
|
81
|
+
function getMessageTypes(messageType) {
|
|
82
|
+
return exports.MESSAGE_TYPES[messageType] || exports.MESSAGE_TYPES.default;
|
|
83
|
+
}
|
|
84
|
+
//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