@blindmarket/sdk 0.1.7 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chain/BlindEscrowClient.d.ts +2 -0
- package/dist/chain/BlindEscrowClient.js +14 -6
- package/dist/chain/BlindReputationClient.d.ts +3 -0
- package/dist/chain/BlindReputationClient.js +3 -1
- package/dist/chain/ChainClient.d.ts +5 -2
- package/dist/chain/ChainClient.js +5 -0
- package/dist/chain/IBlindMarketChain.d.ts +74 -0
- package/dist/chain/TaskRegistryClient.d.ts +2 -1
- package/dist/chain/TaskRegistryClient.js +15 -7
- package/dist/chain/createChainAdapter.d.ts +25 -0
- package/dist/chain/createChainAdapter.js +24 -0
- package/dist/chain/domain-types.d.ts +77 -0
- package/dist/chain/evm/EVMChainAdapter.d.ts +56 -0
- package/dist/chain/evm/EVMChainAdapter.js +161 -0
- package/dist/chain/evm/index.d.ts +1 -0
- package/dist/chain/evm/index.js +1 -0
- package/dist/chain/index.d.ts +4 -0
- package/dist/chain/index.js +5 -0
- package/dist/executor/WorkerRuntime.d.ts +134 -0
- package/dist/executor/WorkerRuntime.js +277 -0
- package/dist/executor/index.d.ts +1 -0
- package/dist/executor/index.js +1 -0
- package/dist/index.d.ts +82 -9
- package/dist/index.js +60 -6
- package/dist/network/presets.d.ts +33 -5
- package/dist/network/presets.js +35 -8
- package/dist/network/resolve.d.ts +12 -3
- package/dist/network/resolve.js +15 -7
- package/dist/network/types.d.ts +3 -16
- package/dist/types.d.ts +1 -1
- package/package.json +8 -1
- package/biome.json +0 -19
- package/dist/BlindEscrowClient-CyPuKMge.d.cts +0 -54
- package/dist/BlindEscrowClient-R7iGpE-n.d.ts +0 -54
- package/dist/KeyStore-Be_SSpCt.d.cts +0 -21
- package/dist/KeyStore-k1JgYPJY.d.ts +0 -21
- package/dist/Signer-BnqH_qew.d.cts +0 -38
- package/dist/Signer-LColE0Uo.d.ts +0 -38
- package/dist/Storage-4QOrh7rm.d.ts +0 -17
- package/dist/Storage-Cf4IJRMk.d.cts +0 -17
- package/dist/TaskRegistryClient-Ch6lYqM_.d.ts +0 -24
- package/dist/TaskRegistryClient-CrQjddDc.d.cts +0 -24
- package/dist/aes-J-7HrHze.d.cts +0 -17
- package/dist/aes-J-7HrHze.d.ts +0 -17
- package/dist/agent/index.cjs +0 -425
- package/dist/agent/index.cjs.map +0 -1
- package/dist/agent/index.d.cts +0 -63
- package/dist/agent/index.js.map +0 -1
- package/dist/api/index.cjs +0 -4
- package/dist/api/index.cjs.map +0 -1
- package/dist/api/index.d.cts +0 -2
- package/dist/api/index.js.map +0 -1
- package/dist/chain/index.cjs +0 -2484
- package/dist/chain/index.cjs.map +0 -1
- package/dist/chain/index.d.cts +0 -2305
- package/dist/chain/index.js.map +0 -1
- package/dist/compute/index.cjs +0 -4
- package/dist/compute/index.cjs.map +0 -1
- package/dist/compute/index.d.cts +0 -2
- package/dist/compute/index.js.map +0 -1
- package/dist/crypto/index.cjs +0 -424
- package/dist/crypto/index.cjs.map +0 -1
- package/dist/crypto/index.d.cts +0 -74
- package/dist/crypto/index.js.map +0 -1
- package/dist/errors/BlindBountyError.d.ts +0 -14
- package/dist/errors/BlindBountyError.js +0 -30
- package/dist/errors/index.cjs +0 -136
- package/dist/errors/index.cjs.map +0 -1
- package/dist/errors/index.d.cts +0 -60
- package/dist/errors/index.js.map +0 -1
- package/dist/events/index.cjs +0 -41
- package/dist/events/index.cjs.map +0 -1
- package/dist/events/index.d.cts +0 -61
- package/dist/events/index.js.map +0 -1
- package/dist/index.cjs +0 -4
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -2
- package/dist/index.js.map +0 -1
- package/dist/keystore/index.cjs +0 -335
- package/dist/keystore/index.cjs.map +0 -1
- package/dist/keystore/index.d.cts +0 -23
- package/dist/keystore/index.js.map +0 -1
- package/dist/mcp.d.ts +0 -23
- package/dist/mcp.js +0 -101
- package/dist/network/index.cjs +0 -74
- package/dist/network/index.cjs.map +0 -1
- package/dist/network/index.d.cts +0 -36
- package/dist/network/index.js.map +0 -1
- package/dist/signer/index.cjs +0 -121
- package/dist/signer/index.cjs.map +0 -1
- package/dist/signer/index.d.cts +0 -40
- package/dist/signer/index.js.map +0 -1
- package/dist/storage/ZgStorage.d.ts +0 -24
- package/dist/storage/ZgStorage.js +0 -102
- package/dist/storage/index.cjs +0 -221
- package/dist/storage/index.cjs.map +0 -1
- package/dist/storage/index.d.cts +0 -44
- package/dist/storage/index.js.map +0 -1
- package/dist/testing/index.cjs +0 -4
- package/dist/testing/index.cjs.map +0 -1
- package/dist/testing/index.d.cts +0 -2
- package/dist/testing/index.js.map +0 -1
- package/dist/types-BOG5Ub1z.d.cts +0 -31
- package/dist/types-BOG5Ub1z.d.ts +0 -31
- package/dist/types-V7_ZmUb-.d.cts +0 -19
- package/dist/types-hAsITUQ7.d.ts +0 -19
- package/dist/verifier/index.cjs +0 -4
- package/dist/verifier/index.cjs.map +0 -1
- package/dist/verifier/index.d.cts +0 -2
- package/dist/verifier/index.js.map +0 -1
- package/dist/worker/index.cjs +0 -382
- package/dist/worker/index.cjs.map +0 -1
- package/dist/worker/index.d.cts +0 -58
- package/dist/worker/index.js.map +0 -1
- package/examples/agent-demo.ts +0 -121
- package/scripts/gen-crypto-fixtures.mjs +0 -72
- package/src/agent/Agent.ts +0 -122
- package/src/agent/index.ts +0 -1
- package/src/chain/BlindEscrowClient.ts +0 -187
- package/src/chain/BlindReputationClient.ts +0 -55
- package/src/chain/ChainClient.ts +0 -59
- package/src/chain/TaskRegistryClient.ts +0 -82
- package/src/chain/abi/BlindEscrow.json +0 -1113
- package/src/chain/abi/BlindReputation.json +0 -447
- package/src/chain/abi/TaskRegistry.json +0 -586
- package/src/chain/abi/index.ts +0 -5
- package/src/chain/errors.ts +0 -43
- package/src/chain/index.ts +0 -6
- package/src/crypto/aes.ts +0 -104
- package/src/crypto/constants.ts +0 -7
- package/src/crypto/ecies.ts +0 -60
- package/src/crypto/envelope.ts +0 -131
- package/src/crypto/hkdf.ts +0 -45
- package/src/crypto/index.ts +0 -6
- package/src/crypto/keys.ts +0 -56
- package/src/errors/BlindMarketError.ts +0 -38
- package/src/errors/codes.ts +0 -67
- package/src/errors/index.ts +0 -3
- package/src/errors/subclasses.ts +0 -59
- package/src/events/EventBus.ts +0 -45
- package/src/events/index.ts +0 -2
- package/src/events/types.ts +0 -13
- package/src/index.ts +0 -617
- package/src/keystore/InMemoryKeyStore.ts +0 -146
- package/src/keystore/KeyStore.ts +0 -19
- package/src/keystore/index.ts +0 -2
- package/src/network/index.ts +0 -3
- package/src/network/presets.ts +0 -27
- package/src/network/resolve.ts +0 -19
- package/src/network/types.ts +0 -18
- package/src/signer/EthersSigner.ts +0 -82
- package/src/signer/PrivateKeySigner.ts +0 -19
- package/src/signer/Signer.ts +0 -40
- package/src/signer/index.ts +0 -3
- package/src/storage/MemoryStorage.ts +0 -49
- package/src/storage/Storage.ts +0 -15
- package/src/storage/ZgStorage.ts +0 -124
- package/src/storage/index.ts +0 -3
- package/src/testing/index.ts +0 -1
- package/src/tools/adapters.ts +0 -177
- package/src/tools/helpers.ts +0 -199
- package/src/tools/index.ts +0 -59
- package/src/tools/types.ts +0 -47
- package/src/types.ts +0 -296
- package/src/verifier/index.ts +0 -1
- package/src/worker/Worker.ts +0 -98
- package/src/worker/index.ts +0 -1
- package/test/agent.test.ts +0 -193
- package/test/chain.test.ts +0 -145
- package/test/crypto.aes.test.ts +0 -81
- package/test/crypto.compat.test.ts +0 -33
- package/test/crypto.ecies.test.ts +0 -64
- package/test/envelope.test.ts +0 -82
- package/test/errors.test.ts +0 -64
- package/test/events.test.ts +0 -59
- package/test/fixtures/crypto.json +0 -16
- package/test/keystore.test.ts +0 -103
- package/test/network.test.ts +0 -53
- package/test/signer.test.ts +0 -66
- package/test/smoke.test.ts +0 -7
- package/test/storage.test.ts +0 -55
- package/test/worker.test.ts +0 -181
- package/tsconfig.build.json +0 -1
- package/tsconfig.json +0 -14
- package/tsup.config.ts +0 -32
- package/vitest.config.ts +0 -17
- /package/{src/api/index.ts → dist/chain/IBlindMarketChain.js} +0 -0
- /package/{src/compute/index.ts → dist/chain/domain-types.js} +0 -0
package/test/network.test.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { ConfigError } from '../src/errors/index.js';
|
|
3
|
-
import { networks, resolveNetwork, type Network } from '../src/network/index.js';
|
|
4
|
-
|
|
5
|
-
describe('networks', () => {
|
|
6
|
-
it('testnet preset matches 0G Galileo', () => {
|
|
7
|
-
expect(networks.testnet.chainId).toBe(16602n);
|
|
8
|
-
expect(networks.testnet.contracts.escrow).toMatch(/^0x[a-fA-F0-9]{40}$/);
|
|
9
|
-
expect(networks.testnet.contracts.registry).toMatch(/^0x[a-fA-F0-9]{40}$/);
|
|
10
|
-
expect(networks.testnet.contracts.reputation).toMatch(/^0x[a-fA-F0-9]{40}$/);
|
|
11
|
-
expect(networks.testnet.contracts.usdc).toMatch(/^0x[a-fA-F0-9]{40}$/);
|
|
12
|
-
expect(networks.testnet.rpc.length).toBeGreaterThan(0);
|
|
13
|
-
expect(networks.testnet.indexer).toBeTruthy();
|
|
14
|
-
expect(networks.testnet.broker).toBeTruthy();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('testnet addresses match contracts/deployments/0g-testnet.json', () => {
|
|
18
|
-
expect(networks.testnet.contracts.escrow).toBe('0xFd4F93F5A7BE144c405D1D8fbEC63Fb776207681');
|
|
19
|
-
expect(networks.testnet.contracts.registry).toBe('0xeE52d780A47F77E8a4a1cEb236e3C65A48FbD828');
|
|
20
|
-
expect(networks.testnet.contracts.reputation).toBe('0x4A6374Fae37E19E69ba43E7cf6994AC15F63256e');
|
|
21
|
-
expect(networks.testnet.contracts.usdc).toBe('0x317227efcA18D004E12CA8046AEf7E1597458F25');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('resolveNetwork accepts a preset name', () => {
|
|
25
|
-
const n = resolveNetwork('testnet');
|
|
26
|
-
expect(n.chainId).toBe(16602n);
|
|
27
|
-
expect(n.name).toBe('0g-galileo-testnet');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('resolveNetwork rejects unknown preset with ConfigError', () => {
|
|
31
|
-
// biome-ignore lint/suspicious/noExplicitAny: intentional type escape to test runtime error path
|
|
32
|
-
expect(() => resolveNetwork('nope' as any)).toThrow(ConfigError);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('resolveNetwork passes through a custom network object', () => {
|
|
36
|
-
const custom: Network = {
|
|
37
|
-
name: 'localhost',
|
|
38
|
-
chainId: 1337n,
|
|
39
|
-
rpc: ['http://localhost:8545'],
|
|
40
|
-
contracts: {
|
|
41
|
-
escrow: '0x0000000000000000000000000000000000000001',
|
|
42
|
-
registry: '0x0000000000000000000000000000000000000002',
|
|
43
|
-
reputation: '0x0000000000000000000000000000000000000003',
|
|
44
|
-
usdc: '0x0000000000000000000000000000000000000004',
|
|
45
|
-
},
|
|
46
|
-
indexer: '',
|
|
47
|
-
broker: '',
|
|
48
|
-
};
|
|
49
|
-
const resolved = resolveNetwork(custom);
|
|
50
|
-
expect(resolved).toBe(custom);
|
|
51
|
-
expect(resolved.chainId).toBe(1337n);
|
|
52
|
-
});
|
|
53
|
-
});
|
package/test/signer.test.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import { eciesDecrypt, eciesEncrypt } from '../src/crypto/index.js';
|
|
4
|
-
import { EthersSigner, PrivateKeySigner } from '../src/signer/index.js';
|
|
5
|
-
|
|
6
|
-
const FIXED_PK = '0x0123456789012345678901234567890123456789012345678901234567890123';
|
|
7
|
-
const FIXED_ADDR = '0x14791697260E4c9A71f18484C9f997B308e59325';
|
|
8
|
-
|
|
9
|
-
describe('PrivateKeySigner', () => {
|
|
10
|
-
it('derives the correct address from a known private key', async () => {
|
|
11
|
-
const signer = new PrivateKeySigner(FIXED_PK);
|
|
12
|
-
expect((await signer.getAddress()).toLowerCase()).toBe(FIXED_ADDR.toLowerCase());
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('accepts the private key with or without 0x prefix', async () => {
|
|
16
|
-
const a = new PrivateKeySigner(FIXED_PK);
|
|
17
|
-
const b = new PrivateKeySigner(FIXED_PK.slice(2));
|
|
18
|
-
expect(await a.getAddress()).toBe(await b.getAddress());
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('signMessage produces a signature that recovers to the signer address', async () => {
|
|
22
|
-
const signer = new PrivateKeySigner(FIXED_PK);
|
|
23
|
-
const msg = 'hello';
|
|
24
|
-
const sig = await signer.signMessage(msg);
|
|
25
|
-
const recovered = ethers.verifyMessage(msg, sig);
|
|
26
|
-
expect(recovered.toLowerCase()).toBe(FIXED_ADDR.toLowerCase());
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('getPublicKey returns the uncompressed key (65 bytes / 130 hex + 0x)', async () => {
|
|
30
|
-
const signer = new PrivateKeySigner(FIXED_PK);
|
|
31
|
-
const pub = await signer.getPublicKey();
|
|
32
|
-
expect(pub.startsWith('0x04')).toBe(true);
|
|
33
|
-
expect(pub.length).toBe(2 + 130);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('pubkey from signer round-trips through ECIES', async () => {
|
|
37
|
-
const signer = new PrivateKeySigner(FIXED_PK);
|
|
38
|
-
const pub = await signer.getPublicKey();
|
|
39
|
-
const plaintext = new TextEncoder().encode('direct-to-signer-pubkey');
|
|
40
|
-
const blob = await eciesEncrypt(plaintext, pub);
|
|
41
|
-
const pt = await eciesDecrypt(blob, FIXED_PK);
|
|
42
|
-
expect(new TextDecoder().decode(pt)).toBe('direct-to-signer-pubkey');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('getPublicKey is cached (returns identical string instance)', async () => {
|
|
46
|
-
const signer = new PrivateKeySigner(FIXED_PK);
|
|
47
|
-
const a = await signer.getPublicKey();
|
|
48
|
-
const b = await signer.getPublicKey();
|
|
49
|
-
expect(a).toBe(b);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
describe('EthersSigner wrapping an arbitrary ethers.Signer', () => {
|
|
54
|
-
it('wraps a provider-less Wallet and passes through signMessage', async () => {
|
|
55
|
-
const wallet = new ethers.Wallet(FIXED_PK);
|
|
56
|
-
const signer = new EthersSigner(wallet);
|
|
57
|
-
const sig = await signer.signMessage('x');
|
|
58
|
-
expect(ethers.verifyMessage('x', sig).toLowerCase()).toBe(FIXED_ADDR.toLowerCase());
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('chainId throws ConfigError when no provider is attached', async () => {
|
|
62
|
-
const wallet = new ethers.Wallet(FIXED_PK);
|
|
63
|
-
const signer = new EthersSigner(wallet);
|
|
64
|
-
await expect(signer.chainId()).rejects.toMatchObject({ code: 'CONFIG/BAD_CONFIG' });
|
|
65
|
-
});
|
|
66
|
-
});
|
package/test/smoke.test.ts
DELETED
package/test/storage.test.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { StorageError } from '../src/errors/index.js';
|
|
3
|
-
import { MemoryStorage } from '../src/storage/index.js';
|
|
4
|
-
|
|
5
|
-
describe('MemoryStorage', () => {
|
|
6
|
-
it('upload returns deterministic root hash for the same bytes', async () => {
|
|
7
|
-
const s = new MemoryStorage();
|
|
8
|
-
const bytes = new TextEncoder().encode('hello');
|
|
9
|
-
const a = await s.upload(bytes);
|
|
10
|
-
const b = await s.upload(bytes);
|
|
11
|
-
expect(a.rootHash).toBe(b.rootHash);
|
|
12
|
-
expect(a.size).toBe(5);
|
|
13
|
-
expect(s.size()).toBe(1);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('download returns the uploaded bytes', async () => {
|
|
17
|
-
const s = new MemoryStorage();
|
|
18
|
-
const bytes = new TextEncoder().encode('payload');
|
|
19
|
-
const { rootHash } = await s.upload(bytes);
|
|
20
|
-
const got = await s.download(rootHash);
|
|
21
|
-
expect(new TextDecoder().decode(got)).toBe('payload');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('download of unknown hash throws STORAGE/NOT_FOUND', async () => {
|
|
25
|
-
const s = new MemoryStorage();
|
|
26
|
-
await expect(s.download('0x' + '00'.repeat(32) as `0x${string}`)).rejects.toBeInstanceOf(StorageError);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('hash is content-addressed and matches SHA-256', async () => {
|
|
30
|
-
const s = new MemoryStorage();
|
|
31
|
-
const h = await s.hash(new TextEncoder().encode('abc'));
|
|
32
|
-
// Known vector for SHA-256('abc')
|
|
33
|
-
expect(h).toBe('0xba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad');
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('returned bytes are a copy (mutation does not affect stored blob)', async () => {
|
|
37
|
-
const s = new MemoryStorage();
|
|
38
|
-
const bytes = new TextEncoder().encode('one');
|
|
39
|
-
const { rootHash } = await s.upload(bytes);
|
|
40
|
-
const a = await s.download(rootHash);
|
|
41
|
-
// biome-ignore lint/style/noNonNullAssertion: non-empty
|
|
42
|
-
a[0] = (a[0]! ^ 0xff) & 0xff;
|
|
43
|
-
const b = await s.download(rootHash);
|
|
44
|
-
expect(b[0]).not.toBe(a[0]);
|
|
45
|
-
expect(new TextDecoder().decode(b)).toBe('one');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('clear wipes all blobs', async () => {
|
|
49
|
-
const s = new MemoryStorage();
|
|
50
|
-
await s.upload(new Uint8Array([1]));
|
|
51
|
-
expect(s.size()).toBe(1);
|
|
52
|
-
s.clear();
|
|
53
|
-
expect(s.size()).toBe(0);
|
|
54
|
-
});
|
|
55
|
-
});
|
package/test/worker.test.ts
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import type {
|
|
3
|
-
BlindEscrowClient,
|
|
4
|
-
CreateTaskArgs,
|
|
5
|
-
OnChainTask,
|
|
6
|
-
TaskRegistryClient,
|
|
7
|
-
} from '../src/chain/index.js';
|
|
8
|
-
import {
|
|
9
|
-
aesEncrypt,
|
|
10
|
-
eciesEncrypt,
|
|
11
|
-
generateAesKey,
|
|
12
|
-
generateKeyPair,
|
|
13
|
-
openEvidenceAsAgent,
|
|
14
|
-
} from '../src/crypto/index.js';
|
|
15
|
-
import { EventBus, type SdkEvents } from '../src/events/index.js';
|
|
16
|
-
import { PrivateKeySigner } from '../src/signer/index.js';
|
|
17
|
-
import { MemoryStorage } from '../src/storage/index.js';
|
|
18
|
-
import type { Address, Hex, RootHash, TaskId, TxReceiptLike } from '../src/types.js';
|
|
19
|
-
import { Worker } from '../src/worker/index.js';
|
|
20
|
-
|
|
21
|
-
const WORKER_PK = '0x1000000000000000000000000000000000000000000000000000000000000001';
|
|
22
|
-
const FAKE_USDC = '0x317227efcA18D004E12CA8046AEf7E1597458F25' as Address;
|
|
23
|
-
const FAKE_TASK_HASH = `0x${'ab'.repeat(32)}` as Hex;
|
|
24
|
-
|
|
25
|
-
class MockEscrow {
|
|
26
|
-
readonly calls: Array<{ method: string; args: unknown }> = [];
|
|
27
|
-
async submitEvidence(taskId: TaskId, evidenceHash: Hex): Promise<TxReceiptLike> {
|
|
28
|
-
this.calls.push({ method: 'submitEvidence', args: { taskId, evidenceHash } });
|
|
29
|
-
return { hash: `0x${'11'.repeat(32)}` as Hex, blockNumber: 10, gasUsed: 21000n };
|
|
30
|
-
}
|
|
31
|
-
async claimTimeout(taskId: TaskId): Promise<TxReceiptLike> {
|
|
32
|
-
this.calls.push({ method: 'claimTimeout', args: { taskId } });
|
|
33
|
-
return { hash: `0x${'22'.repeat(32)}` as Hex, blockNumber: 20, gasUsed: 21000n };
|
|
34
|
-
}
|
|
35
|
-
async getTask(_taskId: TaskId): Promise<OnChainTask> {
|
|
36
|
-
const t: OnChainTask = {
|
|
37
|
-
taskId: 1n,
|
|
38
|
-
agent: '0x0000000000000000000000000000000000000001' as Address,
|
|
39
|
-
worker: '0x0000000000000000000000000000000000000002' as Address,
|
|
40
|
-
token: FAKE_USDC,
|
|
41
|
-
amount: 5_000000n,
|
|
42
|
-
taskHash: FAKE_TASK_HASH,
|
|
43
|
-
evidenceHash: `0x${'00'.repeat(32)}` as Hex,
|
|
44
|
-
status: 'assigned',
|
|
45
|
-
createdAt: new Date(),
|
|
46
|
-
deadline: new Date(Date.now() + 3600_000),
|
|
47
|
-
};
|
|
48
|
-
return t;
|
|
49
|
-
}
|
|
50
|
-
// unused but required for shape
|
|
51
|
-
async createTask(_args: CreateTaskArgs) {
|
|
52
|
-
return { taskId: 1n, receipt: { hash: '0x' as Hex, blockNumber: 0, gasUsed: 0n } };
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
class MockRegistry {
|
|
57
|
-
async getOpenTasks(_offset: bigint, _limit: bigint): Promise<TaskId[]> {
|
|
58
|
-
return [1n, 2n, 3n];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function mkDeps() {
|
|
63
|
-
const storage = new MemoryStorage();
|
|
64
|
-
const signer = new PrivateKeySigner(WORKER_PK);
|
|
65
|
-
const events = new EventBus<SdkEvents>();
|
|
66
|
-
const escrow = new MockEscrow();
|
|
67
|
-
const registry = new MockRegistry();
|
|
68
|
-
return {
|
|
69
|
-
storage,
|
|
70
|
-
signer,
|
|
71
|
-
events,
|
|
72
|
-
escrow,
|
|
73
|
-
registry,
|
|
74
|
-
worker: new Worker({
|
|
75
|
-
// biome-ignore lint/suspicious/noExplicitAny: mocks match the subset used
|
|
76
|
-
escrow: escrow as any as BlindEscrowClient,
|
|
77
|
-
// biome-ignore lint/suspicious/noExplicitAny: mocks match the subset used
|
|
78
|
-
registry: registry as any as TaskRegistryClient,
|
|
79
|
-
storage,
|
|
80
|
-
signer,
|
|
81
|
-
events,
|
|
82
|
-
}),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
describe('Worker.browse + getTaskDetail', () => {
|
|
87
|
-
it('delegates to registry.getOpenTasks', async () => {
|
|
88
|
-
const { worker } = mkDeps();
|
|
89
|
-
const ids = await worker.browse(0n, 10n);
|
|
90
|
-
expect(ids).toEqual([1n, 2n, 3n]);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('returns task detail from escrow.getTask', async () => {
|
|
94
|
-
const { worker } = mkDeps();
|
|
95
|
-
const detail = await worker.getTaskDetail(1n);
|
|
96
|
-
expect(detail.status).toBe('assigned');
|
|
97
|
-
expect(detail.token).toBe(FAKE_USDC);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe('Worker.decryptInstructions', () => {
|
|
102
|
-
it('recovers plaintext instructions end-to-end', async () => {
|
|
103
|
-
const { worker, storage, signer } = mkDeps();
|
|
104
|
-
|
|
105
|
-
// Simulate agent side: generate AES key, encrypt instructions, upload, and
|
|
106
|
-
// wrap AES key to worker pubkey.
|
|
107
|
-
const aesKey = await generateAesKey();
|
|
108
|
-
const instructions = new TextEncoder().encode('photograph the storefront at 123 Main St');
|
|
109
|
-
const ciphertext = await aesEncrypt(instructions, aesKey);
|
|
110
|
-
const { rootHash } = await storage.upload(ciphertext);
|
|
111
|
-
const workerPub = await signer.getPublicKey();
|
|
112
|
-
const wrappedKey = await eciesEncrypt(aesKey, workerPub);
|
|
113
|
-
|
|
114
|
-
const decrypted = await worker.decryptInstructions({
|
|
115
|
-
wrappedKey,
|
|
116
|
-
workerPrivKey: WORKER_PK,
|
|
117
|
-
taskHash: rootHash,
|
|
118
|
-
});
|
|
119
|
-
expect(new TextDecoder().decode(decrypted)).toBe('photograph the storefront at 123 Main St');
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
describe('Worker.submitEvidence', () => {
|
|
124
|
-
it('seals envelope + uploads + calls chain + emits event; agent can decrypt', async () => {
|
|
125
|
-
const { worker, storage, escrow, events } = mkDeps();
|
|
126
|
-
|
|
127
|
-
const agent = generateKeyPair();
|
|
128
|
-
const enclave = generateKeyPair();
|
|
129
|
-
|
|
130
|
-
const submitted: SdkEvents['evidence.submitted'][] = [];
|
|
131
|
-
events.on('evidence.submitted', (p) => submitted.push(p));
|
|
132
|
-
|
|
133
|
-
const res = await worker.submitEvidence({
|
|
134
|
-
taskId: 42n,
|
|
135
|
-
evidence: 'done: photos uploaded',
|
|
136
|
-
agentPubKey: agent.publicKey,
|
|
137
|
-
enclavePubKey: enclave.publicKey,
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
expect(res.rootHash).toMatch(/^0x[0-9a-f]{64}$/);
|
|
141
|
-
expect(escrow.calls.some((c) => c.method === 'submitEvidence')).toBe(true);
|
|
142
|
-
|
|
143
|
-
// Agent can download + decrypt the envelope
|
|
144
|
-
const blob = await storage.download(res.rootHash as RootHash);
|
|
145
|
-
const recovered = await openEvidenceAsAgent(blob, agent.privateKey);
|
|
146
|
-
expect(new TextDecoder().decode(recovered)).toBe('done: photos uploaded');
|
|
147
|
-
|
|
148
|
-
expect(submitted).toHaveLength(1);
|
|
149
|
-
expect(submitted[0]?.taskId).toBe(42n);
|
|
150
|
-
expect(submitted[0]?.rootHash).toBe(res.rootHash);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('accepts Uint8Array evidence as well as strings', async () => {
|
|
154
|
-
const { worker, storage } = mkDeps();
|
|
155
|
-
const agent = generateKeyPair();
|
|
156
|
-
const enclave = generateKeyPair();
|
|
157
|
-
const res = await worker.submitEvidence({
|
|
158
|
-
taskId: 1n,
|
|
159
|
-
evidence: new Uint8Array([0xde, 0xad, 0xbe, 0xef]),
|
|
160
|
-
agentPubKey: agent.publicKey,
|
|
161
|
-
enclavePubKey: enclave.publicKey,
|
|
162
|
-
});
|
|
163
|
-
const blob = await storage.download(res.rootHash);
|
|
164
|
-
const recovered = await openEvidenceAsAgent(blob, agent.privateKey);
|
|
165
|
-
expect(Array.from(recovered)).toEqual([0xde, 0xad, 0xbe, 0xef]);
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
describe('Worker.claimTimeout', () => {
|
|
170
|
-
it('calls chain and emits payment.claimed', async () => {
|
|
171
|
-
const { worker, escrow, events } = mkDeps();
|
|
172
|
-
const claimed: SdkEvents['payment.claimed'][] = [];
|
|
173
|
-
events.on('payment.claimed', (p) => claimed.push(p));
|
|
174
|
-
|
|
175
|
-
const rec = await worker.claimTimeout(7n);
|
|
176
|
-
expect(rec.hash).toMatch(/^0x[0-9a-f]{64}$/);
|
|
177
|
-
expect(escrow.calls.some((c) => c.method === 'claimTimeout')).toBe(true);
|
|
178
|
-
expect(claimed).toHaveLength(1);
|
|
179
|
-
expect(claimed[0]?.taskId).toBe(7n);
|
|
180
|
-
});
|
|
181
|
-
});
|
package/tsconfig.build.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{ "extends": "./tsconfig.json", "compilerOptions": { "noEmit": false }, "exclude": ["test/**/*", "node_modules", "dist"] }
|
package/tsconfig.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "NodeNext",
|
|
5
|
-
"moduleResolution": "NodeNext",
|
|
6
|
-
"outDir": "dist",
|
|
7
|
-
"rootDir": "src",
|
|
8
|
-
"declaration": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"skipLibCheck": true
|
|
11
|
-
},
|
|
12
|
-
"include": ["src"],
|
|
13
|
-
"exclude": ["src/storage/ZgStorage.ts"]
|
|
14
|
-
}
|
package/tsup.config.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'tsup';
|
|
2
|
-
|
|
3
|
-
const entries = [
|
|
4
|
-
'src/index.ts',
|
|
5
|
-
'src/agent/index.ts',
|
|
6
|
-
'src/worker/index.ts',
|
|
7
|
-
'src/verifier/index.ts',
|
|
8
|
-
'src/chain/index.ts',
|
|
9
|
-
'src/storage/index.ts',
|
|
10
|
-
'src/compute/index.ts',
|
|
11
|
-
'src/crypto/index.ts',
|
|
12
|
-
'src/api/index.ts',
|
|
13
|
-
'src/signer/index.ts',
|
|
14
|
-
'src/keystore/index.ts',
|
|
15
|
-
'src/events/index.ts',
|
|
16
|
-
'src/errors/index.ts',
|
|
17
|
-
'src/network/index.ts',
|
|
18
|
-
'src/testing/index.ts',
|
|
19
|
-
];
|
|
20
|
-
|
|
21
|
-
export default defineConfig({
|
|
22
|
-
entry: entries,
|
|
23
|
-
format: ['esm', 'cjs'],
|
|
24
|
-
dts: true,
|
|
25
|
-
sourcemap: true,
|
|
26
|
-
clean: true,
|
|
27
|
-
treeshake: true,
|
|
28
|
-
splitting: false,
|
|
29
|
-
target: 'es2022',
|
|
30
|
-
tsconfig: './tsconfig.build.json',
|
|
31
|
-
outDir: 'dist',
|
|
32
|
-
});
|
package/vitest.config.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vitest/config';
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
test: {
|
|
5
|
-
environment: 'node',
|
|
6
|
-
globals: false,
|
|
7
|
-
include: ['test/**/*.test.ts'],
|
|
8
|
-
coverage: {
|
|
9
|
-
provider: 'v8',
|
|
10
|
-
reporter: ['text', 'html', 'lcov'],
|
|
11
|
-
include: ['src/**/*.ts'],
|
|
12
|
-
exclude: ['src/**/index.ts', 'src/**/*.d.ts'],
|
|
13
|
-
thresholds: { lines: 90, functions: 90, branches: 85, statements: 90 },
|
|
14
|
-
},
|
|
15
|
-
testTimeout: 20_000,
|
|
16
|
-
},
|
|
17
|
-
});
|
|
File without changes
|
|
File without changes
|