clawmarket 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/README.md +142 -0
- package/dist/api-proxy.d.ts +11 -0
- package/dist/api-proxy.d.ts.map +1 -0
- package/dist/api-proxy.js +98 -0
- package/dist/api-proxy.js.map +1 -0
- package/dist/buyer/discovery.d.ts +52 -0
- package/dist/buyer/discovery.d.ts.map +1 -0
- package/dist/buyer/discovery.js +121 -0
- package/dist/buyer/discovery.js.map +1 -0
- package/dist/buyer/index.d.ts +4 -0
- package/dist/buyer/index.d.ts.map +1 -0
- package/dist/buyer/index.js +4 -0
- package/dist/buyer/index.js.map +1 -0
- package/dist/buyer/mode.d.ts +60 -0
- package/dist/buyer/mode.d.ts.map +1 -0
- package/dist/buyer/mode.js +150 -0
- package/dist/buyer/mode.js.map +1 -0
- package/dist/buyer/relay.d.ts +27 -0
- package/dist/buyer/relay.d.ts.map +1 -0
- package/dist/buyer/relay.js +103 -0
- package/dist/buyer/relay.js.map +1 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +252 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +29 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +37 -0
- package/dist/config.js.map +1 -0
- package/dist/crypto/e2ee.d.ts +45 -0
- package/dist/crypto/e2ee.d.ts.map +1 -0
- package/dist/crypto/e2ee.js +87 -0
- package/dist/crypto/e2ee.js.map +1 -0
- package/dist/crypto/index.d.ts +3 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.js +3 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/crypto/ticket.d.ts +62 -0
- package/dist/crypto/ticket.d.ts.map +1 -0
- package/dist/crypto/ticket.js +123 -0
- package/dist/crypto/ticket.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/local-proxy.d.ts +12 -0
- package/dist/local-proxy.d.ts.map +1 -0
- package/dist/local-proxy.js +593 -0
- package/dist/local-proxy.js.map +1 -0
- package/dist/openclaw-adapter.d.ts +105 -0
- package/dist/openclaw-adapter.d.ts.map +1 -0
- package/dist/openclaw-adapter.js +125 -0
- package/dist/openclaw-adapter.js.map +1 -0
- package/dist/provider.d.ts +116 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +328 -0
- package/dist/provider.js.map +1 -0
- package/dist/seller/index.d.ts +4 -0
- package/dist/seller/index.d.ts.map +1 -0
- package/dist/seller/index.js +4 -0
- package/dist/seller/index.js.map +1 -0
- package/dist/seller/mode.d.ts +62 -0
- package/dist/seller/mode.d.ts.map +1 -0
- package/dist/seller/mode.js +179 -0
- package/dist/seller/mode.js.map +1 -0
- package/dist/seller/registry.d.ts +27 -0
- package/dist/seller/registry.d.ts.map +1 -0
- package/dist/seller/registry.js +95 -0
- package/dist/seller/registry.js.map +1 -0
- package/dist/seller/relay.d.ts +64 -0
- package/dist/seller/relay.d.ts.map +1 -0
- package/dist/seller/relay.js +171 -0
- package/dist/seller/relay.js.map +1 -0
- package/dist/seller-cli.d.ts +26 -0
- package/dist/seller-cli.d.ts.map +1 -0
- package/dist/seller-cli.js +354 -0
- package/dist/seller-cli.js.map +1 -0
- package/dist/seller-daemon.d.ts +7 -0
- package/dist/seller-daemon.d.ts.map +1 -0
- package/dist/seller-daemon.js +349 -0
- package/dist/seller-daemon.js.map +1 -0
- package/dist/types/config.d.ts +529 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +81 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/protocol.d.ts +131 -0
- package/dist/types/protocol.d.ts.map +1 -0
- package/dist/types/protocol.js +2 -0
- package/dist/types/protocol.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Key pair for E2EE communication
|
|
3
|
+
*/
|
|
4
|
+
export interface KeyPair {
|
|
5
|
+
privateKey: Uint8Array;
|
|
6
|
+
publicKey: Uint8Array;
|
|
7
|
+
secretKey: Uint8Array;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Generate a new secp256k1 key pair
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateKeyPair(): KeyPair;
|
|
13
|
+
/**
|
|
14
|
+
* Derive public key from private key
|
|
15
|
+
*/
|
|
16
|
+
export declare function getPublicKey(privateKey: Uint8Array): Uint8Array;
|
|
17
|
+
/**
|
|
18
|
+
* Compute shared secret using ECDH
|
|
19
|
+
*/
|
|
20
|
+
export declare function computeSharedSecret(privateKey: Uint8Array, publicKey: Uint8Array): Uint8Array;
|
|
21
|
+
/**
|
|
22
|
+
* Encrypt data using AES-256-GCM with ECDH shared secret
|
|
23
|
+
*/
|
|
24
|
+
export declare function encrypt(plaintext: string, senderPrivateKey: Uint8Array, recipientPublicKey: Uint8Array): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Decrypt data using AES-256-GCM with ECDH shared secret
|
|
27
|
+
*/
|
|
28
|
+
export declare function decrypt(encryptedBase64: string, recipientPrivateKey: Uint8Array, senderPublicKey: Uint8Array): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Convert hex string to Uint8Array
|
|
31
|
+
*/
|
|
32
|
+
export declare function hexToBytes(hex: string): Uint8Array;
|
|
33
|
+
/**
|
|
34
|
+
* Convert Uint8Array to hex string
|
|
35
|
+
*/
|
|
36
|
+
export declare function bytesToHex(bytes: Uint8Array): string;
|
|
37
|
+
/**
|
|
38
|
+
* Serialize public key for transmission
|
|
39
|
+
*/
|
|
40
|
+
export declare function serializePublicKey(publicKey: Uint8Array): string;
|
|
41
|
+
/**
|
|
42
|
+
* Deserialize public key from transmission
|
|
43
|
+
*/
|
|
44
|
+
export declare function deserializePublicKey(serialized: string): Uint8Array;
|
|
45
|
+
//# sourceMappingURL=e2ee.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"e2ee.d.ts","sourceRoot":"","sources":["../../src/crypto/e2ee.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,EAAE,UAAU,CAAC;IACtB,SAAS,EAAE,UAAU,CAAC;CACvB;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAIzC;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAE/D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,UAAU,GACpB,UAAU,CAIZ;AAED;;GAEG;AACH,wBAAsB,OAAO,CAC3B,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,UAAU,EAC5B,kBAAkB,EAAE,UAAU,GAC7B,OAAO,CAAC,MAAM,CAAC,CA8BjB;AAED;;GAEG;AACH,wBAAsB,OAAO,CAC3B,eAAe,EAAE,MAAM,EACvB,mBAAmB,EAAE,UAAU,EAC/B,eAAe,EAAE,UAAU,GAC1B,OAAO,CAAC,MAAM,CAAC,CA4BjB;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAGlD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEpD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM,CAEhE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,CAEnE"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import * as secp256k1 from '@noble/secp256k1';
|
|
2
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
3
|
+
import { randomBytes } from 'crypto';
|
|
4
|
+
/**
|
|
5
|
+
* Generate a new secp256k1 key pair
|
|
6
|
+
*/
|
|
7
|
+
export function generateKeyPair() {
|
|
8
|
+
const privateKey = secp256k1.utils.randomPrivateKey();
|
|
9
|
+
const publicKey = secp256k1.getPublicKey(privateKey, false); // uncompressed
|
|
10
|
+
return { privateKey, publicKey, secretKey: privateKey };
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Derive public key from private key
|
|
14
|
+
*/
|
|
15
|
+
export function getPublicKey(privateKey) {
|
|
16
|
+
return secp256k1.getPublicKey(privateKey, false);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Compute shared secret using ECDH
|
|
20
|
+
*/
|
|
21
|
+
export function computeSharedSecret(privateKey, publicKey) {
|
|
22
|
+
const shared = secp256k1.getSharedSecret(privateKey, publicKey);
|
|
23
|
+
// Hash the shared secret to get a 32-byte key
|
|
24
|
+
return sha256(shared);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Encrypt data using AES-256-GCM with ECDH shared secret
|
|
28
|
+
*/
|
|
29
|
+
export async function encrypt(plaintext, senderPrivateKey, recipientPublicKey) {
|
|
30
|
+
const sharedSecret = computeSharedSecret(senderPrivateKey, recipientPublicKey);
|
|
31
|
+
// Generate random IV (12 bytes for GCM)
|
|
32
|
+
const iv = randomBytes(12);
|
|
33
|
+
// Import key for Web Crypto API
|
|
34
|
+
const key = await crypto.subtle.importKey('raw', sharedSecret, { name: 'AES-GCM' }, false, ['encrypt']);
|
|
35
|
+
// Encrypt
|
|
36
|
+
const encoder = new TextEncoder();
|
|
37
|
+
const data = encoder.encode(plaintext);
|
|
38
|
+
const ciphertext = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, key, data);
|
|
39
|
+
// Combine IV + ciphertext and encode as base64
|
|
40
|
+
const combined = new Uint8Array(iv.length + ciphertext.byteLength);
|
|
41
|
+
combined.set(iv, 0);
|
|
42
|
+
combined.set(new Uint8Array(ciphertext), iv.length);
|
|
43
|
+
return Buffer.from(combined).toString('base64');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Decrypt data using AES-256-GCM with ECDH shared secret
|
|
47
|
+
*/
|
|
48
|
+
export async function decrypt(encryptedBase64, recipientPrivateKey, senderPublicKey) {
|
|
49
|
+
const sharedSecret = computeSharedSecret(recipientPrivateKey, senderPublicKey);
|
|
50
|
+
// Decode base64
|
|
51
|
+
const combined = Buffer.from(encryptedBase64, 'base64');
|
|
52
|
+
// Extract IV and ciphertext
|
|
53
|
+
const iv = combined.subarray(0, 12);
|
|
54
|
+
const ciphertext = combined.subarray(12);
|
|
55
|
+
// Import key
|
|
56
|
+
const key = await crypto.subtle.importKey('raw', sharedSecret, { name: 'AES-GCM' }, false, ['decrypt']);
|
|
57
|
+
// Decrypt
|
|
58
|
+
const plaintext = await crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, ciphertext);
|
|
59
|
+
const decoder = new TextDecoder();
|
|
60
|
+
return decoder.decode(plaintext);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Convert hex string to Uint8Array
|
|
64
|
+
*/
|
|
65
|
+
export function hexToBytes(hex) {
|
|
66
|
+
const cleanHex = hex.startsWith('0x') ? hex.slice(2) : hex;
|
|
67
|
+
return new Uint8Array(Buffer.from(cleanHex, 'hex'));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Convert Uint8Array to hex string
|
|
71
|
+
*/
|
|
72
|
+
export function bytesToHex(bytes) {
|
|
73
|
+
return '0x' + Buffer.from(bytes).toString('hex');
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Serialize public key for transmission
|
|
77
|
+
*/
|
|
78
|
+
export function serializePublicKey(publicKey) {
|
|
79
|
+
return bytesToHex(publicKey);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Deserialize public key from transmission
|
|
83
|
+
*/
|
|
84
|
+
export function deserializePublicKey(serialized) {
|
|
85
|
+
return hexToBytes(serialized);
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=e2ee.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"e2ee.js","sourceRoot":"","sources":["../../src/crypto/e2ee.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAWrC;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,UAAU,GAAG,SAAS,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC;IACtD,MAAM,SAAS,GAAG,SAAS,CAAC,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC,eAAe;IAC5E,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;AAC1D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,UAAsB;IACjD,OAAO,SAAS,CAAC,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;AACnD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,UAAsB,EACtB,SAAqB;IAErB,MAAM,MAAM,GAAG,SAAS,CAAC,eAAe,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IAChE,8CAA8C;IAC9C,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,SAAiB,EACjB,gBAA4B,EAC5B,kBAA8B;IAE9B,MAAM,YAAY,GAAG,mBAAmB,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;IAE/E,wCAAwC;IACxC,MAAM,EAAE,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;IAE3B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cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/crypto/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Ticket, SignedTicket } from '../types/protocol.js';
|
|
2
|
+
/**
|
|
3
|
+
* EIP-712 domain for ClawChannel contract
|
|
4
|
+
*/
|
|
5
|
+
export interface EIP712Domain {
|
|
6
|
+
name: string;
|
|
7
|
+
version: string;
|
|
8
|
+
chainId: number;
|
|
9
|
+
verifyingContract: `0x${string}`;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Default domain for Base Sepolia
|
|
13
|
+
*/
|
|
14
|
+
export declare function getDefaultDomain(contractAddress: `0x${string}`): EIP712Domain;
|
|
15
|
+
/**
|
|
16
|
+
* EIP-712 types for Ticket
|
|
17
|
+
*/
|
|
18
|
+
export declare const TICKET_TYPES: {
|
|
19
|
+
readonly Ticket: readonly [{
|
|
20
|
+
readonly name: "channelId";
|
|
21
|
+
readonly type: "bytes32";
|
|
22
|
+
}, {
|
|
23
|
+
readonly name: "amount";
|
|
24
|
+
readonly type: "uint256";
|
|
25
|
+
}, {
|
|
26
|
+
readonly name: "nonce";
|
|
27
|
+
readonly type: "uint256";
|
|
28
|
+
}];
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Ticket signer for buyers
|
|
32
|
+
*/
|
|
33
|
+
export declare class TicketSigner {
|
|
34
|
+
private walletClient;
|
|
35
|
+
private account;
|
|
36
|
+
private domain;
|
|
37
|
+
constructor(privateKey: `0x${string}`, contractAddress: `0x${string}`, rpcUrl: string, chainId?: number);
|
|
38
|
+
/**
|
|
39
|
+
* Get the signer's address
|
|
40
|
+
*/
|
|
41
|
+
get address(): `0x${string}`;
|
|
42
|
+
/**
|
|
43
|
+
* Sign a payment ticket
|
|
44
|
+
*/
|
|
45
|
+
signTicket(ticket: Ticket): Promise<SignedTicket>;
|
|
46
|
+
/**
|
|
47
|
+
* Create and sign a ticket with USD amount
|
|
48
|
+
*/
|
|
49
|
+
createTicket(channelId: `0x${string}`, amountUsd: number, nonce: bigint): Promise<SignedTicket>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Verify a ticket signature (for sellers)
|
|
53
|
+
*/
|
|
54
|
+
export declare function verifyTicketSignature(ticket: SignedTicket, expectedSigner: `0x${string}`, domain: EIP712Domain): Promise<boolean>;
|
|
55
|
+
/**
|
|
56
|
+
* Calculate ticket amount based on token usage
|
|
57
|
+
*/
|
|
58
|
+
export declare function calculateTicketAmount(inputTokens: number, outputTokens: number, pricing: {
|
|
59
|
+
inputPer1m: number;
|
|
60
|
+
outputPer1m: number;
|
|
61
|
+
}): number;
|
|
62
|
+
//# sourceMappingURL=ticket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ticket.d.ts","sourceRoot":"","sources":["../../src/crypto/ticket.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,KAAK,MAAM,EAAE,CAAC;CAClC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,eAAe,EAAE,KAAK,MAAM,EAAE,GAAG,YAAY,CAO7E;AAED;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;CAMf,CAAC;AAEX;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,MAAM,CAAe;gBAG3B,UAAU,EAAE,KAAK,MAAM,EAAE,EACzB,eAAe,EAAE,KAAK,MAAM,EAAE,EAC9B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,MAAc;IAyBzB;;OAEG;IACH,IAAI,OAAO,IAAI,KAAK,MAAM,EAAE,CAE3B;IAED;;OAEG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAmBvD;;OAEG;IACG,YAAY,CAChB,SAAS,EAAE,KAAK,MAAM,EAAE,EACxB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,YAAY,CAAC;CAUzB;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,YAAY,EACpB,cAAc,EAAE,KAAK,MAAM,EAAE,EAC7B,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,OAAO,CAAC,CAqBlB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GACnD,MAAM,CAIR"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { createWalletClient, http, parseUnits, } from 'viem';
|
|
2
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
3
|
+
import { baseSepolia } from 'viem/chains';
|
|
4
|
+
/**
|
|
5
|
+
* Default domain for Base Sepolia
|
|
6
|
+
*/
|
|
7
|
+
export function getDefaultDomain(contractAddress) {
|
|
8
|
+
return {
|
|
9
|
+
name: 'ClawChannel',
|
|
10
|
+
version: '1',
|
|
11
|
+
chainId: 84532, // Base Sepolia
|
|
12
|
+
verifyingContract: contractAddress,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* EIP-712 types for Ticket
|
|
17
|
+
*/
|
|
18
|
+
export const TICKET_TYPES = {
|
|
19
|
+
Ticket: [
|
|
20
|
+
{ name: 'channelId', type: 'bytes32' },
|
|
21
|
+
{ name: 'amount', type: 'uint256' },
|
|
22
|
+
{ name: 'nonce', type: 'uint256' },
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Ticket signer for buyers
|
|
27
|
+
*/
|
|
28
|
+
export class TicketSigner {
|
|
29
|
+
walletClient;
|
|
30
|
+
account;
|
|
31
|
+
domain;
|
|
32
|
+
constructor(privateKey, contractAddress, rpcUrl, chainId = 84532) {
|
|
33
|
+
this.account = privateKeyToAccount(privateKey);
|
|
34
|
+
const chain = chainId === 84532 ? baseSepolia : {
|
|
35
|
+
id: chainId,
|
|
36
|
+
name: 'Custom',
|
|
37
|
+
nativeCurrency: { name: 'ETH', symbol: 'ETH', decimals: 18 },
|
|
38
|
+
rpcUrls: { default: { http: [rpcUrl] } },
|
|
39
|
+
};
|
|
40
|
+
this.walletClient = createWalletClient({
|
|
41
|
+
account: this.account,
|
|
42
|
+
chain,
|
|
43
|
+
transport: http(rpcUrl),
|
|
44
|
+
});
|
|
45
|
+
this.domain = {
|
|
46
|
+
name: 'ClawChannel',
|
|
47
|
+
version: '1',
|
|
48
|
+
chainId,
|
|
49
|
+
verifyingContract: contractAddress,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get the signer's address
|
|
54
|
+
*/
|
|
55
|
+
get address() {
|
|
56
|
+
return this.account.address;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Sign a payment ticket
|
|
60
|
+
*/
|
|
61
|
+
async signTicket(ticket) {
|
|
62
|
+
const signature = await this.walletClient.signTypedData({
|
|
63
|
+
account: this.account,
|
|
64
|
+
domain: this.domain,
|
|
65
|
+
types: TICKET_TYPES,
|
|
66
|
+
primaryType: 'Ticket',
|
|
67
|
+
message: {
|
|
68
|
+
channelId: ticket.channelId,
|
|
69
|
+
amount: ticket.amount,
|
|
70
|
+
nonce: ticket.nonce,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
...ticket,
|
|
75
|
+
signature,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Create and sign a ticket with USD amount
|
|
80
|
+
*/
|
|
81
|
+
async createTicket(channelId, amountUsd, nonce) {
|
|
82
|
+
// Convert USD to USDC (6 decimals)
|
|
83
|
+
const amount = parseUnits(amountUsd.toFixed(6), 6);
|
|
84
|
+
return this.signTicket({
|
|
85
|
+
channelId,
|
|
86
|
+
amount,
|
|
87
|
+
nonce,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Verify a ticket signature (for sellers)
|
|
93
|
+
*/
|
|
94
|
+
export async function verifyTicketSignature(ticket, expectedSigner, domain) {
|
|
95
|
+
const { verifyTypedData } = await import('viem');
|
|
96
|
+
try {
|
|
97
|
+
const isValid = await verifyTypedData({
|
|
98
|
+
address: expectedSigner,
|
|
99
|
+
domain,
|
|
100
|
+
types: TICKET_TYPES,
|
|
101
|
+
primaryType: 'Ticket',
|
|
102
|
+
message: {
|
|
103
|
+
channelId: ticket.channelId,
|
|
104
|
+
amount: ticket.amount,
|
|
105
|
+
nonce: ticket.nonce,
|
|
106
|
+
},
|
|
107
|
+
signature: ticket.signature,
|
|
108
|
+
});
|
|
109
|
+
return isValid;
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Calculate ticket amount based on token usage
|
|
117
|
+
*/
|
|
118
|
+
export function calculateTicketAmount(inputTokens, outputTokens, pricing) {
|
|
119
|
+
const inputCost = (inputTokens / 1_000_000) * pricing.inputPer1m;
|
|
120
|
+
const outputCost = (outputTokens / 1_000_000) * pricing.outputPer1m;
|
|
121
|
+
return inputCost + outputCost;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=ticket.js.map
|
|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pB,cAA6B,EAC7B,MAAoB;IAEpB,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;IAEjD,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC;YACpC,OAAO,EAAE,cAAc;YACvB,MAAM;YACN,KAAK,EAAE,YAAY;YACnB,WAAW,EAAE,QAAQ;YACrB,OAAO,EAAE;gBACP,SAAS,EAAE,MAAM,CAAC,SAAS;gBAC3B,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,KAAK,EAAE,MAAM,CAAC,KAAK;aACpB;YACD,SAAS,EAAE,MAAM,CAAC,SAAS;SAC5B,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IACjB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,WAAmB,EACnB,YAAoB,EACpB,OAAoD;IAEpD,MAAM,SAAS,GAAG,CAAC,WAAW,GAAG,SAAS,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;IACjE,MAAM,UAAU,GAAG,CAAC,YAAY,GAAG,SAAS,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;IACpE,OAAO,SAAS,GAAG,UAAU,CAAC;AAChC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClawMarket OpenClaw Plugin
|
|
3
|
+
*
|
|
4
|
+
* 一键安装,自动配置
|
|
5
|
+
*/
|
|
6
|
+
export { ClawMarketProvider, initClawMarket } from './provider.js';
|
|
7
|
+
export { ClawMarketOpenClawProvider, createProvider, metadata } from './openclaw-adapter.js';
|
|
8
|
+
export { generateKeyPair, encrypt, decrypt } from './crypto/e2ee.js';
|
|
9
|
+
export * from './types/index.js';
|
|
10
|
+
export { createProvider as default } from './openclaw-adapter.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC7F,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACrE,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EAAE,cAAc,IAAI,OAAO,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClawMarket OpenClaw Plugin
|
|
3
|
+
*
|
|
4
|
+
* 一键安装,自动配置
|
|
5
|
+
*/
|
|
6
|
+
// 核心导出
|
|
7
|
+
export { ClawMarketProvider, initClawMarket } from './provider.js';
|
|
8
|
+
export { ClawMarketOpenClawProvider, createProvider, metadata } from './openclaw-adapter.js';
|
|
9
|
+
export { generateKeyPair, encrypt, decrypt } from './crypto/e2ee.js';
|
|
10
|
+
export * from './types/index.js';
|
|
11
|
+
// 默认导出 OpenClaw provider 创建函数
|
|
12
|
+
export { createProvider as default } from './openclaw-adapter.js';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO;AACP,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC7F,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACrE,cAAc,kBAAkB,CAAC;AAEjC,8BAA8B;AAC9B,OAAO,EAAE,cAAc,IAAI,OAAO,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* ClawMarket 本地代理 v3 - 流式微支付版
|
|
4
|
+
*
|
|
5
|
+
* 改动:
|
|
6
|
+
* - 直接 WebSocket 连 Relay(跳过 Gateway)
|
|
7
|
+
* - 流式接收 AI 响应,SSE 推给 OpenClaw
|
|
8
|
+
* - 收到 stream_end 后按实际 token 用量签最终 ticket
|
|
9
|
+
* - 保留 HTTP 兼容模式(非 stream 请求走旧路径)
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=local-proxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-proxy.d.ts","sourceRoot":"","sources":["../src/local-proxy.ts"],"names":[],"mappings":";AACA;;;;;;;;GAQG"}
|