@donezone/client 0.1.51 → 0.1.55
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 +542 -71
- package/dist/auth.d.ts +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/done.d.ts +20 -8
- package/dist/done.d.ts.map +1 -1
- package/dist/{envelope.d.ts → envelope-builder.d.ts} +1 -4
- package/dist/envelope-builder.d.ts.map +1 -0
- package/dist/envelope-crypto.d.ts +6 -0
- package/dist/envelope-crypto.d.ts.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1219 -6
- package/package.json +6 -5
- package/dist/auth.js +0 -112
- package/dist/client.js +0 -140
- package/dist/done.js +0 -484
- package/dist/envelope.d.ts.map +0 -1
- package/dist/envelope.js +0 -113
- package/dist/messages.js +0 -46
- package/dist/types.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@donezone/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.55",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -13,15 +13,16 @@
|
|
|
13
13
|
"files": [
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
|
+
"sideEffects": false,
|
|
16
17
|
"scripts": {
|
|
17
|
-
"build": "tsc -p tsconfig.json",
|
|
18
|
+
"build": "esbuild ./src/index.ts --bundle --format=esm --platform=neutral --outfile=dist/index.js && tsc -p tsconfig.json --emitDeclarationOnly",
|
|
18
19
|
"test": "bun test"
|
|
19
20
|
},
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"@noble/hashes": "1.3.2"
|
|
22
|
-
},
|
|
21
|
+
"dependencies": {},
|
|
23
22
|
"devDependencies": {
|
|
23
|
+
"@noble/hashes": "1.3.2",
|
|
24
24
|
"@types/node": "^22.7.9",
|
|
25
|
+
"esbuild": "^0.21.5",
|
|
25
26
|
"typescript": "^5.8.3"
|
|
26
27
|
},
|
|
27
28
|
"publishConfig": {
|
package/dist/auth.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { buildEnvelope as buildEnvelopeHelper, encodeSignature, toSignDoc, } from "./envelope";
|
|
2
|
-
export function createPasskeyEnvelopeBuilder(options) {
|
|
3
|
-
return async (ctx) => {
|
|
4
|
-
const [userId, nonce, expiresAt, publicKey, agent, forwarder, metadata] = await Promise.all([
|
|
5
|
-
resolve(options.userId, ctx),
|
|
6
|
-
resolve(options.nonce, ctx),
|
|
7
|
-
resolve(options.expiresAt, ctx),
|
|
8
|
-
resolve(options.publicKey, ctx),
|
|
9
|
-
resolve(options.agent, ctx),
|
|
10
|
-
resolve(options.forwarder, ctx),
|
|
11
|
-
resolve(options.metadata, ctx),
|
|
12
|
-
]);
|
|
13
|
-
assertDefined(userId, "userId");
|
|
14
|
-
assertDefined(nonce, "nonce");
|
|
15
|
-
assertDefined(expiresAt, "expiresAt");
|
|
16
|
-
assertDefined(publicKey, "publicKey");
|
|
17
|
-
const mergedMetadata = combineMetadata(ctx.metadata, metadata);
|
|
18
|
-
const draft = {
|
|
19
|
-
user_id: userId,
|
|
20
|
-
msgs: [ctx.msg],
|
|
21
|
-
nonce: nonce,
|
|
22
|
-
expires_at: expiresAt,
|
|
23
|
-
role: options.role ?? "Passkey",
|
|
24
|
-
agent: agent ?? undefined,
|
|
25
|
-
forwarder: forwarder ?? undefined,
|
|
26
|
-
metadata: mergedMetadata,
|
|
27
|
-
signatures: {},
|
|
28
|
-
};
|
|
29
|
-
const signDoc = toSignDoc(draft);
|
|
30
|
-
const signature = await options.sign(signDoc, ctx);
|
|
31
|
-
draft.signatures = {
|
|
32
|
-
passkey: normalizeSignature(signature),
|
|
33
|
-
};
|
|
34
|
-
const envelope = buildEnvelopeHelper(draft);
|
|
35
|
-
envelope.metadata = envelope.metadata ?? mergedMetadata;
|
|
36
|
-
const passkeyOption = { publicKey: publicKey };
|
|
37
|
-
const executeOptions = { passkey: passkeyOption };
|
|
38
|
-
return makeResult(envelope, executeOptions);
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export function createSessionEnvelopeBuilder(options) {
|
|
42
|
-
return async (ctx) => {
|
|
43
|
-
const [userId, sessionId, nonce, expiresAt, agent, forwarder, metadata] = await Promise.all([
|
|
44
|
-
resolve(options.userId, ctx),
|
|
45
|
-
resolve(options.sessionId, ctx),
|
|
46
|
-
resolve(options.nonce, ctx),
|
|
47
|
-
resolve(options.expiresAt, ctx),
|
|
48
|
-
resolve(options.agent, ctx),
|
|
49
|
-
resolve(options.forwarder, ctx),
|
|
50
|
-
resolve(options.metadata, ctx),
|
|
51
|
-
]);
|
|
52
|
-
assertDefined(userId, "userId");
|
|
53
|
-
assertDefined(sessionId, "sessionId");
|
|
54
|
-
assertDefined(nonce, "nonce");
|
|
55
|
-
assertDefined(expiresAt, "expiresAt");
|
|
56
|
-
const mergedMetadata = combineMetadata(ctx.metadata, metadata);
|
|
57
|
-
const draft = {
|
|
58
|
-
user_id: userId,
|
|
59
|
-
session_id: sessionId,
|
|
60
|
-
msgs: [ctx.msg],
|
|
61
|
-
nonce: nonce,
|
|
62
|
-
expires_at: expiresAt,
|
|
63
|
-
role: options.role ?? "Session",
|
|
64
|
-
agent: agent ?? undefined,
|
|
65
|
-
forwarder: forwarder ?? undefined,
|
|
66
|
-
metadata: mergedMetadata,
|
|
67
|
-
signatures: {},
|
|
68
|
-
};
|
|
69
|
-
const signDoc = toSignDoc(draft);
|
|
70
|
-
const signature = await options.sign(signDoc, ctx);
|
|
71
|
-
draft.signatures = {
|
|
72
|
-
session: normalizeSignature(signature),
|
|
73
|
-
};
|
|
74
|
-
const envelope = buildEnvelopeHelper(draft);
|
|
75
|
-
envelope.metadata = envelope.metadata ?? mergedMetadata;
|
|
76
|
-
return makeResult(envelope, undefined);
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
function normalizeSignature(signature) {
|
|
80
|
-
if (typeof signature === "string") {
|
|
81
|
-
return signature;
|
|
82
|
-
}
|
|
83
|
-
return encodeSignature(signature);
|
|
84
|
-
}
|
|
85
|
-
function combineMetadata(base, override) {
|
|
86
|
-
const merged = {};
|
|
87
|
-
for (const entry of [base, override]) {
|
|
88
|
-
if (!entry)
|
|
89
|
-
continue;
|
|
90
|
-
if (entry.trace_id)
|
|
91
|
-
merged.trace_id = entry.trace_id;
|
|
92
|
-
if (entry.memo)
|
|
93
|
-
merged.memo = entry.memo;
|
|
94
|
-
if (typeof entry.gas_limit === "number")
|
|
95
|
-
merged.gas_limit = entry.gas_limit;
|
|
96
|
-
}
|
|
97
|
-
return Object.keys(merged).length > 0 ? merged : undefined;
|
|
98
|
-
}
|
|
99
|
-
function makeResult(envelope, options) {
|
|
100
|
-
return options ? { envelope, options } : { envelope };
|
|
101
|
-
}
|
|
102
|
-
function resolve(value, ctx) {
|
|
103
|
-
if (typeof value === "function") {
|
|
104
|
-
return Promise.resolve(value(ctx));
|
|
105
|
-
}
|
|
106
|
-
return Promise.resolve(value);
|
|
107
|
-
}
|
|
108
|
-
function assertDefined(value, name) {
|
|
109
|
-
if (value === undefined || value === null) {
|
|
110
|
-
throw new Error(`${name} must be provided for envelope builder`);
|
|
111
|
-
}
|
|
112
|
-
}
|
package/dist/client.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { buildEnvelope } from "./envelope";
|
|
2
|
-
import { buildQueryMessage, buildTransactionMessage } from "./messages";
|
|
3
|
-
export class DoneBackendClient {
|
|
4
|
-
baseUrl;
|
|
5
|
-
fetchImpl;
|
|
6
|
-
constructor(config) {
|
|
7
|
-
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
8
|
-
const candidate = config.fetch ?? fetch;
|
|
9
|
-
if (typeof candidate !== "function") {
|
|
10
|
-
throw new Error("fetch implementation is not available; configure Done with a fetch implementation via Done.config");
|
|
11
|
-
}
|
|
12
|
-
this.fetchImpl = candidate.bind(globalThis);
|
|
13
|
-
}
|
|
14
|
-
contract(address) {
|
|
15
|
-
return new DoneContractHandle(this, address);
|
|
16
|
-
}
|
|
17
|
-
buildEnvelope(draft) {
|
|
18
|
-
return buildEnvelope(draft);
|
|
19
|
-
}
|
|
20
|
-
async executeEnvelope(envelope, options = {}, init = {}) {
|
|
21
|
-
const body = {
|
|
22
|
-
envelope,
|
|
23
|
-
passkey: options.passkey,
|
|
24
|
-
memo: options.memo ?? envelope.metadata?.memo,
|
|
25
|
-
};
|
|
26
|
-
const { headers: initHeaders, signal: initSignal, method: initMethod, body: _ignoredBody, ...rest } = init;
|
|
27
|
-
const headers = new Headers(initHeaders ?? {});
|
|
28
|
-
headers.set("content-type", "application/json");
|
|
29
|
-
const res = await this.fetchImpl(`${this.baseUrl}/tx`, {
|
|
30
|
-
...rest,
|
|
31
|
-
method: initMethod ?? "POST",
|
|
32
|
-
headers,
|
|
33
|
-
body: JSON.stringify(body),
|
|
34
|
-
signal: initSignal ?? options.signal,
|
|
35
|
-
});
|
|
36
|
-
if (!res.ok) {
|
|
37
|
-
const text = await res.text().catch(() => "");
|
|
38
|
-
throw new Error(`tx failed with ${res.status}: ${text}`);
|
|
39
|
-
}
|
|
40
|
-
return res.json();
|
|
41
|
-
}
|
|
42
|
-
async publishCode(request, init = {}) {
|
|
43
|
-
const { contract, script, msg } = request;
|
|
44
|
-
const { headers: initHeaders, method: initMethod, body: _ignoredBody, ...rest } = init;
|
|
45
|
-
const headers = new Headers(initHeaders ?? {});
|
|
46
|
-
headers.set("content-type", "application/json");
|
|
47
|
-
const payload = { script };
|
|
48
|
-
if (Object.prototype.hasOwnProperty.call(request, "msg")) {
|
|
49
|
-
payload.msg = msg;
|
|
50
|
-
}
|
|
51
|
-
const res = await this.fetchImpl(`${this.baseUrl}/contracts/${contract}/publish`, {
|
|
52
|
-
...rest,
|
|
53
|
-
method: initMethod ?? "POST",
|
|
54
|
-
headers,
|
|
55
|
-
body: JSON.stringify(payload),
|
|
56
|
-
});
|
|
57
|
-
if (!res.ok) {
|
|
58
|
-
const text = await res.text().catch(() => "");
|
|
59
|
-
throw new Error(`publish failed with ${res.status}: ${text}`);
|
|
60
|
-
}
|
|
61
|
-
return res.json();
|
|
62
|
-
}
|
|
63
|
-
async queryContractRaw(address, call, init = {}) {
|
|
64
|
-
const message = buildQueryMessage(call);
|
|
65
|
-
const params = new URLSearchParams();
|
|
66
|
-
params.set("msg", JSON.stringify(message));
|
|
67
|
-
const { method: initMethod, ...rest } = init;
|
|
68
|
-
return this.fetchImpl(`${this.baseUrl}/query/${address}?${params}`, {
|
|
69
|
-
method: initMethod ?? "GET",
|
|
70
|
-
...rest,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
async queryContract(address, call, init = {}) {
|
|
74
|
-
const res = await this.queryContractRaw(address, call, init);
|
|
75
|
-
if (!res.ok) {
|
|
76
|
-
const text = await res.text().catch(() => "");
|
|
77
|
-
throw new Error(`query failed with ${res.status}: ${text}`);
|
|
78
|
-
}
|
|
79
|
-
return res.json();
|
|
80
|
-
}
|
|
81
|
-
async getAgentQuota(userId, agent) {
|
|
82
|
-
const res = await this.fetchImpl(`${this.baseUrl}/quota/agent/${userId}/${agent}`);
|
|
83
|
-
if (!res.ok) {
|
|
84
|
-
const text = await res.text().catch(() => "");
|
|
85
|
-
throw new Error(`agent quota failed with ${res.status}: ${text}`);
|
|
86
|
-
}
|
|
87
|
-
return res.json();
|
|
88
|
-
}
|
|
89
|
-
async getForwarderQuota(address) {
|
|
90
|
-
const res = await this.fetchImpl(`${this.baseUrl}/quota/forwarder/${address}`);
|
|
91
|
-
if (!res.ok) {
|
|
92
|
-
const text = await res.text().catch(() => "");
|
|
93
|
-
throw new Error(`forwarder quota failed with ${res.status}: ${text}`);
|
|
94
|
-
}
|
|
95
|
-
return res.json();
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
class DoneContractHandle {
|
|
99
|
-
backend;
|
|
100
|
-
address;
|
|
101
|
-
constructor(backend, address) {
|
|
102
|
-
this.backend = backend;
|
|
103
|
-
this.address = address;
|
|
104
|
-
}
|
|
105
|
-
transaction(path, options = {}) {
|
|
106
|
-
const call = {
|
|
107
|
-
path,
|
|
108
|
-
query: options.query,
|
|
109
|
-
body: options.body,
|
|
110
|
-
};
|
|
111
|
-
const msg = buildTransactionMessage(this.address, call, options);
|
|
112
|
-
const metadata = metadataFromOptions(options);
|
|
113
|
-
return { msg, metadata };
|
|
114
|
-
}
|
|
115
|
-
async query(path, options = {}) {
|
|
116
|
-
const call = {
|
|
117
|
-
path,
|
|
118
|
-
query: options.query,
|
|
119
|
-
body: options.body,
|
|
120
|
-
};
|
|
121
|
-
return this.backend.queryContract(this.address, call);
|
|
122
|
-
}
|
|
123
|
-
publishCode(request, init = {}) {
|
|
124
|
-
return this.backend.publishCode({
|
|
125
|
-
contract: this.address,
|
|
126
|
-
script: request.script,
|
|
127
|
-
msg: request.msg,
|
|
128
|
-
}, init);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
function metadataFromOptions(options) {
|
|
132
|
-
const metadata = {};
|
|
133
|
-
if (options.traceId)
|
|
134
|
-
metadata.trace_id = options.traceId;
|
|
135
|
-
if (options.memo)
|
|
136
|
-
metadata.memo = options.memo;
|
|
137
|
-
if (typeof options.gasLimit === "number")
|
|
138
|
-
metadata.gas_limit = options.gasLimit;
|
|
139
|
-
return Object.keys(metadata).length > 0 ? metadata : undefined;
|
|
140
|
-
}
|