@ottochain/sdk 1.2.0 → 1.3.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/LICENSE +190 -0
- package/dist/cjs/index.js +34 -15
- package/dist/cjs/ottochain/index.js +20 -1
- package/dist/cjs/ottochain/metagraph-client.js +7 -8
- package/dist/cjs/ottochain/snapshot.js +3 -3
- package/dist/cjs/{metakit → ottochain}/transaction.js +4 -5
- package/dist/cjs/verify.js +17 -0
- package/dist/esm/apps/contracts/index.js +28 -10
- package/dist/esm/apps/corporate/index.js +79 -24
- package/dist/esm/apps/governance/index.js +85 -36
- package/dist/esm/apps/identity/constants.js +27 -22
- package/dist/esm/apps/identity/index.js +35 -7
- package/dist/esm/apps/index.js +32 -6
- package/dist/esm/apps/markets/index.js +27 -6
- package/dist/esm/apps/oracles/index.js +27 -7
- package/dist/esm/errors.js +19 -9
- package/dist/esm/generated/google/protobuf/struct.js +39 -33
- package/dist/esm/generated/google/protobuf/timestamp.js +9 -6
- package/dist/esm/generated/index.js +134 -10
- package/dist/esm/generated/ottochain/apps/contracts/v1/contract.js +54 -48
- package/dist/esm/generated/ottochain/apps/corporate/v1/corporate.js +357 -335
- package/dist/esm/generated/ottochain/apps/governance/v1/governance.js +299 -284
- package/dist/esm/generated/ottochain/apps/identity/v1/agent.js +47 -38
- package/dist/esm/generated/ottochain/apps/identity/v1/attestation.js +50 -44
- package/dist/esm/generated/ottochain/apps/markets/v1/market.js +86 -77
- package/dist/esm/generated/ottochain/apps/oracles/v1/oracle.js +72 -66
- package/dist/esm/generated/ottochain/v1/common.js +4 -1
- package/dist/esm/generated/ottochain/v1/fiber.js +96 -90
- package/dist/esm/generated/ottochain/v1/messages.js +82 -79
- package/dist/esm/generated/ottochain/v1/records.js +140 -137
- package/dist/esm/index.js +86 -20
- package/dist/esm/{metakit → ottochain}/drop-nulls.js +5 -1
- package/dist/esm/ottochain/index.js +56 -3
- package/dist/esm/ottochain/metagraph-client.js +16 -13
- package/dist/esm/{metakit → ottochain}/normalize.js +11 -4
- package/dist/esm/ottochain/snapshot.js +20 -10
- package/dist/esm/{metakit → ottochain}/transaction.js +25 -14
- package/dist/esm/ottochain/types.js +2 -1
- package/dist/esm/types.js +7 -2
- package/dist/esm/validation.js +76 -65
- package/dist/esm/verify.js +17 -0
- package/dist/types/index.d.ts +14 -7
- package/dist/types/ottochain/index.d.ts +4 -0
- package/dist/types/ottochain/metagraph-client.d.ts +1 -1
- package/dist/types/{metakit → ottochain}/transaction.d.ts +1 -1
- package/dist/types/validation.d.ts +8 -8
- package/dist/types/verify.d.ts +9 -0
- package/package.json +5 -3
- package/dist/cjs/metakit/binary.js +0 -58
- package/dist/cjs/metakit/canonicalize.js +0 -40
- package/dist/cjs/metakit/codec.js +0 -45
- package/dist/cjs/metakit/currency-transaction.js +0 -319
- package/dist/cjs/metakit/currency-types.js +0 -13
- package/dist/cjs/metakit/hash.js +0 -84
- package/dist/cjs/metakit/index.js +0 -86
- package/dist/cjs/metakit/network/client.js +0 -78
- package/dist/cjs/metakit/network/currency-l1-client.js +0 -101
- package/dist/cjs/metakit/network/data-l1-client.js +0 -76
- package/dist/cjs/metakit/network/index.js +0 -16
- package/dist/cjs/metakit/network/types.js +0 -20
- package/dist/cjs/metakit/sign.js +0 -120
- package/dist/cjs/metakit/signed-object.js +0 -100
- package/dist/cjs/metakit/types.js +0 -14
- package/dist/cjs/metakit/verify.js +0 -217
- package/dist/cjs/metakit/wallet.js +0 -127
- package/dist/esm/metakit/binary.js +0 -53
- package/dist/esm/metakit/canonicalize.js +0 -33
- package/dist/esm/metakit/codec.js +0 -38
- package/dist/esm/metakit/currency-transaction.js +0 -306
- package/dist/esm/metakit/currency-types.js +0 -10
- package/dist/esm/metakit/hash.js +0 -77
- package/dist/esm/metakit/index.js +0 -33
- package/dist/esm/metakit/network/client.js +0 -74
- package/dist/esm/metakit/network/currency-l1-client.js +0 -97
- package/dist/esm/metakit/network/data-l1-client.js +0 -72
- package/dist/esm/metakit/network/index.js +0 -9
- package/dist/esm/metakit/network/types.js +0 -16
- package/dist/esm/metakit/sign.js +0 -114
- package/dist/esm/metakit/signed-object.js +0 -94
- package/dist/esm/metakit/types.js +0 -11
- package/dist/esm/metakit/verify.js +0 -210
- package/dist/esm/metakit/wallet.js +0 -117
- package/dist/types/metakit/binary.d.ts +0 -38
- package/dist/types/metakit/canonicalize.d.ts +0 -26
- package/dist/types/metakit/codec.d.ts +0 -16
- package/dist/types/metakit/currency-transaction.d.ts +0 -157
- package/dist/types/metakit/currency-types.d.ts +0 -55
- package/dist/types/metakit/hash.d.ts +0 -50
- package/dist/types/metakit/index.d.ts +0 -26
- package/dist/types/metakit/network/client.d.ts +0 -23
- package/dist/types/metakit/network/currency-l1-client.d.ts +0 -71
- package/dist/types/metakit/network/data-l1-client.d.ts +0 -57
- package/dist/types/metakit/network/index.d.ts +0 -10
- package/dist/types/metakit/network/types.d.ts +0 -74
- package/dist/types/metakit/sign.d.ts +0 -65
- package/dist/types/metakit/signed-object.d.ts +0 -66
- package/dist/types/metakit/types.d.ts +0 -67
- package/dist/types/metakit/verify.d.ts +0 -55
- package/dist/types/metakit/wallet.d.ts +0 -70
- /package/dist/cjs/{metakit → ottochain}/drop-nulls.js +0 -0
- /package/dist/cjs/{metakit → ottochain}/normalize.js +0 -0
- /package/dist/types/{metakit → ottochain}/drop-nulls.d.ts +0 -0
- /package/dist/types/{metakit → ottochain}/normalize.d.ts +0 -0
package/dist/esm/types.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* OttoChain Type Aliases
|
|
3
4
|
*
|
|
@@ -6,15 +7,19 @@
|
|
|
6
7
|
*
|
|
7
8
|
* @packageDocumentation
|
|
8
9
|
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.isValidFiberId = exports.isValidAddress = void 0;
|
|
9
12
|
/**
|
|
10
13
|
* Validate a DAG address format.
|
|
11
14
|
*/
|
|
12
|
-
|
|
15
|
+
function isValidAddress(value) {
|
|
13
16
|
return /^DAG[0-9a-zA-Z]+$/.test(value);
|
|
14
17
|
}
|
|
18
|
+
exports.isValidAddress = isValidAddress;
|
|
15
19
|
/**
|
|
16
20
|
* Validate a UUID format.
|
|
17
21
|
*/
|
|
18
|
-
|
|
22
|
+
function isValidFiberId(value) {
|
|
19
23
|
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
|
20
24
|
}
|
|
25
|
+
exports.isValidFiberId = isValidFiberId;
|
package/dist/esm/validation.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Input Validation with Zod Schemas
|
|
3
4
|
*
|
|
@@ -5,8 +6,10 @@
|
|
|
5
6
|
*
|
|
6
7
|
* @packageDocumentation
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.assert = exports.safeParse = exports.validateKeyPair = exports.validateAddress = exports.validatePublicKey = exports.validatePrivateKey = exports.validate = exports.CompleteContractRequestSchema = exports.AcceptContractRequestSchema = exports.ProposeContractRequestSchema = exports.ContractTermsSchema = exports.PlatformLinkSchema = exports.AgentIdentityRegistrationSchema = exports.TransferParamsSchema = exports.CurrencyTransactionSchema = exports.CurrencyTransactionValueSchema = exports.TransactionReferenceSchema = exports.SignedSchema = exports.SignatureProofSchema = exports.KeyPairSchema = exports.PublicKeySchema = exports.PrivateKeySchema = exports.DagAddressSchema = void 0;
|
|
11
|
+
const zod_1 = require("zod");
|
|
12
|
+
const errors_js_1 = require("./errors.js");
|
|
10
13
|
// ============================================================================
|
|
11
14
|
// Primitive Schemas
|
|
12
15
|
// ============================================================================
|
|
@@ -14,7 +17,7 @@ import { ValidationError } from './errors.js';
|
|
|
14
17
|
* Schema for a hex string of specific length
|
|
15
18
|
*/
|
|
16
19
|
const hexString = (length) => {
|
|
17
|
-
let schema = z.string().regex(/^[0-9a-fA-F]+$/, 'Must be a valid hex string');
|
|
20
|
+
let schema = zod_1.z.string().regex(/^[0-9a-fA-F]+$/, 'Must be a valid hex string');
|
|
18
21
|
if (length !== undefined) {
|
|
19
22
|
schema = schema.length(length, `Must be exactly ${length} characters`);
|
|
20
23
|
}
|
|
@@ -23,7 +26,7 @@ const hexString = (length) => {
|
|
|
23
26
|
/**
|
|
24
27
|
* Schema for a DAG address
|
|
25
28
|
*/
|
|
26
|
-
|
|
29
|
+
exports.DagAddressSchema = zod_1.z
|
|
27
30
|
.string()
|
|
28
31
|
.regex(/^DAG[0-9][a-zA-Z0-9]{36}$/, 'Must be a valid DAG address');
|
|
29
32
|
// ============================================================================
|
|
@@ -32,29 +35,29 @@ export const DagAddressSchema = z
|
|
|
32
35
|
/**
|
|
33
36
|
* Schema for a private key (64-character hex string)
|
|
34
37
|
*/
|
|
35
|
-
|
|
38
|
+
exports.PrivateKeySchema = hexString(64).describe('Private key in hex format (64 characters)');
|
|
36
39
|
/**
|
|
37
40
|
* Schema for a public key (128 or 130 character hex string)
|
|
38
41
|
*/
|
|
39
|
-
|
|
42
|
+
exports.PublicKeySchema = zod_1.z
|
|
40
43
|
.string()
|
|
41
44
|
.regex(/^(04)?[0-9a-fA-F]{128}$/, 'Must be a valid public key (128 or 130 hex chars)')
|
|
42
45
|
.describe('Public key in hex format (with optional 04 prefix)');
|
|
43
46
|
/**
|
|
44
47
|
* Schema for a KeyPair
|
|
45
48
|
*/
|
|
46
|
-
|
|
49
|
+
exports.KeyPairSchema = zod_1.z.object({
|
|
47
50
|
/** Private key in hex format */
|
|
48
|
-
privateKey: PrivateKeySchema,
|
|
51
|
+
privateKey: exports.PrivateKeySchema,
|
|
49
52
|
/** Public key in hex format (uncompressed, with 04 prefix) */
|
|
50
|
-
publicKey: PublicKeySchema,
|
|
53
|
+
publicKey: exports.PublicKeySchema,
|
|
51
54
|
/** DAG address derived from the public key */
|
|
52
|
-
address: DagAddressSchema,
|
|
55
|
+
address: exports.DagAddressSchema,
|
|
53
56
|
});
|
|
54
57
|
/**
|
|
55
58
|
* Schema for a SignatureProof
|
|
56
59
|
*/
|
|
57
|
-
|
|
60
|
+
exports.SignatureProofSchema = zod_1.z.object({
|
|
58
61
|
/** Public key hex (uncompressed, without 04 prefix) - 128 characters */
|
|
59
62
|
id: hexString(128),
|
|
60
63
|
/** DER-encoded ECDSA signature in hex format */
|
|
@@ -63,44 +66,45 @@ export const SignatureProofSchema = z.object({
|
|
|
63
66
|
/**
|
|
64
67
|
* Schema for a Signed object (generic)
|
|
65
68
|
*/
|
|
66
|
-
|
|
69
|
+
const SignedSchema = (valueSchema) => zod_1.z.object({
|
|
67
70
|
value: valueSchema,
|
|
68
|
-
proofs: z.array(SignatureProofSchema).min(1, 'At least one proof is required'),
|
|
71
|
+
proofs: zod_1.z.array(exports.SignatureProofSchema).min(1, 'At least one proof is required'),
|
|
69
72
|
});
|
|
73
|
+
exports.SignedSchema = SignedSchema;
|
|
70
74
|
// ============================================================================
|
|
71
75
|
// Transaction Schemas
|
|
72
76
|
// ============================================================================
|
|
73
77
|
/**
|
|
74
78
|
* Schema for TransactionReference
|
|
75
79
|
*/
|
|
76
|
-
|
|
77
|
-
ordinal: z.number().int().min(0),
|
|
78
|
-
hash: z.string().min(1),
|
|
80
|
+
exports.TransactionReferenceSchema = zod_1.z.object({
|
|
81
|
+
ordinal: zod_1.z.number().int().min(0),
|
|
82
|
+
hash: zod_1.z.string().min(1),
|
|
79
83
|
});
|
|
80
84
|
/**
|
|
81
85
|
* Schema for CurrencyTransactionValue
|
|
82
86
|
*/
|
|
83
|
-
|
|
84
|
-
source: DagAddressSchema,
|
|
85
|
-
destination: DagAddressSchema,
|
|
86
|
-
amount: z.number().int().positive('Amount must be positive'),
|
|
87
|
-
fee: z.number().int().min(0).default(0),
|
|
87
|
+
exports.CurrencyTransactionValueSchema = zod_1.z.object({
|
|
88
|
+
source: exports.DagAddressSchema,
|
|
89
|
+
destination: exports.DagAddressSchema,
|
|
90
|
+
amount: zod_1.z.number().int().positive('Amount must be positive'),
|
|
91
|
+
fee: zod_1.z.number().int().min(0).default(0),
|
|
88
92
|
});
|
|
89
93
|
/**
|
|
90
94
|
* Schema for CurrencyTransaction
|
|
91
95
|
*/
|
|
92
|
-
|
|
93
|
-
value: CurrencyTransactionValueSchema,
|
|
94
|
-
parent: TransactionReferenceSchema,
|
|
96
|
+
exports.CurrencyTransactionSchema = zod_1.z.object({
|
|
97
|
+
value: exports.CurrencyTransactionValueSchema,
|
|
98
|
+
parent: exports.TransactionReferenceSchema,
|
|
95
99
|
});
|
|
96
100
|
/**
|
|
97
101
|
* Schema for TransferParams
|
|
98
102
|
*/
|
|
99
|
-
|
|
100
|
-
from: DagAddressSchema,
|
|
101
|
-
to: DagAddressSchema,
|
|
102
|
-
amount: z.number().positive('Amount must be positive'),
|
|
103
|
-
fee: z.number().min(0).optional().default(0),
|
|
103
|
+
exports.TransferParamsSchema = zod_1.z.object({
|
|
104
|
+
from: exports.DagAddressSchema,
|
|
105
|
+
to: exports.DagAddressSchema,
|
|
106
|
+
amount: zod_1.z.number().positive('Amount must be positive'),
|
|
107
|
+
fee: zod_1.z.number().min(0).optional().default(0),
|
|
104
108
|
});
|
|
105
109
|
// ============================================================================
|
|
106
110
|
// Identity Schemas
|
|
@@ -108,22 +112,22 @@ export const TransferParamsSchema = z.object({
|
|
|
108
112
|
/**
|
|
109
113
|
* Schema for AgentIdentity registration
|
|
110
114
|
*/
|
|
111
|
-
|
|
115
|
+
exports.AgentIdentityRegistrationSchema = zod_1.z.object({
|
|
112
116
|
/** Public key in hex format */
|
|
113
|
-
publicKey: PublicKeySchema,
|
|
117
|
+
publicKey: exports.PublicKeySchema,
|
|
114
118
|
/** Display name for the agent */
|
|
115
|
-
displayName: z.string().min(1).max(64),
|
|
119
|
+
displayName: zod_1.z.string().min(1).max(64),
|
|
116
120
|
/** Initial reputation (default: 10) */
|
|
117
|
-
reputation: z.number().int().min(0).optional().default(10),
|
|
121
|
+
reputation: zod_1.z.number().int().min(0).optional().default(10),
|
|
118
122
|
});
|
|
119
123
|
/**
|
|
120
124
|
* Schema for PlatformLink
|
|
121
125
|
*/
|
|
122
|
-
|
|
123
|
-
platform: z.enum(['DISCORD', 'TELEGRAM', 'TWITTER', 'GITHUB', 'CUSTOM']),
|
|
124
|
-
platformUserId: z.string().min(1),
|
|
125
|
-
platformUsername: z.string().min(1),
|
|
126
|
-
verified: z.boolean().optional().default(false),
|
|
126
|
+
exports.PlatformLinkSchema = zod_1.z.object({
|
|
127
|
+
platform: zod_1.z.enum(['DISCORD', 'TELEGRAM', 'TWITTER', 'GITHUB', 'CUSTOM']),
|
|
128
|
+
platformUserId: zod_1.z.string().min(1),
|
|
129
|
+
platformUsername: zod_1.z.string().min(1),
|
|
130
|
+
verified: zod_1.z.boolean().optional().default(false),
|
|
127
131
|
});
|
|
128
132
|
// ============================================================================
|
|
129
133
|
// Contract Schemas
|
|
@@ -131,39 +135,39 @@ export const PlatformLinkSchema = z.object({
|
|
|
131
135
|
/**
|
|
132
136
|
* Schema for contract terms (flexible structure)
|
|
133
137
|
*/
|
|
134
|
-
|
|
138
|
+
exports.ContractTermsSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.unknown());
|
|
135
139
|
/**
|
|
136
140
|
* Schema for ProposeContractRequest
|
|
137
141
|
*/
|
|
138
|
-
|
|
142
|
+
exports.ProposeContractRequestSchema = zod_1.z.object({
|
|
139
143
|
/** Proposer's DAG address */
|
|
140
|
-
proposer: DagAddressSchema,
|
|
144
|
+
proposer: exports.DagAddressSchema,
|
|
141
145
|
/** Counterparty's DAG address */
|
|
142
|
-
counterparty: DagAddressSchema,
|
|
146
|
+
counterparty: exports.DagAddressSchema,
|
|
143
147
|
/** Contract terms */
|
|
144
|
-
terms: ContractTermsSchema,
|
|
148
|
+
terms: exports.ContractTermsSchema,
|
|
145
149
|
/** Human-readable description */
|
|
146
|
-
description: z.string().min(1).max(1000),
|
|
150
|
+
description: zod_1.z.string().min(1).max(1000),
|
|
147
151
|
});
|
|
148
152
|
/**
|
|
149
153
|
* Schema for AcceptContractRequest
|
|
150
154
|
*/
|
|
151
|
-
|
|
155
|
+
exports.AcceptContractRequestSchema = zod_1.z.object({
|
|
152
156
|
/** Contract ID to accept */
|
|
153
|
-
contractId: z.string().min(1),
|
|
157
|
+
contractId: zod_1.z.string().min(1),
|
|
154
158
|
/** Acceptor's DAG address */
|
|
155
|
-
acceptor: DagAddressSchema,
|
|
159
|
+
acceptor: exports.DagAddressSchema,
|
|
156
160
|
});
|
|
157
161
|
/**
|
|
158
162
|
* Schema for CompleteContractRequest
|
|
159
163
|
*/
|
|
160
|
-
|
|
164
|
+
exports.CompleteContractRequestSchema = zod_1.z.object({
|
|
161
165
|
/** Contract ID to complete */
|
|
162
|
-
contractId: z.string().min(1),
|
|
166
|
+
contractId: zod_1.z.string().min(1),
|
|
163
167
|
/** Completer's DAG address */
|
|
164
|
-
completer: DagAddressSchema,
|
|
168
|
+
completer: exports.DagAddressSchema,
|
|
165
169
|
/** Proof of completion */
|
|
166
|
-
proof: z.string().min(1),
|
|
170
|
+
proof: zod_1.z.string().min(1),
|
|
167
171
|
});
|
|
168
172
|
// ============================================================================
|
|
169
173
|
// Validation Helpers
|
|
@@ -183,7 +187,7 @@ export const CompleteContractRequestSchema = z.object({
|
|
|
183
187
|
* // keyPair is now typed as ValidatedKeyPair
|
|
184
188
|
* ```
|
|
185
189
|
*/
|
|
186
|
-
|
|
190
|
+
function validate(schema, data, fieldName) {
|
|
187
191
|
const result = schema.safeParse(data);
|
|
188
192
|
if (!result.success) {
|
|
189
193
|
const issues = result.error.issues;
|
|
@@ -191,7 +195,7 @@ export function validate(schema, data, fieldName) {
|
|
|
191
195
|
// Build a helpful error message
|
|
192
196
|
const path = firstIssue.path.length > 0 ? firstIssue.path.join('.') : fieldName || 'input';
|
|
193
197
|
const message = `Validation failed for '${path}': ${firstIssue.message}`;
|
|
194
|
-
throw new ValidationError(message, {
|
|
198
|
+
throw new errors_js_1.ValidationError(message, {
|
|
195
199
|
field: path,
|
|
196
200
|
value: data,
|
|
197
201
|
details: {
|
|
@@ -205,6 +209,7 @@ export function validate(schema, data, fieldName) {
|
|
|
205
209
|
}
|
|
206
210
|
return result.data;
|
|
207
211
|
}
|
|
212
|
+
exports.validate = validate;
|
|
208
213
|
/**
|
|
209
214
|
* Validate a private key
|
|
210
215
|
*
|
|
@@ -212,9 +217,10 @@ export function validate(schema, data, fieldName) {
|
|
|
212
217
|
* @returns Validated private key
|
|
213
218
|
* @throws {ValidationError} If validation fails
|
|
214
219
|
*/
|
|
215
|
-
|
|
216
|
-
return validate(PrivateKeySchema, privateKey, 'privateKey');
|
|
220
|
+
function validatePrivateKey(privateKey) {
|
|
221
|
+
return validate(exports.PrivateKeySchema, privateKey, 'privateKey');
|
|
217
222
|
}
|
|
223
|
+
exports.validatePrivateKey = validatePrivateKey;
|
|
218
224
|
/**
|
|
219
225
|
* Validate a public key
|
|
220
226
|
*
|
|
@@ -222,9 +228,10 @@ export function validatePrivateKey(privateKey) {
|
|
|
222
228
|
* @returns Validated public key
|
|
223
229
|
* @throws {ValidationError} If validation fails
|
|
224
230
|
*/
|
|
225
|
-
|
|
226
|
-
return validate(PublicKeySchema, publicKey, 'publicKey');
|
|
231
|
+
function validatePublicKey(publicKey) {
|
|
232
|
+
return validate(exports.PublicKeySchema, publicKey, 'publicKey');
|
|
227
233
|
}
|
|
234
|
+
exports.validatePublicKey = validatePublicKey;
|
|
228
235
|
/**
|
|
229
236
|
* Validate a DAG address
|
|
230
237
|
*
|
|
@@ -232,9 +239,10 @@ export function validatePublicKey(publicKey) {
|
|
|
232
239
|
* @returns Validated address
|
|
233
240
|
* @throws {ValidationError} If validation fails
|
|
234
241
|
*/
|
|
235
|
-
|
|
236
|
-
return validate(DagAddressSchema, address, 'address');
|
|
242
|
+
function validateAddress(address) {
|
|
243
|
+
return validate(exports.DagAddressSchema, address, 'address');
|
|
237
244
|
}
|
|
245
|
+
exports.validateAddress = validateAddress;
|
|
238
246
|
/**
|
|
239
247
|
* Validate a KeyPair
|
|
240
248
|
*
|
|
@@ -242,9 +250,10 @@ export function validateAddress(address) {
|
|
|
242
250
|
* @returns Validated KeyPair
|
|
243
251
|
* @throws {ValidationError} If validation fails
|
|
244
252
|
*/
|
|
245
|
-
|
|
246
|
-
return validate(KeyPairSchema, keyPair, 'keyPair');
|
|
253
|
+
function validateKeyPair(keyPair) {
|
|
254
|
+
return validate(exports.KeyPairSchema, keyPair, 'keyPair');
|
|
247
255
|
}
|
|
256
|
+
exports.validateKeyPair = validateKeyPair;
|
|
248
257
|
/**
|
|
249
258
|
* Safe validation that returns a result object instead of throwing
|
|
250
259
|
*
|
|
@@ -262,7 +271,7 @@ export function validateKeyPair(keyPair) {
|
|
|
262
271
|
* }
|
|
263
272
|
* ```
|
|
264
273
|
*/
|
|
265
|
-
|
|
274
|
+
function safeParse(schema, data) {
|
|
266
275
|
const result = schema.safeParse(data);
|
|
267
276
|
if (result.success) {
|
|
268
277
|
return { success: true, data: result.data };
|
|
@@ -273,7 +282,7 @@ export function safeParse(schema, data) {
|
|
|
273
282
|
const message = `Validation failed for '${path}': ${firstIssue.message}`;
|
|
274
283
|
return {
|
|
275
284
|
success: false,
|
|
276
|
-
error: new ValidationError(message, {
|
|
285
|
+
error: new errors_js_1.ValidationError(message, {
|
|
277
286
|
field: path,
|
|
278
287
|
value: data,
|
|
279
288
|
details: {
|
|
@@ -286,6 +295,7 @@ export function safeParse(schema, data) {
|
|
|
286
295
|
}),
|
|
287
296
|
};
|
|
288
297
|
}
|
|
298
|
+
exports.safeParse = safeParse;
|
|
289
299
|
/**
|
|
290
300
|
* Assert that a condition is true, throwing ValidationError if not
|
|
291
301
|
*
|
|
@@ -294,8 +304,9 @@ export function safeParse(schema, data) {
|
|
|
294
304
|
* @param field - Optional field name for context
|
|
295
305
|
* @throws {ValidationError} If condition is false
|
|
296
306
|
*/
|
|
297
|
-
|
|
307
|
+
function assert(condition, message, field) {
|
|
298
308
|
if (!condition) {
|
|
299
|
-
throw new ValidationError(message, { field });
|
|
309
|
+
throw new errors_js_1.ValidationError(message, { field });
|
|
300
310
|
}
|
|
301
311
|
}
|
|
312
|
+
exports.assert = assert;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Backward-compatible verify wrapper.
|
|
4
|
+
*
|
|
5
|
+
* The package embeds `mode: "standard"|"dataUpdate"` in signed objects and
|
|
6
|
+
* its verify() ignores the `isDataUpdate` parameter when `mode` is present.
|
|
7
|
+
* This wrapper strips `mode` so callers' explicit `isDataUpdate` always wins.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.verify = void 0;
|
|
11
|
+
const metagraph_sdk_1 = require("@constellation-network/metagraph-sdk");
|
|
12
|
+
function verify(signed, isDataUpdate) {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
14
|
+
const { mode, ...rest } = signed;
|
|
15
|
+
return (0, metagraph_sdk_1.verify)(rest, isDataUpdate);
|
|
16
|
+
}
|
|
17
|
+
exports.verify = verify;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Ottochain SDK
|
|
3
3
|
*
|
|
4
|
-
* Unified SDK combining
|
|
4
|
+
* Unified SDK combining @constellation-network/metagraph-sdk with OttoChain domain types.
|
|
5
5
|
*
|
|
6
6
|
* Structure:
|
|
7
|
-
* - `
|
|
7
|
+
* - `@constellation-network/metagraph-sdk` — Core signing, hashing, encoding, wallet, currency transactions
|
|
8
|
+
* - `@constellation-network/metagraph-sdk/network` — HttpClient, MetagraphClient, NetworkError
|
|
9
|
+
* - `ottochain` — OttoChain-specific transaction helpers, types, snapshot, and client
|
|
8
10
|
* - `generated` — Protobuf-generated types (source of truth)
|
|
9
11
|
* - `apps/identity` — Agent Identity application types
|
|
10
12
|
* - `apps/contracts` — Contract application types
|
|
@@ -13,12 +15,17 @@
|
|
|
13
15
|
*
|
|
14
16
|
* @packageDocumentation
|
|
15
17
|
*/
|
|
18
|
+
export * from '@constellation-network/metagraph-sdk';
|
|
19
|
+
export { verify } from './verify.js';
|
|
20
|
+
export { MetagraphClient, createMetagraphClient, HttpClient, NetworkError as MetagraphNetworkError, } from '@constellation-network/metagraph-sdk/network';
|
|
21
|
+
export type { MetagraphClientConfig as BaseMetagraphClientConfig, LayerType, ClusterInfo, } from '@constellation-network/metagraph-sdk/network';
|
|
22
|
+
export type { RequestOptions, TransactionStatus, PendingTransaction, PostTransactionResponse, EstimateFeeResponse, PostDataResponse, } from '@constellation-network/metagraph-sdk/network';
|
|
16
23
|
export * from './types.js';
|
|
17
|
-
export * from './
|
|
24
|
+
export * from './ottochain/transaction.js';
|
|
25
|
+
export { normalizeCreateStateMachine, normalizeTransitionStateMachine, normalizeArchiveStateMachine, normalizeMessage } from './ottochain/normalize.js';
|
|
26
|
+
export { dropNulls } from './ottochain/drop-nulls.js';
|
|
18
27
|
export * from './generated/index.js';
|
|
19
28
|
export { OttoChainError, NetworkError, ValidationError, SigningError, TransactionError, ErrorCode, isErrorCode, wrapError, } from './errors.js';
|
|
20
29
|
export { DagAddressSchema, PrivateKeySchema, PublicKeySchema, KeyPairSchema, SignatureProofSchema, SignedSchema, TransactionReferenceSchema, CurrencyTransactionValueSchema, CurrencyTransactionSchema, TransferParamsSchema, AgentIdentityRegistrationSchema, PlatformLinkSchema, ContractTermsSchema, ProposeContractRequestSchema, AcceptContractRequestSchema, CompleteContractRequestSchema, validate, validatePrivateKey, validatePublicKey, validateAddress, validateKeyPair, safeParse, assert, type ValidatedKeyPair, type ValidatedSignatureProof, type ValidatedCurrencyTransaction, type ValidatedTransferParams, type ValidatedAgentIdentityRegistration, type ValidatedPlatformLink, type ValidatedProposeContractRequest, type ValidatedAcceptContractRequest, type ValidatedCompleteContractRequest, } from './validation.js';
|
|
21
|
-
export
|
|
22
|
-
export
|
|
23
|
-
export { MetagraphClient } from './ottochain/metagraph-client.js';
|
|
24
|
-
export type { MetagraphClientConfig, Checkpoint, SubscribeOptions, FiberStateCallback, Unsubscribe } from './ottochain/metagraph-client.js';
|
|
30
|
+
export { MetagraphClient as OttoMetagraphClient } from './ottochain/metagraph-client.js';
|
|
31
|
+
export type { MetagraphClientConfig, Checkpoint, SubscribeOptions, FiberStateCallback, Unsubscribe, } from './ottochain/metagraph-client.js';
|
|
@@ -11,3 +11,7 @@ export type { CurrencySnapshotResponse } from './snapshot.js';
|
|
|
11
11
|
export { decodeOnChainState, getSnapshotOnChainState, getLatestOnChainState, getLogsForFiber, getEventReceipts, getScriptInvocations, extractOnChainState, } from './snapshot.js';
|
|
12
12
|
export type { Checkpoint, MetagraphClientConfig, SubscribeOptions, FiberStateCallback, Unsubscribe, } from './metagraph-client.js';
|
|
13
13
|
export { MetagraphClient } from './metagraph-client.js';
|
|
14
|
+
export { createTransitionPayload, createArchivePayload, createInvokeScriptPayload, signTransaction, addTransactionSignature, getPublicKeyForRegistration, createStateMachinePayload, createScriptPayload, createDataTransactionRequest, } from './transaction.js';
|
|
15
|
+
export type { CreateStateMachineParams, CreateStateMachineMessage, CreateScriptParams, CreateScriptMessage, DataTransactionRequest, TransitionParams, TransitionStateMachineMessage, ArchiveParams, ArchiveStateMachineMessage, InvokeScriptParams, InvokeScriptMessage, } from './transaction.js';
|
|
16
|
+
export { normalizeCreateStateMachine, normalizeTransitionStateMachine, normalizeArchiveStateMachine, normalizeMessage, } from './normalize.js';
|
|
17
|
+
export { dropNulls } from './drop-nulls.js';
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @see modules/data_l1/src/main/scala/xyz/kd5ujc/data_l1/DataL1CustomRoutes.scala
|
|
9
9
|
* @packageDocumentation
|
|
10
10
|
*/
|
|
11
|
-
import type { Signed } from '
|
|
11
|
+
import type { Signed } from '@constellation-network/metagraph-sdk';
|
|
12
12
|
import type { OnChain, CalculatedState, StateMachineFiberRecord, ScriptFiberRecord, EventReceipt, OracleInvocation, FiberStatus } from './types.js';
|
|
13
13
|
/**
|
|
14
14
|
* Checkpoint response from the metagraph (ordinal + calculated state).
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* These helpers create properly formatted payloads for the bridge's
|
|
5
5
|
* self-signed mode, where clients sign their own transactions.
|
|
6
6
|
*/
|
|
7
|
-
import type { Signed } from '
|
|
7
|
+
import type { Signed } from '@constellation-network/metagraph-sdk';
|
|
8
8
|
/**
|
|
9
9
|
* Parameters for creating a new state machine fiber
|
|
10
10
|
*/
|
|
@@ -142,11 +142,11 @@ export declare const TransactionReferenceSchema: z.ZodObject<{
|
|
|
142
142
|
ordinal: z.ZodNumber;
|
|
143
143
|
hash: z.ZodString;
|
|
144
144
|
}, "strip", z.ZodTypeAny, {
|
|
145
|
-
hash: string;
|
|
146
145
|
ordinal: number;
|
|
147
|
-
}, {
|
|
148
146
|
hash: string;
|
|
147
|
+
}, {
|
|
149
148
|
ordinal: number;
|
|
149
|
+
hash: string;
|
|
150
150
|
}>;
|
|
151
151
|
/**
|
|
152
152
|
* Schema for CurrencyTransactionValue
|
|
@@ -191,11 +191,11 @@ export declare const CurrencyTransactionSchema: z.ZodObject<{
|
|
|
191
191
|
ordinal: z.ZodNumber;
|
|
192
192
|
hash: z.ZodString;
|
|
193
193
|
}, "strip", z.ZodTypeAny, {
|
|
194
|
-
hash: string;
|
|
195
194
|
ordinal: number;
|
|
196
|
-
}, {
|
|
197
195
|
hash: string;
|
|
196
|
+
}, {
|
|
198
197
|
ordinal: number;
|
|
198
|
+
hash: string;
|
|
199
199
|
}>;
|
|
200
200
|
}, "strip", z.ZodTypeAny, {
|
|
201
201
|
value: {
|
|
@@ -205,8 +205,8 @@ export declare const CurrencyTransactionSchema: z.ZodObject<{
|
|
|
205
205
|
fee: number;
|
|
206
206
|
};
|
|
207
207
|
parent: {
|
|
208
|
-
hash: string;
|
|
209
208
|
ordinal: number;
|
|
209
|
+
hash: string;
|
|
210
210
|
};
|
|
211
211
|
}, {
|
|
212
212
|
value: {
|
|
@@ -216,8 +216,8 @@ export declare const CurrencyTransactionSchema: z.ZodObject<{
|
|
|
216
216
|
fee?: number | undefined;
|
|
217
217
|
};
|
|
218
218
|
parent: {
|
|
219
|
-
hash: string;
|
|
220
219
|
ordinal: number;
|
|
220
|
+
hash: string;
|
|
221
221
|
};
|
|
222
222
|
}>;
|
|
223
223
|
/**
|
|
@@ -233,14 +233,14 @@ export declare const TransferParamsSchema: z.ZodObject<{
|
|
|
233
233
|
amount: z.ZodNumber;
|
|
234
234
|
fee: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
235
235
|
}, "strip", z.ZodTypeAny, {
|
|
236
|
-
amount: number;
|
|
237
236
|
from: string;
|
|
238
237
|
to: string;
|
|
238
|
+
amount: number;
|
|
239
239
|
fee: number;
|
|
240
240
|
}, {
|
|
241
|
-
amount: number;
|
|
242
241
|
from: string;
|
|
243
242
|
to: string;
|
|
243
|
+
amount: number;
|
|
244
244
|
fee?: number | undefined;
|
|
245
245
|
}>;
|
|
246
246
|
/**
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Backward-compatible verify wrapper.
|
|
3
|
+
*
|
|
4
|
+
* The package embeds `mode: "standard"|"dataUpdate"` in signed objects and
|
|
5
|
+
* its verify() ignores the `isDataUpdate` parameter when `mode` is present.
|
|
6
|
+
* This wrapper strips `mode` so callers' explicit `isDataUpdate` always wins.
|
|
7
|
+
*/
|
|
8
|
+
import type { Signed, VerificationResult } from '@constellation-network/metagraph-sdk';
|
|
9
|
+
export declare function verify<T>(signed: Signed<T>, isDataUpdate?: boolean): VerificationResult;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ottochain/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "TypeScript SDK for ottochain metagraph operations - signing, encoding, and network interactions",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -104,6 +104,7 @@
|
|
|
104
104
|
},
|
|
105
105
|
"dependencies": {
|
|
106
106
|
"@bufbuild/protobuf": "^2.11.0",
|
|
107
|
+
"@constellation-network/metagraph-sdk": "^0.2.0",
|
|
107
108
|
"@stardust-collective/dag4": "^2.6.0",
|
|
108
109
|
"@stardust-collective/dag4-keystore": "^2.6.0",
|
|
109
110
|
"canonicalize": "^2.1.0",
|
|
@@ -112,8 +113,9 @@
|
|
|
112
113
|
"zod": "^3.22.0"
|
|
113
114
|
},
|
|
114
115
|
"devDependencies": {
|
|
116
|
+
"@babel/preset-env": "^7.29.0",
|
|
115
117
|
"@types/jest": "^30.0.0",
|
|
116
|
-
"@types/node": "^
|
|
118
|
+
"@types/node": "^25.3.3",
|
|
117
119
|
"@typescript-eslint/eslint-plugin": "^8.56.1",
|
|
118
120
|
"@typescript-eslint/parser": "^8.56.1",
|
|
119
121
|
"eslint": "^9.39.3",
|
|
@@ -128,7 +130,7 @@
|
|
|
128
130
|
"@stardust-collective/dag4": "^2.6.0"
|
|
129
131
|
},
|
|
130
132
|
"engines": {
|
|
131
|
-
"node": ">=
|
|
133
|
+
"node": ">=20.19.0"
|
|
132
134
|
},
|
|
133
135
|
"publishConfig": {
|
|
134
136
|
"registry": "https://registry.npmjs.org"
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Binary Encoding
|
|
4
|
-
*
|
|
5
|
-
* Converts JSON data to binary format for cryptographic operations.
|
|
6
|
-
* Supports both regular encoding and DataUpdate encoding with Constellation prefix.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.encodeDataUpdate = exports.toBytes = void 0;
|
|
10
|
-
const canonicalize_js_1 = require("./canonicalize.js");
|
|
11
|
-
const types_js_1 = require("./types.js");
|
|
12
|
-
/**
|
|
13
|
-
* Convert data to binary bytes for signing
|
|
14
|
-
*
|
|
15
|
-
* For regular data:
|
|
16
|
-
* JSON -> RFC 8785 canonicalization -> UTF-8 bytes
|
|
17
|
-
*
|
|
18
|
-
* For DataUpdate (isDataUpdate=true):
|
|
19
|
-
* JSON -> RFC 8785 -> UTF-8 -> Base64 -> prepend Constellation prefix -> UTF-8 bytes
|
|
20
|
-
*
|
|
21
|
-
* @param data - Any JSON-serializable object
|
|
22
|
-
* @param isDataUpdate - If true, applies DataUpdate encoding with Constellation prefix
|
|
23
|
-
* @returns Binary bytes as Uint8Array
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```typescript
|
|
27
|
-
* // Regular encoding
|
|
28
|
-
* const bytes = toBytes({ action: 'test' });
|
|
29
|
-
*
|
|
30
|
-
* // DataUpdate encoding
|
|
31
|
-
* const updateBytes = toBytes({ action: 'test' }, true);
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
function toBytes(data, isDataUpdate = false) {
|
|
35
|
-
const canonicalJson = (0, canonicalize_js_1.canonicalize)(data);
|
|
36
|
-
const utf8Bytes = new TextEncoder().encode(canonicalJson);
|
|
37
|
-
if (isDataUpdate) {
|
|
38
|
-
// Base64 encode the UTF-8 bytes
|
|
39
|
-
const base64String = Buffer.from(utf8Bytes).toString('base64');
|
|
40
|
-
// Create the wrapped string with Constellation prefix
|
|
41
|
-
const wrappedString = `${types_js_1.CONSTELLATION_PREFIX}${base64String.length}\n${base64String}`;
|
|
42
|
-
return new TextEncoder().encode(wrappedString);
|
|
43
|
-
}
|
|
44
|
-
return utf8Bytes;
|
|
45
|
-
}
|
|
46
|
-
exports.toBytes = toBytes;
|
|
47
|
-
/**
|
|
48
|
-
* Encode data as a DataUpdate with Constellation prefix
|
|
49
|
-
*
|
|
50
|
-
* This is equivalent to `toBytes(data, true)`.
|
|
51
|
-
*
|
|
52
|
-
* @param data - Any JSON-serializable object
|
|
53
|
-
* @returns Binary bytes with Constellation prefix
|
|
54
|
-
*/
|
|
55
|
-
function encodeDataUpdate(data) {
|
|
56
|
-
return toBytes(data, true);
|
|
57
|
-
}
|
|
58
|
-
exports.encodeDataUpdate = encodeDataUpdate;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* RFC 8785 JSON Canonicalization
|
|
4
|
-
*
|
|
5
|
-
* Provides deterministic JSON serialization according to RFC 8785.
|
|
6
|
-
* This ensures identical JSON objects always produce identical strings.
|
|
7
|
-
*/
|
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.canonicalize = void 0;
|
|
13
|
-
const canonicalize_1 = __importDefault(require("canonicalize"));
|
|
14
|
-
/**
|
|
15
|
-
* Canonicalize JSON data according to RFC 8785
|
|
16
|
-
*
|
|
17
|
-
* Key features:
|
|
18
|
-
* - Object keys sorted by UTF-16BE binary comparison
|
|
19
|
-
* - Numbers serialized in shortest decimal representation
|
|
20
|
-
* - No whitespace
|
|
21
|
-
* - Proper Unicode escaping
|
|
22
|
-
*
|
|
23
|
-
* @param data - Any JSON-serializable object
|
|
24
|
-
* @returns Canonical JSON string
|
|
25
|
-
* @throws Error if data cannot be serialized to JSON
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```typescript
|
|
29
|
-
* const canonical = canonicalize({ b: 2, a: 1 });
|
|
30
|
-
* // Returns: '{"a":1,"b":2}'
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
function canonicalize(data) {
|
|
34
|
-
const result = (0, canonicalize_1.default)(data);
|
|
35
|
-
if (result === undefined) {
|
|
36
|
-
throw new Error('Failed to canonicalize data: data cannot be serialized to JSON');
|
|
37
|
-
}
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
40
|
-
exports.canonicalize = canonicalize;
|