@agirails/sdk 2.0.0 → 2.0.1-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 +108 -116
- package/dist/ACTPClient.d.ts +33 -456
- package/dist/ACTPClient.d.ts.map +1 -1
- package/dist/ACTPClient.js +93 -477
- package/dist/ACTPClient.js.map +1 -1
- package/dist/abi/EscrowVault.json +38 -106
- package/dist/builders/DeliveryProofBuilder.d.ts +1 -60
- package/dist/builders/DeliveryProofBuilder.d.ts.map +1 -1
- package/dist/builders/DeliveryProofBuilder.js +5 -81
- package/dist/builders/DeliveryProofBuilder.js.map +1 -1
- package/dist/builders/QuoteBuilder.d.ts +0 -101
- package/dist/builders/QuoteBuilder.d.ts.map +1 -1
- package/dist/builders/QuoteBuilder.js +3 -120
- package/dist/builders/QuoteBuilder.js.map +1 -1
- package/dist/builders/index.d.ts +0 -4
- package/dist/builders/index.d.ts.map +1 -1
- package/dist/builders/index.js +0 -4
- package/dist/builders/index.js.map +1 -1
- package/dist/config/networks.d.ts +0 -28
- package/dist/config/networks.d.ts.map +1 -1
- package/dist/config/networks.js +12 -60
- package/dist/config/networks.js.map +1 -1
- package/dist/errors/index.d.ts +2 -165
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +2 -260
- package/dist/errors/index.js.map +1 -1
- package/dist/index.d.ts +13 -61
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -141
- package/dist/index.js.map +1 -1
- package/dist/protocol/ACTPKernel.d.ts +2 -229
- package/dist/protocol/ACTPKernel.d.ts.map +1 -1
- package/dist/protocol/ACTPKernel.js +33 -367
- package/dist/protocol/ACTPKernel.js.map +1 -1
- package/dist/protocol/EASHelper.d.ts +2 -57
- package/dist/protocol/EASHelper.d.ts.map +1 -1
- package/dist/protocol/EASHelper.js +37 -230
- package/dist/protocol/EASHelper.js.map +1 -1
- package/dist/protocol/EscrowVault.d.ts +2 -93
- package/dist/protocol/EscrowVault.d.ts.map +1 -1
- package/dist/protocol/EscrowVault.js +33 -122
- package/dist/protocol/EscrowVault.js.map +1 -1
- package/dist/protocol/EventMonitor.d.ts +1 -45
- package/dist/protocol/EventMonitor.d.ts.map +1 -1
- package/dist/protocol/EventMonitor.js +8 -64
- package/dist/protocol/EventMonitor.js.map +1 -1
- package/dist/protocol/MessageSigner.d.ts +2 -116
- package/dist/protocol/MessageSigner.d.ts.map +1 -1
- package/dist/protocol/MessageSigner.js +9 -215
- package/dist/protocol/MessageSigner.js.map +1 -1
- package/dist/protocol/ProofGenerator.d.ts +0 -93
- package/dist/protocol/ProofGenerator.d.ts.map +1 -1
- package/dist/protocol/ProofGenerator.js +9 -194
- package/dist/protocol/ProofGenerator.js.map +1 -1
- package/dist/protocol/QuoteBuilder.d.ts +0 -8
- package/dist/protocol/QuoteBuilder.d.ts.map +1 -1
- package/dist/protocol/QuoteBuilder.js +0 -8
- package/dist/protocol/QuoteBuilder.js.map +1 -1
- package/dist/types/eip712.d.ts +0 -34
- package/dist/types/eip712.d.ts.map +1 -1
- package/dist/types/eip712.js +5 -31
- package/dist/types/eip712.js.map +1 -1
- package/dist/types/escrow.d.ts +10 -17
- package/dist/types/escrow.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +0 -8
- package/dist/types/index.js.map +1 -1
- package/dist/types/message.d.ts +0 -32
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/message.js +0 -4
- package/dist/types/message.js.map +1 -1
- package/dist/types/state.d.ts +0 -28
- package/dist/types/state.d.ts.map +1 -1
- package/dist/types/state.js +6 -37
- package/dist/types/state.js.map +1 -1
- package/dist/types/transaction.d.ts +0 -17
- package/dist/types/transaction.d.ts.map +1 -1
- package/dist/utils/IPFSClient.d.ts +0 -113
- package/dist/utils/IPFSClient.d.ts.map +1 -1
- package/dist/utils/IPFSClient.js +7 -128
- package/dist/utils/IPFSClient.js.map +1 -1
- package/dist/utils/NonceManager.d.ts +1 -234
- package/dist/utils/NonceManager.d.ts.map +1 -1
- package/dist/utils/NonceManager.js +7 -372
- package/dist/utils/NonceManager.js.map +1 -1
- package/dist/utils/ReceivedNonceTracker.d.ts +0 -175
- package/dist/utils/ReceivedNonceTracker.d.ts.map +1 -1
- package/dist/utils/ReceivedNonceTracker.js +5 -261
- package/dist/utils/ReceivedNonceTracker.js.map +1 -1
- package/dist/utils/canonicalJson.d.ts +0 -22
- package/dist/utils/canonicalJson.d.ts.map +1 -1
- package/dist/utils/canonicalJson.js +3 -26
- package/dist/utils/canonicalJson.js.map +1 -1
- package/dist/utils/computeTypeHash.d.ts +0 -14
- package/dist/utils/computeTypeHash.d.ts.map +1 -1
- package/dist/utils/computeTypeHash.js +2 -19
- package/dist/utils/computeTypeHash.js.map +1 -1
- package/dist/utils/validation.d.ts +0 -40
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +7 -184
- package/dist/utils/validation.js.map +1 -1
- package/package.json +37 -54
- package/src/ACTPClient.ts +178 -692
- 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/EscrowVault.json +38 -106
- package/src/builders/DeliveryProofBuilder.ts +2 -3
- package/src/config/networks.ts +9 -32
- package/src/errors/index.ts +1 -298
- package/src/index.ts +71 -207
- package/src/protocol/ACTPKernel.ts +23 -175
- package/src/protocol/EASHelper.ts +46 -230
- package/src/protocol/EscrowVault.ts +50 -68
- package/src/protocol/EventMonitor.ts +15 -44
- package/src/protocol/MessageSigner.ts +13 -193
- package/src/protocol/ProofGenerator.ts +4 -223
- package/src/types/escrow.ts +11 -12
- package/src/types/index.ts +1 -5
- package/src/types/state.ts +3 -12
- package/src/types/transaction.ts +1 -4
- package/src/utils/IPFSClient.ts +5 -122
- package/src/utils/NonceManager.ts +8 -305
- package/src/utils/ReceivedNonceTracker.ts +0 -170
- package/src/utils/validation.ts +0 -164
- package/LICENSE +0 -190
- package/bin/actp +0 -10
- package/dist/abi/AgentRegistry.json +0 -782
- package/dist/abi/IdentityRegistry.json +0 -316
- package/dist/adapters/BaseAdapter.d.ts +0 -231
- package/dist/adapters/BaseAdapter.d.ts.map +0 -1
- package/dist/adapters/BaseAdapter.js +0 -393
- package/dist/adapters/BaseAdapter.js.map +0 -1
- package/dist/adapters/BeginnerAdapter.d.ts +0 -152
- package/dist/adapters/BeginnerAdapter.d.ts.map +0 -1
- package/dist/adapters/BeginnerAdapter.js +0 -168
- package/dist/adapters/BeginnerAdapter.js.map +0 -1
- package/dist/adapters/IntermediateAdapter.d.ts +0 -211
- package/dist/adapters/IntermediateAdapter.d.ts.map +0 -1
- package/dist/adapters/IntermediateAdapter.js +0 -260
- package/dist/adapters/IntermediateAdapter.js.map +0 -1
- package/dist/adapters/index.d.ts +0 -15
- package/dist/adapters/index.d.ts.map +0 -1
- package/dist/adapters/index.js +0 -26
- package/dist/adapters/index.js.map +0 -1
- package/dist/cli/commands/balance.d.ts +0 -13
- package/dist/cli/commands/balance.d.ts.map +0 -1
- package/dist/cli/commands/balance.js +0 -89
- package/dist/cli/commands/balance.js.map +0 -1
- package/dist/cli/commands/batch.d.ts +0 -24
- package/dist/cli/commands/batch.d.ts.map +0 -1
- package/dist/cli/commands/batch.js +0 -424
- package/dist/cli/commands/batch.js.map +0 -1
- package/dist/cli/commands/config.d.ts +0 -13
- package/dist/cli/commands/config.d.ts.map +0 -1
- package/dist/cli/commands/config.js +0 -192
- package/dist/cli/commands/config.js.map +0 -1
- package/dist/cli/commands/init.d.ts +0 -19
- package/dist/cli/commands/init.d.ts.map +0 -1
- package/dist/cli/commands/init.js +0 -143
- package/dist/cli/commands/init.js.map +0 -1
- package/dist/cli/commands/mint.d.ts +0 -13
- package/dist/cli/commands/mint.d.ts.map +0 -1
- package/dist/cli/commands/mint.js +0 -91
- package/dist/cli/commands/mint.js.map +0 -1
- package/dist/cli/commands/pay.d.ts +0 -18
- package/dist/cli/commands/pay.d.ts.map +0 -1
- package/dist/cli/commands/pay.js +0 -87
- package/dist/cli/commands/pay.js.map +0 -1
- package/dist/cli/commands/simulate.d.ts +0 -32
- package/dist/cli/commands/simulate.d.ts.map +0 -1
- package/dist/cli/commands/simulate.js +0 -290
- package/dist/cli/commands/simulate.js.map +0 -1
- package/dist/cli/commands/time.d.ts +0 -29
- package/dist/cli/commands/time.d.ts.map +0 -1
- package/dist/cli/commands/time.js +0 -252
- package/dist/cli/commands/time.js.map +0 -1
- package/dist/cli/commands/tx.d.ts +0 -16
- package/dist/cli/commands/tx.d.ts.map +0 -1
- package/dist/cli/commands/tx.js +0 -379
- package/dist/cli/commands/tx.js.map +0 -1
- package/dist/cli/commands/watch.d.ts +0 -20
- package/dist/cli/commands/watch.d.ts.map +0 -1
- package/dist/cli/commands/watch.js +0 -160
- package/dist/cli/commands/watch.js.map +0 -1
- package/dist/cli/index.d.ts +0 -17
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/index.js +0 -104
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/utils/client.d.ts +0 -70
- package/dist/cli/utils/client.d.ts.map +0 -1
- package/dist/cli/utils/client.js +0 -240
- package/dist/cli/utils/client.js.map +0 -1
- package/dist/cli/utils/config.d.ts +0 -91
- package/dist/cli/utils/config.d.ts.map +0 -1
- package/dist/cli/utils/config.js +0 -240
- package/dist/cli/utils/config.js.map +0 -1
- package/dist/cli/utils/output.d.ts +0 -174
- package/dist/cli/utils/output.d.ts.map +0 -1
- package/dist/cli/utils/output.js +0 -380
- package/dist/cli/utils/output.js.map +0 -1
- package/dist/level0/Provider.d.ts +0 -106
- package/dist/level0/Provider.d.ts.map +0 -1
- package/dist/level0/Provider.js +0 -10
- package/dist/level0/Provider.js.map +0 -1
- package/dist/level0/ServiceDirectory.d.ts +0 -74
- package/dist/level0/ServiceDirectory.d.ts.map +0 -1
- package/dist/level0/ServiceDirectory.js +0 -122
- package/dist/level0/ServiceDirectory.js.map +0 -1
- package/dist/level0/index.d.ts +0 -10
- package/dist/level0/index.d.ts.map +0 -1
- package/dist/level0/index.js +0 -15
- package/dist/level0/index.js.map +0 -1
- package/dist/level0/provide.d.ts +0 -51
- package/dist/level0/provide.d.ts.map +0 -1
- package/dist/level0/provide.js +0 -113
- package/dist/level0/provide.js.map +0 -1
- package/dist/level0/request.d.ts +0 -53
- package/dist/level0/request.d.ts.map +0 -1
- package/dist/level0/request.js +0 -462
- package/dist/level0/request.js.map +0 -1
- package/dist/level1/Agent.d.ts +0 -472
- package/dist/level1/Agent.d.ts.map +0 -1
- package/dist/level1/Agent.js +0 -1091
- package/dist/level1/Agent.js.map +0 -1
- package/dist/level1/index.d.ts +0 -10
- package/dist/level1/index.d.ts.map +0 -1
- package/dist/level1/index.js +0 -30
- package/dist/level1/index.js.map +0 -1
- package/dist/level1/pricing/PriceCalculator.d.ts +0 -62
- package/dist/level1/pricing/PriceCalculator.d.ts.map +0 -1
- package/dist/level1/pricing/PriceCalculator.js +0 -237
- package/dist/level1/pricing/PriceCalculator.js.map +0 -1
- package/dist/level1/pricing/PricingStrategy.d.ts +0 -179
- package/dist/level1/pricing/PricingStrategy.d.ts.map +0 -1
- package/dist/level1/pricing/PricingStrategy.js +0 -11
- package/dist/level1/pricing/PricingStrategy.js.map +0 -1
- package/dist/level1/types/Job.d.ts +0 -166
- package/dist/level1/types/Job.d.ts.map +0 -1
- package/dist/level1/types/Job.js +0 -11
- package/dist/level1/types/Job.js.map +0 -1
- package/dist/level1/types/Options.d.ts +0 -258
- package/dist/level1/types/Options.d.ts.map +0 -1
- package/dist/level1/types/Options.js +0 -8
- package/dist/level1/types/Options.js.map +0 -1
- package/dist/level1/types/index.d.ts +0 -8
- package/dist/level1/types/index.d.ts.map +0 -1
- package/dist/level1/types/index.js +0 -8
- package/dist/level1/types/index.js.map +0 -1
- package/dist/protocol/AgentRegistry.d.ts +0 -177
- package/dist/protocol/AgentRegistry.d.ts.map +0 -1
- package/dist/protocol/AgentRegistry.js +0 -449
- package/dist/protocol/AgentRegistry.js.map +0 -1
- package/dist/protocol/DIDManager.d.ts +0 -289
- package/dist/protocol/DIDManager.d.ts.map +0 -1
- package/dist/protocol/DIDManager.js +0 -481
- package/dist/protocol/DIDManager.js.map +0 -1
- package/dist/protocol/DIDResolver.d.ts +0 -236
- package/dist/protocol/DIDResolver.d.ts.map +0 -1
- package/dist/protocol/DIDResolver.js +0 -495
- package/dist/protocol/DIDResolver.js.map +0 -1
- package/dist/runtime/BlockchainRuntime.d.ts +0 -360
- package/dist/runtime/BlockchainRuntime.d.ts.map +0 -1
- package/dist/runtime/BlockchainRuntime.js +0 -767
- package/dist/runtime/BlockchainRuntime.js.map +0 -1
- package/dist/runtime/IACTPRuntime.d.ts +0 -271
- package/dist/runtime/IACTPRuntime.d.ts.map +0 -1
- package/dist/runtime/IACTPRuntime.js +0 -15
- package/dist/runtime/IACTPRuntime.js.map +0 -1
- package/dist/runtime/MockRuntime.d.ts +0 -445
- package/dist/runtime/MockRuntime.d.ts.map +0 -1
- package/dist/runtime/MockRuntime.js +0 -1065
- package/dist/runtime/MockRuntime.js.map +0 -1
- package/dist/runtime/MockStateManager.d.ts +0 -233
- package/dist/runtime/MockStateManager.d.ts.map +0 -1
- package/dist/runtime/MockStateManager.js +0 -533
- package/dist/runtime/MockStateManager.js.map +0 -1
- package/dist/runtime/index.d.ts +0 -14
- package/dist/runtime/index.d.ts.map +0 -1
- package/dist/runtime/index.js +0 -42
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/types/MockState.d.ts +0 -167
- package/dist/runtime/types/MockState.d.ts.map +0 -1
- package/dist/runtime/types/MockState.js +0 -43
- package/dist/runtime/types/MockState.js.map +0 -1
- package/dist/types/agent.d.ts +0 -76
- package/dist/types/agent.d.ts.map +0 -1
- package/dist/types/agent.js +0 -8
- package/dist/types/agent.js.map +0 -1
- package/dist/types/did.d.ts +0 -192
- package/dist/types/did.d.ts.map +0 -1
- package/dist/types/did.js +0 -38
- package/dist/types/did.js.map +0 -1
- package/dist/utils/ErrorRecoveryGuide.d.ts +0 -125
- package/dist/utils/ErrorRecoveryGuide.d.ts.map +0 -1
- package/dist/utils/ErrorRecoveryGuide.js +0 -579
- package/dist/utils/ErrorRecoveryGuide.js.map +0 -1
- package/dist/utils/Helpers.d.ts +0 -453
- package/dist/utils/Helpers.d.ts.map +0 -1
- package/dist/utils/Helpers.js +0 -623
- package/dist/utils/Helpers.js.map +0 -1
- package/dist/utils/Logger.d.ts +0 -195
- package/dist/utils/Logger.d.ts.map +0 -1
- package/dist/utils/Logger.js +0 -382
- package/dist/utils/Logger.js.map +0 -1
- package/dist/utils/RateLimiter.d.ts +0 -253
- package/dist/utils/RateLimiter.d.ts.map +0 -1
- package/dist/utils/RateLimiter.js +0 -424
- package/dist/utils/RateLimiter.js.map +0 -1
- package/dist/utils/SDKLifecycle.d.ts +0 -156
- package/dist/utils/SDKLifecycle.d.ts.map +0 -1
- package/dist/utils/SDKLifecycle.js +0 -347
- package/dist/utils/SDKLifecycle.js.map +0 -1
- package/dist/utils/SecureNonce.d.ts +0 -57
- package/dist/utils/SecureNonce.d.ts.map +0 -1
- package/dist/utils/SecureNonce.js +0 -80
- package/dist/utils/SecureNonce.js.map +0 -1
- package/dist/utils/Semaphore.d.ts +0 -123
- package/dist/utils/Semaphore.d.ts.map +0 -1
- package/dist/utils/Semaphore.js +0 -247
- package/dist/utils/Semaphore.js.map +0 -1
- package/dist/utils/UsedAttestationTracker.d.ts +0 -167
- package/dist/utils/UsedAttestationTracker.d.ts.map +0 -1
- package/dist/utils/UsedAttestationTracker.js +0 -309
- package/dist/utils/UsedAttestationTracker.js.map +0 -1
- package/dist/utils/fsSafe.d.ts +0 -14
- package/dist/utils/fsSafe.d.ts.map +0 -1
- package/dist/utils/fsSafe.js +0 -89
- package/dist/utils/fsSafe.js.map +0 -1
- package/dist/utils/index.d.ts +0 -15
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -51
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/security.d.ts +0 -147
- package/dist/utils/security.d.ts.map +0 -1
- package/dist/utils/security.js +0 -391
- package/dist/utils/security.js.map +0 -1
- package/src/abi/AgentRegistry.json +0 -782
- package/src/abi/IdentityRegistry.json +0 -316
- package/src/adapters/BaseAdapter.ts +0 -473
- package/src/adapters/BeginnerAdapter.ts +0 -232
- package/src/adapters/IntermediateAdapter.ts +0 -316
- package/src/adapters/index.ts +0 -25
- package/src/cli/commands/balance.ts +0 -110
- package/src/cli/commands/batch.ts +0 -487
- package/src/cli/commands/config.ts +0 -231
- package/src/cli/commands/init.ts +0 -161
- package/src/cli/commands/mint.ts +0 -116
- package/src/cli/commands/pay.ts +0 -113
- package/src/cli/commands/simulate.ts +0 -345
- package/src/cli/commands/time.ts +0 -303
- package/src/cli/commands/tx.ts +0 -448
- package/src/cli/commands/watch.ts +0 -211
- package/src/cli/index.ts +0 -116
- package/src/cli/utils/client.ts +0 -249
- package/src/cli/utils/config.ts +0 -282
- package/src/cli/utils/output.ts +0 -465
- package/src/level0/Provider.ts +0 -117
- package/src/level0/ServiceDirectory.ts +0 -131
- package/src/level0/index.ts +0 -10
- package/src/level0/provide.ts +0 -131
- package/src/level0/request.ts +0 -494
- package/src/level1/Agent.ts +0 -1432
- package/src/level1/index.ts +0 -10
- package/src/level1/pricing/PriceCalculator.ts +0 -255
- package/src/level1/pricing/PricingStrategy.ts +0 -198
- package/src/level1/types/Job.ts +0 -179
- package/src/level1/types/Options.ts +0 -291
- package/src/level1/types/index.ts +0 -8
- package/src/protocol/AgentRegistry.ts +0 -559
- package/src/protocol/DIDManager.ts +0 -629
- package/src/protocol/DIDResolver.ts +0 -554
- package/src/runtime/BlockchainRuntime.ts +0 -993
- package/src/runtime/IACTPRuntime.ts +0 -284
- package/src/runtime/MockRuntime.ts +0 -1244
- package/src/runtime/MockStateManager.ts +0 -576
- package/src/runtime/index.ts +0 -25
- package/src/runtime/types/MockState.ts +0 -227
- package/src/types/agent.ts +0 -79
- package/src/types/did.ts +0 -223
- package/src/utils/ErrorRecoveryGuide.ts +0 -675
- package/src/utils/Helpers.ts +0 -688
- package/src/utils/Logger.ts +0 -484
- package/src/utils/RateLimiter.ts +0 -534
- package/src/utils/SDKLifecycle.ts +0 -416
- package/src/utils/SecureNonce.ts +0 -78
- package/src/utils/Semaphore.ts +0 -276
- package/src/utils/UsedAttestationTracker.ts +0 -387
- package/src/utils/fsSafe.ts +0 -75
- package/src/utils/index.ts +0 -80
- package/src/utils/security.ts +0 -418
|
@@ -2,83 +2,11 @@ import { keccak256, toUtf8Bytes, AbiCoder, BytesLike } from 'ethers';
|
|
|
2
2
|
import { DeliveryProof } from '../types';
|
|
3
3
|
import { DeliveryProofData, deliveryProofDataFromProof } from '../types/eip712';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* SECURITY FIX (MEDIUM-2): URL validation configuration for SSRF prevention
|
|
7
|
-
*/
|
|
8
|
-
export interface URLValidationConfig {
|
|
9
|
-
/**
|
|
10
|
-
* Allowed URL protocols (default: ['https:'])
|
|
11
|
-
* Set to ['https:', 'http:'] to allow HTTP in development
|
|
12
|
-
*/
|
|
13
|
-
allowedProtocols?: string[];
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Allow localhost URLs (default: false in production, true in dev)
|
|
17
|
-
*/
|
|
18
|
-
allowLocalhost?: boolean;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Maximum response size in bytes (default: 10MB)
|
|
22
|
-
*/
|
|
23
|
-
maxSize?: number;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Request timeout in milliseconds (default: 30000)
|
|
27
|
-
*/
|
|
28
|
-
timeout?: number;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Blocked hostnames (e.g., internal services)
|
|
32
|
-
*/
|
|
33
|
-
blockedHosts?: string[];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Default URL validation config - SECURE by default
|
|
38
|
-
*/
|
|
39
|
-
const DEFAULT_URL_CONFIG: Required<URLValidationConfig> = {
|
|
40
|
-
allowedProtocols: ['https:'],
|
|
41
|
-
allowLocalhost: false,
|
|
42
|
-
maxSize: 10 * 1024 * 1024, // 10MB
|
|
43
|
-
timeout: 30000, // 30 seconds
|
|
44
|
-
blockedHosts: [
|
|
45
|
-
'metadata.google.internal',
|
|
46
|
-
'169.254.169.254', // AWS/GCP metadata
|
|
47
|
-
'metadata.aws.internal',
|
|
48
|
-
'localhost',
|
|
49
|
-
'127.0.0.1',
|
|
50
|
-
'0.0.0.0',
|
|
51
|
-
'[::1]',
|
|
52
|
-
],
|
|
53
|
-
};
|
|
54
|
-
|
|
55
5
|
/**
|
|
56
6
|
* ProofGenerator - Content hashing and delivery proofs
|
|
57
7
|
* Reference: Yellow Paper §11.4.1
|
|
58
|
-
*
|
|
59
|
-
* SECURITY FIX (MEDIUM-2): Now includes URL validation for SSRF prevention
|
|
60
8
|
*/
|
|
61
9
|
export class ProofGenerator {
|
|
62
|
-
private readonly urlConfig: Required<URLValidationConfig>;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Create ProofGenerator with optional URL validation config
|
|
66
|
-
*
|
|
67
|
-
* @param urlConfig - URL validation configuration for hashFromUrl()
|
|
68
|
-
*/
|
|
69
|
-
constructor(urlConfig?: URLValidationConfig) {
|
|
70
|
-
this.urlConfig = {
|
|
71
|
-
...DEFAULT_URL_CONFIG,
|
|
72
|
-
...urlConfig,
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
// If localhost is explicitly allowed, remove from blocked hosts
|
|
76
|
-
if (urlConfig?.allowLocalhost) {
|
|
77
|
-
this.urlConfig.blockedHosts = this.urlConfig.blockedHosts.filter(
|
|
78
|
-
(h) => !['localhost', '127.0.0.1', '0.0.0.0', '[::1]'].includes(h)
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
10
|
/**
|
|
83
11
|
* Hash deliverable content
|
|
84
12
|
* Uses Keccak256 per Yellow Paper §11.4.1
|
|
@@ -176,163 +104,16 @@ export class ProofGenerator {
|
|
|
176
104
|
|
|
177
105
|
/**
|
|
178
106
|
* Generate content hash from URL (for IPFS/Arweave)
|
|
179
|
-
*
|
|
180
|
-
* SECURITY FIX (MEDIUM-2): Now includes:
|
|
181
|
-
* - Protocol validation (HTTPS only by default)
|
|
182
|
-
* - Hostname blocklist (prevents SSRF to internal services)
|
|
183
|
-
* - Size limits (prevents DoS via large responses)
|
|
184
|
-
* - Request timeout
|
|
185
|
-
*
|
|
186
|
-
* @param url - URL to fetch content from
|
|
187
|
-
* @returns Keccak256 hash of content
|
|
188
|
-
* @throws Error if URL is blocked, too large, or fetch fails
|
|
189
107
|
*/
|
|
190
108
|
async hashFromUrl(url: string): Promise<string> {
|
|
191
|
-
// SECURITY FIX (MEDIUM-2): Validate URL before fetching
|
|
192
|
-
this.validateUrl(url);
|
|
193
|
-
|
|
194
109
|
// In browser/Node.js environment with fetch
|
|
195
110
|
try {
|
|
196
|
-
|
|
197
|
-
const
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
try {
|
|
201
|
-
const response = await fetch(url, {
|
|
202
|
-
signal: controller.signal,
|
|
203
|
-
// Prevent following redirects to blocked hosts
|
|
204
|
-
redirect: 'follow',
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
clearTimeout(timeoutId);
|
|
208
|
-
|
|
209
|
-
if (!response.ok) {
|
|
210
|
-
throw new Error(`HTTP error: ${response.status} ${response.statusText}`);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// SECURITY FIX (MEDIUM-2): Check Content-Length header first
|
|
214
|
-
const contentLength = response.headers.get('content-length');
|
|
215
|
-
if (contentLength) {
|
|
216
|
-
const size = parseInt(contentLength, 10);
|
|
217
|
-
if (size > this.urlConfig.maxSize) {
|
|
218
|
-
throw new Error(
|
|
219
|
-
`Content too large: ${size} bytes exceeds maximum of ${this.urlConfig.maxSize} bytes`
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// SECURITY FIX (MEDIUM-2): Read response with size limit
|
|
225
|
-
const chunks: Uint8Array[] = [];
|
|
226
|
-
let totalSize = 0;
|
|
227
|
-
const reader = response.body?.getReader();
|
|
228
|
-
|
|
229
|
-
if (!reader) {
|
|
230
|
-
throw new Error('Response body is not readable');
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
while (true) {
|
|
234
|
-
const { done, value } = await reader.read();
|
|
235
|
-
|
|
236
|
-
if (done) break;
|
|
237
|
-
|
|
238
|
-
totalSize += value.length;
|
|
239
|
-
|
|
240
|
-
// Check size limit during streaming
|
|
241
|
-
if (totalSize > this.urlConfig.maxSize) {
|
|
242
|
-
reader.cancel();
|
|
243
|
-
throw new Error(
|
|
244
|
-
`Content too large: ${totalSize}+ bytes exceeds maximum of ${this.urlConfig.maxSize} bytes`
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
chunks.push(value);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// Concatenate chunks
|
|
252
|
-
const buffer = Buffer.concat(chunks.map(c => Buffer.from(c)));
|
|
253
|
-
return this.hashContent(buffer);
|
|
254
|
-
} finally {
|
|
255
|
-
clearTimeout(timeoutId);
|
|
256
|
-
}
|
|
111
|
+
const response = await fetch(url);
|
|
112
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
113
|
+
const buffer = Buffer.from(arrayBuffer);
|
|
114
|
+
return this.hashContent(buffer);
|
|
257
115
|
} catch (error) {
|
|
258
|
-
if (error instanceof Error && error.name === 'AbortError') {
|
|
259
|
-
throw new Error(`Request timed out after ${this.urlConfig.timeout}ms for ${url}`);
|
|
260
|
-
}
|
|
261
116
|
throw new Error(`Failed to fetch content from ${url}: ${error}`);
|
|
262
117
|
}
|
|
263
118
|
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* SECURITY FIX (MEDIUM-2): Validate URL against security rules
|
|
267
|
-
*
|
|
268
|
-
* @param url - URL to validate
|
|
269
|
-
* @throws Error if URL is not allowed
|
|
270
|
-
*/
|
|
271
|
-
private validateUrl(url: string): void {
|
|
272
|
-
let parsed: URL;
|
|
273
|
-
|
|
274
|
-
try {
|
|
275
|
-
parsed = new URL(url);
|
|
276
|
-
} catch {
|
|
277
|
-
throw new Error(`Invalid URL: ${url}`);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// Check protocol
|
|
281
|
-
if (!this.urlConfig.allowedProtocols.includes(parsed.protocol)) {
|
|
282
|
-
throw new Error(
|
|
283
|
-
`URL protocol "${parsed.protocol}" not allowed. ` +
|
|
284
|
-
`Allowed protocols: ${this.urlConfig.allowedProtocols.join(', ')}`
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// Check blocked hosts
|
|
289
|
-
const hostname = parsed.hostname.toLowerCase();
|
|
290
|
-
if (this.urlConfig.blockedHosts.includes(hostname)) {
|
|
291
|
-
throw new Error(
|
|
292
|
-
`URL hostname "${hostname}" is blocked for security reasons. ` +
|
|
293
|
-
`This prevents SSRF attacks to internal services.`
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// Check for private IP ranges (additional SSRF protection)
|
|
298
|
-
if (this.isPrivateIP(hostname)) {
|
|
299
|
-
throw new Error(
|
|
300
|
-
`URL hostname "${hostname}" resolves to a private IP address. ` +
|
|
301
|
-
`This is blocked for security reasons (SSRF prevention).`
|
|
302
|
-
);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Check if hostname is a private IP address
|
|
308
|
-
*
|
|
309
|
-
* @param hostname - Hostname to check
|
|
310
|
-
* @returns true if hostname is a private IP
|
|
311
|
-
*/
|
|
312
|
-
private isPrivateIP(hostname: string): boolean {
|
|
313
|
-
// IPv4 private ranges
|
|
314
|
-
const ipv4PrivateRanges = [
|
|
315
|
-
/^10\./, // 10.0.0.0 - 10.255.255.255
|
|
316
|
-
/^172\.(1[6-9]|2[0-9]|3[0-1])\./, // 172.16.0.0 - 172.31.255.255
|
|
317
|
-
/^192\.168\./, // 192.168.0.0 - 192.168.255.255
|
|
318
|
-
/^127\./, // 127.0.0.0 - 127.255.255.255 (loopback)
|
|
319
|
-
/^169\.254\./, // 169.254.0.0 - 169.254.255.255 (link-local)
|
|
320
|
-
/^0\./, // 0.0.0.0/8
|
|
321
|
-
];
|
|
322
|
-
|
|
323
|
-
for (const range of ipv4PrivateRanges) {
|
|
324
|
-
if (range.test(hostname)) {
|
|
325
|
-
return true;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
return false;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Get the URL validation config (for testing/inspection)
|
|
334
|
-
*/
|
|
335
|
-
getUrlConfig(): Required<URLValidationConfig> {
|
|
336
|
-
return { ...this.urlConfig };
|
|
337
|
-
}
|
|
338
119
|
}
|
package/src/types/escrow.ts
CHANGED
|
@@ -2,26 +2,25 @@
|
|
|
2
2
|
* Escrow creation parameters
|
|
3
3
|
*/
|
|
4
4
|
export interface CreateEscrowParams {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
requester: string;
|
|
9
|
-
/** Provider who receives payout on settlement */
|
|
10
|
-
provider: string;
|
|
11
|
-
/** Amount locked in escrow (USDC wei, 6 decimals) */
|
|
5
|
+
kernelAddress: string;
|
|
6
|
+
txId: string;
|
|
7
|
+
token: string;
|
|
12
8
|
amount: bigint;
|
|
9
|
+
beneficiary: string;
|
|
13
10
|
}
|
|
14
11
|
|
|
15
12
|
/**
|
|
16
|
-
* Escrow state
|
|
13
|
+
* Escrow state
|
|
17
14
|
*/
|
|
18
15
|
export interface Escrow {
|
|
19
16
|
escrowId: string;
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
kernel: string;
|
|
18
|
+
txId: string;
|
|
19
|
+
token: string;
|
|
22
20
|
amount: bigint;
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
beneficiary: string;
|
|
22
|
+
createdAt: number;
|
|
23
|
+
released: boolean;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
|
package/src/types/index.ts
CHANGED
|
@@ -7,8 +7,4 @@ export * from './transaction';
|
|
|
7
7
|
export * from './escrow';
|
|
8
8
|
export * from './message';
|
|
9
9
|
export * from './eip712';
|
|
10
|
-
|
|
11
|
-
export * from './did';
|
|
12
|
-
// Note: storage and archive types are not yet implemented in this version
|
|
13
|
-
// export * from './storage';
|
|
14
|
-
// export * from './archive';
|
|
10
|
+
|
package/src/types/state.ts
CHANGED
|
@@ -17,23 +17,14 @@ export enum State {
|
|
|
17
17
|
export class StateMachine {
|
|
18
18
|
/**
|
|
19
19
|
* Valid state transitions per Yellow Paper §3.2.2
|
|
20
|
-
*
|
|
21
|
-
* SECURITY FIX (CRITICAL-1): State machine must match ACTPKernel contract exactly
|
|
22
|
-
* Per CLAUDE.md §Architecture Overview - ACTP Protocol State Machine:
|
|
23
|
-
* - COMMITTED can transition to IN_PROGRESS, DELIVERED, or CANCELLED
|
|
24
|
-
* - IN_PROGRESS can transition to DELIVERED or CANCELLED (not DISPUTED)
|
|
25
|
-
* - DISPUTED can only transition to SETTLED (not CANCELLED)
|
|
26
20
|
*/
|
|
27
21
|
private static readonly TRANSITIONS: Record<State, State[]> = {
|
|
28
22
|
[State.INITIATED]: [State.QUOTED, State.COMMITTED, State.CANCELLED], // Allow direct INITIATED → COMMITTED (AIP-3)
|
|
29
23
|
[State.QUOTED]: [State.COMMITTED, State.CANCELLED],
|
|
30
|
-
|
|
31
|
-
[State.
|
|
32
|
-
// SECURITY FIX (CRITICAL-1): Remove DISPUTED, add CANCELLED
|
|
33
|
-
[State.IN_PROGRESS]: [State.DELIVERED, State.CANCELLED],
|
|
24
|
+
[State.COMMITTED]: [State.IN_PROGRESS, State.CANCELLED],
|
|
25
|
+
[State.IN_PROGRESS]: [State.DELIVERED, State.DISPUTED],
|
|
34
26
|
[State.DELIVERED]: [State.SETTLED, State.DISPUTED],
|
|
35
|
-
|
|
36
|
-
[State.DISPUTED]: [State.SETTLED],
|
|
27
|
+
[State.DISPUTED]: [State.SETTLED, State.CANCELLED],
|
|
37
28
|
[State.SETTLED]: [], // Terminal state
|
|
38
29
|
[State.CANCELLED]: [] // Terminal state
|
|
39
30
|
};
|
package/src/types/transaction.ts
CHANGED
|
@@ -11,15 +11,11 @@ export interface Transaction {
|
|
|
11
11
|
amount: bigint;
|
|
12
12
|
state: State;
|
|
13
13
|
createdAt: number;
|
|
14
|
-
updatedAt: number;
|
|
15
14
|
deadline: number;
|
|
16
15
|
disputeWindow: number;
|
|
17
16
|
escrowContract: string;
|
|
18
17
|
escrowId: string;
|
|
19
|
-
serviceHash: string;
|
|
20
|
-
attestationUID: string;
|
|
21
18
|
metadata: string;
|
|
22
|
-
platformFeeBpsLocked: number;
|
|
23
19
|
}
|
|
24
20
|
|
|
25
21
|
/**
|
|
@@ -55,3 +51,4 @@ export interface EconomicParams {
|
|
|
55
51
|
providerPenaltyBps: number;
|
|
56
52
|
}
|
|
57
53
|
|
|
54
|
+
|
package/src/utils/IPFSClient.ts
CHANGED
|
@@ -59,24 +59,6 @@ export interface IPFSClientConfig {
|
|
|
59
59
|
* Default: 60000 (60 seconds)
|
|
60
60
|
*/
|
|
61
61
|
timeout?: number;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* SECURITY FIX (MEDIUM-3): Maximum content size in bytes
|
|
65
|
-
* Default: 50MB (50 * 1024 * 1024)
|
|
66
|
-
*/
|
|
67
|
-
maxSize?: number;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* SECURITY FIX (MEDIUM-3): Allowed URL protocols
|
|
71
|
-
* Default: ['http:', 'https:'] (http for localhost, https for remote)
|
|
72
|
-
*/
|
|
73
|
-
allowedProtocols?: string[];
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* SECURITY FIX (MEDIUM-3): Allow localhost URLs
|
|
77
|
-
* Default: true (required for local IPFS daemon)
|
|
78
|
-
*/
|
|
79
|
-
allowLocalhost?: boolean;
|
|
80
62
|
}
|
|
81
63
|
|
|
82
64
|
/**
|
|
@@ -99,45 +81,21 @@ export const IPFS_CONFIGS = {
|
|
|
99
81
|
/**
|
|
100
82
|
* IPFS HTTP Client Implementation
|
|
101
83
|
* Uses ipfs-http-client library
|
|
102
|
-
*
|
|
103
|
-
* SECURITY FIX (MEDIUM-3): Now includes URL and size validation
|
|
104
84
|
*/
|
|
105
85
|
export class IPFSHTTPClientImpl implements IPFSClient {
|
|
106
86
|
private client: IPFSHTTPClient;
|
|
107
|
-
private config:
|
|
108
|
-
|
|
109
|
-
// SECURITY FIX (MEDIUM-3): Default security settings
|
|
110
|
-
private static readonly DEFAULT_MAX_SIZE = 50 * 1024 * 1024; // 50MB
|
|
111
|
-
private static readonly DEFAULT_ALLOWED_PROTOCOLS = ['http:', 'https:'];
|
|
112
|
-
private static readonly BLOCKED_HOSTS = [
|
|
113
|
-
'metadata.google.internal',
|
|
114
|
-
'169.254.169.254',
|
|
115
|
-
'metadata.aws.internal',
|
|
116
|
-
];
|
|
87
|
+
private config: IPFSClientConfig;
|
|
117
88
|
|
|
118
89
|
/**
|
|
119
90
|
* Create IPFS client
|
|
120
|
-
*
|
|
121
|
-
* SECURITY FIX (MEDIUM-3): Validates URL and adds size limits
|
|
122
|
-
*
|
|
123
91
|
* @param config - IPFS client configuration
|
|
124
|
-
* @throws Error if URL is invalid or blocked
|
|
125
92
|
*/
|
|
126
93
|
constructor(config: IPFSClientConfig = {}) {
|
|
127
|
-
const url = config.url || 'http://localhost:5001';
|
|
128
|
-
|
|
129
|
-
// SECURITY FIX (MEDIUM-3): Validate URL
|
|
130
|
-
this.validateUrl(url, config.allowLocalhost ?? true, config.allowedProtocols);
|
|
131
|
-
|
|
132
94
|
this.config = {
|
|
133
|
-
url,
|
|
95
|
+
url: config.url || 'http://localhost:5001',
|
|
134
96
|
timeout: config.timeout || 60000,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
allowLocalhost: config.allowLocalhost ?? true,
|
|
138
|
-
auth: config.auth,
|
|
139
|
-
headers: config.headers,
|
|
140
|
-
} as Required<IPFSClientConfig>;
|
|
97
|
+
...config
|
|
98
|
+
};
|
|
141
99
|
|
|
142
100
|
const options: Options = {
|
|
143
101
|
url: this.config.url,
|
|
@@ -159,76 +117,15 @@ export class IPFSHTTPClientImpl implements IPFSClient {
|
|
|
159
117
|
this.client = create(options);
|
|
160
118
|
}
|
|
161
119
|
|
|
162
|
-
/**
|
|
163
|
-
* SECURITY FIX (MEDIUM-3): Validate IPFS endpoint URL
|
|
164
|
-
*/
|
|
165
|
-
private validateUrl(
|
|
166
|
-
url: string,
|
|
167
|
-
allowLocalhost: boolean,
|
|
168
|
-
allowedProtocols?: string[]
|
|
169
|
-
): void {
|
|
170
|
-
let parsed: URL;
|
|
171
|
-
|
|
172
|
-
try {
|
|
173
|
-
parsed = new URL(url);
|
|
174
|
-
} catch {
|
|
175
|
-
throw new Error(`Invalid IPFS endpoint URL: ${url}`);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const protocols = allowedProtocols || IPFSHTTPClientImpl.DEFAULT_ALLOWED_PROTOCOLS;
|
|
179
|
-
if (!protocols.includes(parsed.protocol)) {
|
|
180
|
-
throw new Error(
|
|
181
|
-
`IPFS endpoint protocol "${parsed.protocol}" not allowed. ` +
|
|
182
|
-
`Allowed protocols: ${protocols.join(', ')}`
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const hostname = parsed.hostname.toLowerCase();
|
|
187
|
-
|
|
188
|
-
// Check blocked hosts (cloud metadata endpoints)
|
|
189
|
-
if (IPFSHTTPClientImpl.BLOCKED_HOSTS.includes(hostname)) {
|
|
190
|
-
throw new Error(
|
|
191
|
-
`IPFS endpoint hostname "${hostname}" is blocked for security reasons.`
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// Check localhost
|
|
196
|
-
const isLocalhost = ['localhost', '127.0.0.1', '0.0.0.0', '[::1]'].includes(hostname);
|
|
197
|
-
if (isLocalhost && !allowLocalhost) {
|
|
198
|
-
throw new Error(
|
|
199
|
-
`Localhost IPFS endpoints are disabled. Set allowLocalhost: true to enable.`
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// For remote hosts, require HTTPS
|
|
204
|
-
if (!isLocalhost && parsed.protocol !== 'https:') {
|
|
205
|
-
console.warn(
|
|
206
|
-
`[SECURITY WARNING] Using non-HTTPS protocol "${parsed.protocol}" for remote IPFS endpoint "${hostname}". ` +
|
|
207
|
-
`This may expose data in transit. Consider using HTTPS.`
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
120
|
/**
|
|
213
121
|
* Upload data to IPFS
|
|
214
|
-
*
|
|
215
|
-
* SECURITY FIX (MEDIUM-3): Validates size before upload
|
|
216
|
-
*
|
|
217
122
|
* @param data - JSON string or buffer
|
|
218
123
|
* @returns CIDv1 string (base32)
|
|
219
|
-
* @throws Error if data exceeds maxSize
|
|
220
124
|
*/
|
|
221
125
|
async add(data: string | Buffer): Promise<string> {
|
|
222
126
|
try {
|
|
223
127
|
const content = typeof data === 'string' ? Buffer.from(data, 'utf-8') : data;
|
|
224
128
|
|
|
225
|
-
// SECURITY FIX (MEDIUM-3): Check size before upload
|
|
226
|
-
if (content.length > this.config.maxSize) {
|
|
227
|
-
throw new Error(
|
|
228
|
-
`Content too large: ${content.length} bytes exceeds maximum of ${this.config.maxSize} bytes`
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
129
|
const result = await this.client.add(content, {
|
|
233
130
|
cidVersion: 1, // Use CIDv1 (base32)
|
|
234
131
|
hashAlg: 'sha2-256',
|
|
@@ -256,33 +153,19 @@ export class IPFSHTTPClientImpl implements IPFSClient {
|
|
|
256
153
|
|
|
257
154
|
/**
|
|
258
155
|
* Retrieve content from IPFS
|
|
259
|
-
*
|
|
260
|
-
* SECURITY FIX (MEDIUM-3): Validates size during retrieval
|
|
261
|
-
*
|
|
262
156
|
* @param cid - IPFS CID
|
|
263
157
|
* @returns Content as string
|
|
264
|
-
* @throws Error if content exceeds maxSize
|
|
265
158
|
*/
|
|
266
159
|
async get(cid: string): Promise<string> {
|
|
267
160
|
try {
|
|
268
161
|
const chunks: Uint8Array[] = [];
|
|
269
|
-
let totalLength = 0;
|
|
270
162
|
|
|
271
163
|
for await (const chunk of this.client.cat(cid)) {
|
|
272
|
-
totalLength += chunk.length;
|
|
273
|
-
|
|
274
|
-
// SECURITY FIX (MEDIUM-3): Check size during streaming to prevent DoS
|
|
275
|
-
if (totalLength > this.config.maxSize) {
|
|
276
|
-
throw new Error(
|
|
277
|
-
`Content too large: ${totalLength}+ bytes exceeds maximum of ${this.config.maxSize} bytes. ` +
|
|
278
|
-
`Consider increasing maxSize in IPFSClientConfig if this is expected.`
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
164
|
chunks.push(chunk);
|
|
283
165
|
}
|
|
284
166
|
|
|
285
167
|
// Concatenate all chunks
|
|
168
|
+
const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
|
|
286
169
|
const result = new Uint8Array(totalLength);
|
|
287
170
|
let offset = 0;
|
|
288
171
|
|