@ottochain/sdk 1.2.0 → 1.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.
Files changed (103) hide show
  1. package/LICENSE +190 -0
  2. package/dist/cjs/index.js +34 -15
  3. package/dist/cjs/ottochain/index.js +20 -1
  4. package/dist/cjs/ottochain/metagraph-client.js +7 -8
  5. package/dist/cjs/ottochain/snapshot.js +3 -3
  6. package/dist/cjs/{metakit → ottochain}/transaction.js +4 -5
  7. package/dist/cjs/verify.js +17 -0
  8. package/dist/esm/apps/contracts/index.js +28 -10
  9. package/dist/esm/apps/corporate/index.js +79 -24
  10. package/dist/esm/apps/governance/index.js +85 -36
  11. package/dist/esm/apps/identity/constants.js +27 -22
  12. package/dist/esm/apps/identity/index.js +35 -7
  13. package/dist/esm/apps/index.js +32 -6
  14. package/dist/esm/apps/markets/index.js +27 -6
  15. package/dist/esm/apps/oracles/index.js +27 -7
  16. package/dist/esm/errors.js +19 -9
  17. package/dist/esm/generated/google/protobuf/struct.js +39 -33
  18. package/dist/esm/generated/google/protobuf/timestamp.js +9 -6
  19. package/dist/esm/generated/index.js +134 -10
  20. package/dist/esm/generated/ottochain/apps/contracts/v1/contract.js +54 -48
  21. package/dist/esm/generated/ottochain/apps/corporate/v1/corporate.js +357 -335
  22. package/dist/esm/generated/ottochain/apps/governance/v1/governance.js +299 -284
  23. package/dist/esm/generated/ottochain/apps/identity/v1/agent.js +47 -38
  24. package/dist/esm/generated/ottochain/apps/identity/v1/attestation.js +50 -44
  25. package/dist/esm/generated/ottochain/apps/markets/v1/market.js +86 -77
  26. package/dist/esm/generated/ottochain/apps/oracles/v1/oracle.js +72 -66
  27. package/dist/esm/generated/ottochain/v1/common.js +4 -1
  28. package/dist/esm/generated/ottochain/v1/fiber.js +96 -90
  29. package/dist/esm/generated/ottochain/v1/messages.js +82 -79
  30. package/dist/esm/generated/ottochain/v1/records.js +140 -137
  31. package/dist/esm/index.js +86 -20
  32. package/dist/esm/{metakit → ottochain}/drop-nulls.js +5 -1
  33. package/dist/esm/ottochain/index.js +56 -3
  34. package/dist/esm/ottochain/metagraph-client.js +16 -13
  35. package/dist/esm/{metakit → ottochain}/normalize.js +11 -4
  36. package/dist/esm/ottochain/snapshot.js +20 -10
  37. package/dist/esm/{metakit → ottochain}/transaction.js +25 -14
  38. package/dist/esm/ottochain/types.js +2 -1
  39. package/dist/esm/types.js +7 -2
  40. package/dist/esm/validation.js +76 -65
  41. package/dist/esm/verify.js +17 -0
  42. package/dist/types/index.d.ts +14 -7
  43. package/dist/types/ottochain/index.d.ts +4 -0
  44. package/dist/types/ottochain/metagraph-client.d.ts +1 -1
  45. package/dist/types/{metakit → ottochain}/transaction.d.ts +1 -1
  46. package/dist/types/validation.d.ts +8 -8
  47. package/dist/types/verify.d.ts +9 -0
  48. package/package.json +5 -3
  49. package/dist/cjs/metakit/binary.js +0 -58
  50. package/dist/cjs/metakit/canonicalize.js +0 -40
  51. package/dist/cjs/metakit/codec.js +0 -45
  52. package/dist/cjs/metakit/currency-transaction.js +0 -319
  53. package/dist/cjs/metakit/currency-types.js +0 -13
  54. package/dist/cjs/metakit/hash.js +0 -84
  55. package/dist/cjs/metakit/index.js +0 -86
  56. package/dist/cjs/metakit/network/client.js +0 -78
  57. package/dist/cjs/metakit/network/currency-l1-client.js +0 -101
  58. package/dist/cjs/metakit/network/data-l1-client.js +0 -76
  59. package/dist/cjs/metakit/network/index.js +0 -16
  60. package/dist/cjs/metakit/network/types.js +0 -20
  61. package/dist/cjs/metakit/sign.js +0 -120
  62. package/dist/cjs/metakit/signed-object.js +0 -100
  63. package/dist/cjs/metakit/types.js +0 -14
  64. package/dist/cjs/metakit/verify.js +0 -217
  65. package/dist/cjs/metakit/wallet.js +0 -127
  66. package/dist/esm/metakit/binary.js +0 -53
  67. package/dist/esm/metakit/canonicalize.js +0 -33
  68. package/dist/esm/metakit/codec.js +0 -38
  69. package/dist/esm/metakit/currency-transaction.js +0 -306
  70. package/dist/esm/metakit/currency-types.js +0 -10
  71. package/dist/esm/metakit/hash.js +0 -77
  72. package/dist/esm/metakit/index.js +0 -33
  73. package/dist/esm/metakit/network/client.js +0 -74
  74. package/dist/esm/metakit/network/currency-l1-client.js +0 -97
  75. package/dist/esm/metakit/network/data-l1-client.js +0 -72
  76. package/dist/esm/metakit/network/index.js +0 -9
  77. package/dist/esm/metakit/network/types.js +0 -16
  78. package/dist/esm/metakit/sign.js +0 -114
  79. package/dist/esm/metakit/signed-object.js +0 -94
  80. package/dist/esm/metakit/types.js +0 -11
  81. package/dist/esm/metakit/verify.js +0 -210
  82. package/dist/esm/metakit/wallet.js +0 -117
  83. package/dist/types/metakit/binary.d.ts +0 -38
  84. package/dist/types/metakit/canonicalize.d.ts +0 -26
  85. package/dist/types/metakit/codec.d.ts +0 -16
  86. package/dist/types/metakit/currency-transaction.d.ts +0 -157
  87. package/dist/types/metakit/currency-types.d.ts +0 -55
  88. package/dist/types/metakit/hash.d.ts +0 -50
  89. package/dist/types/metakit/index.d.ts +0 -26
  90. package/dist/types/metakit/network/client.d.ts +0 -23
  91. package/dist/types/metakit/network/currency-l1-client.d.ts +0 -71
  92. package/dist/types/metakit/network/data-l1-client.d.ts +0 -57
  93. package/dist/types/metakit/network/index.d.ts +0 -10
  94. package/dist/types/metakit/network/types.d.ts +0 -74
  95. package/dist/types/metakit/sign.d.ts +0 -65
  96. package/dist/types/metakit/signed-object.d.ts +0 -66
  97. package/dist/types/metakit/types.d.ts +0 -67
  98. package/dist/types/metakit/verify.d.ts +0 -55
  99. package/dist/types/metakit/wallet.d.ts +0 -70
  100. /package/dist/cjs/{metakit → ottochain}/drop-nulls.js +0 -0
  101. /package/dist/cjs/{metakit → ottochain}/normalize.js +0 -0
  102. /package/dist/types/{metakit → ottochain}/drop-nulls.d.ts +0 -0
  103. /package/dist/types/{metakit → ottochain}/normalize.d.ts +0 -0
@@ -1,74 +0,0 @@
1
- /**
2
- * Network types for L1 client operations
3
- *
4
- * @packageDocumentation
5
- */
6
- import type { CurrencyTransaction } from '../currency-types.js';
7
- /**
8
- * Network configuration for connecting to L1 nodes
9
- */
10
- export interface NetworkConfig {
11
- /** Currency L1 endpoint URL (e.g., 'http://localhost:9010') */
12
- l1Url?: string;
13
- /** Data L1 endpoint URL (e.g., 'http://localhost:8080') */
14
- dataL1Url?: string;
15
- /** Request timeout in milliseconds (default: 30000) */
16
- timeout?: number;
17
- }
18
- /**
19
- * HTTP request options
20
- */
21
- export interface RequestOptions {
22
- /** Request timeout in milliseconds */
23
- timeout?: number;
24
- /** Additional headers */
25
- headers?: Record<string, string>;
26
- }
27
- /**
28
- * Transaction status in the network
29
- */
30
- export type TransactionStatus = 'Waiting' | 'InProgress' | 'Accepted';
31
- /**
32
- * Pending transaction response from L1
33
- */
34
- export interface PendingTransaction {
35
- /** Transaction hash */
36
- hash: string;
37
- /** Current status */
38
- status: TransactionStatus;
39
- /** The transaction value */
40
- transaction: CurrencyTransaction;
41
- }
42
- /**
43
- * Response from posting a transaction
44
- */
45
- export interface PostTransactionResponse {
46
- /** Transaction hash */
47
- hash: string;
48
- }
49
- /**
50
- * Response from estimating data transaction fee
51
- */
52
- export interface EstimateFeeResponse {
53
- /** Estimated fee in smallest units */
54
- fee: number;
55
- /** Fee destination address */
56
- address: string;
57
- }
58
- /**
59
- * Response from posting data
60
- */
61
- export interface PostDataResponse {
62
- /** Data hash */
63
- hash: string;
64
- }
65
- /**
66
- * Network error with status code and response details
67
- */
68
- export declare class NetworkError extends Error {
69
- /** HTTP status code if applicable */
70
- statusCode?: number;
71
- /** Raw response body */
72
- responseBody?: string;
73
- constructor(message: string, statusCode?: number, responseBody?: string);
74
- }
@@ -1,65 +0,0 @@
1
- /**
2
- * Signing Functions
3
- *
4
- * ECDSA signing using secp256k1 curve via dag4js.
5
- * Implements the Constellation signature protocol.
6
- */
7
- import { SignatureProof } from './types.js';
8
- /**
9
- * Sign data using the regular Constellation protocol (non-DataUpdate)
10
- *
11
- * Protocol:
12
- * 1. Canonicalize JSON (RFC 8785)
13
- * 2. SHA-256 hash the canonical JSON string
14
- * 3. Sign using dag4.keyStore.sign
15
- *
16
- * @param data - Any JSON-serializable object
17
- * @param privateKey - Private key in hex format
18
- * @returns SignatureProof with public key ID and signature
19
- *
20
- * @example
21
- * ```typescript
22
- * const proof = await sign({ action: 'test' }, privateKeyHex);
23
- * console.log(proof.id); // public key (128 chars)
24
- * console.log(proof.signature); // DER signature
25
- * ```
26
- */
27
- export declare function sign<T>(data: T, privateKey: string): Promise<SignatureProof>;
28
- /**
29
- * Sign data as a DataUpdate (with Constellation prefix)
30
- *
31
- * Protocol:
32
- * 1. Canonicalize JSON (RFC 8785)
33
- * 2. Base64 encode the canonical JSON
34
- * 3. Sign using dag4.keyStore.dataSign (adds Constellation prefix internally)
35
- *
36
- * @param data - Any JSON-serializable object
37
- * @param privateKey - Private key in hex format
38
- * @returns SignatureProof
39
- */
40
- export declare function signDataUpdate<T>(data: T, privateKey: string): Promise<SignatureProof>;
41
- /**
42
- * Sign a pre-computed SHA-256 hash
43
- *
44
- * This is the low-level signing function. Use `sign()` or `signDataUpdate()`
45
- * for most use cases.
46
- *
47
- * Protocol (performed by dag4.keyStore.sign):
48
- * 1. Treat hashHex as UTF-8 bytes (64 ASCII characters = 64 bytes)
49
- * 2. SHA-512 hash those bytes (produces 64 bytes)
50
- * 3. Truncate to first 32 bytes (for secp256k1 curve order)
51
- * 4. Sign with ECDSA secp256k1
52
- * 5. Return DER-encoded signature
53
- *
54
- * @param hashHex - SHA-256 hash as 64-character hex string
55
- * @param privateKey - Private key in hex format (64 characters)
56
- * @returns DER-encoded signature in hex format
57
- *
58
- * @example
59
- * ```typescript
60
- * // Compute your own hash
61
- * const hashHex = sha256(myData);
62
- * const signature = await signHash(hashHex, privateKey);
63
- * ```
64
- */
65
- export declare function signHash(hashHex: string, privateKey: string): Promise<string>;
@@ -1,66 +0,0 @@
1
- /**
2
- * High-Level Signed Object API
3
- *
4
- * Convenience functions for creating and managing signed objects.
5
- */
6
- import { Signed, SigningOptions } from './types.js';
7
- /**
8
- * Create a signed object with a single signature
9
- *
10
- * @param value - Any JSON-serializable object
11
- * @param privateKey - Private key in hex format
12
- * @param options - Signing options
13
- * @returns Signed object ready for submission
14
- *
15
- * @example
16
- * ```typescript
17
- * // Sign a regular data object
18
- * const signed = await createSignedObject(myData, privateKey);
19
- *
20
- * // Sign as DataUpdate for L1 submission
21
- * const signedUpdate = await createSignedObject(myData, privateKey, { isDataUpdate: true });
22
- * ```
23
- */
24
- export declare function createSignedObject<T>(value: T, privateKey: string, options?: SigningOptions): Promise<Signed<T>>;
25
- /**
26
- * Add an additional signature to an existing signed object
27
- *
28
- * This allows building multi-signature objects where multiple parties
29
- * need to sign the same data.
30
- *
31
- * @param signed - Existing signed object
32
- * @param privateKey - Private key in hex format
33
- * @param options - Signing options (must match original signing)
34
- * @returns New signed object with additional proof
35
- *
36
- * @example
37
- * ```typescript
38
- * // First party signs
39
- * let signed = await createSignedObject(data, party1Key);
40
- *
41
- * // Second party adds signature
42
- * signed = await addSignature(signed, party2Key);
43
- *
44
- * // Now has 2 proofs
45
- * console.log(signed.proofs.length); // 2
46
- * ```
47
- */
48
- export declare function addSignature<T>(signed: Signed<T>, privateKey: string, options?: SigningOptions): Promise<Signed<T>>;
49
- /**
50
- * Create a signed object with multiple signatures at once
51
- *
52
- * Useful when you have access to multiple private keys and want
53
- * to create a multi-sig object in one operation.
54
- *
55
- * @param value - Any JSON-serializable object
56
- * @param privateKeys - Array of private keys in hex format
57
- * @param options - Signing options
58
- * @returns Signed object with multiple proofs
59
- *
60
- * @example
61
- * ```typescript
62
- * const signed = await batchSign(data, [key1, key2, key3]);
63
- * console.log(signed.proofs.length); // 3
64
- * ```
65
- */
66
- export declare function batchSign<T>(value: T, privateKeys: string[], options?: SigningOptions): Promise<Signed<T>>;
@@ -1,67 +0,0 @@
1
- /**
2
- * Core type definitions for the Ottochain SDK
3
- */
4
- /**
5
- * A signature proof containing the signer's public key ID and signature
6
- */
7
- export interface SignatureProof {
8
- /** Public key hex (uncompressed, without 04 prefix) - 128 characters */
9
- id: string;
10
- /** DER-encoded ECDSA signature in hex format */
11
- signature: string;
12
- }
13
- /**
14
- * A signed object wrapping a value with one or more signature proofs
15
- */
16
- export interface Signed<T> {
17
- /** The signed value */
18
- value: T;
19
- /** Array of signature proofs */
20
- proofs: SignatureProof[];
21
- }
22
- /**
23
- * A key pair for signing operations
24
- */
25
- export interface KeyPair {
26
- /** Private key in hex format */
27
- privateKey: string;
28
- /** Public key in hex format (uncompressed, with 04 prefix) */
29
- publicKey: string;
30
- /** DAG address derived from the public key */
31
- address: string;
32
- }
33
- /**
34
- * A hash result containing both hex string and raw bytes
35
- */
36
- export interface Hash {
37
- /** SHA-256 hash as 64-character hex string */
38
- value: string;
39
- /** Raw 32-byte hash as Uint8Array */
40
- bytes: Uint8Array;
41
- }
42
- /**
43
- * Result of signature verification
44
- */
45
- export interface VerificationResult {
46
- /** Whether all signatures are valid */
47
- isValid: boolean;
48
- /** Proofs that passed verification */
49
- validProofs: SignatureProof[];
50
- /** Proofs that failed verification */
51
- invalidProofs: SignatureProof[];
52
- }
53
- /**
54
- * Options for signing operations
55
- */
56
- export interface SigningOptions {
57
- /** Whether to sign as a DataUpdate (with Constellation prefix) */
58
- isDataUpdate?: boolean;
59
- }
60
- /**
61
- * Supported signature algorithm
62
- */
63
- export declare const ALGORITHM: "SECP256K1_RFC8785_V1";
64
- /**
65
- * Constellation prefix for DataUpdate signing
66
- */
67
- export declare const CONSTELLATION_PREFIX = "\u0019Constellation Signed Data:\n";
@@ -1,55 +0,0 @@
1
- /**
2
- * Signature Verification
3
- *
4
- * Verify ECDSA signatures using secp256k1 curve via dag4js.
5
- */
6
- import { Signed, SignatureProof, VerificationResult } from './types.js';
7
- /**
8
- * Verify a signed object
9
- *
10
- * @param signed - Signed object with value and proofs
11
- * @param isDataUpdate - Whether the value was signed as a DataUpdate
12
- * @returns VerificationResult with valid/invalid proof lists
13
- *
14
- * @example
15
- * ```typescript
16
- * const result = await verify(signedObject);
17
- * if (result.isValid) {
18
- * console.log('All signatures valid');
19
- * }
20
- * ```
21
- */
22
- export declare function verify<T>(signed: Signed<T>, isDataUpdate?: boolean): Promise<VerificationResult>;
23
- /**
24
- * Verify a signature against a SHA-256 hash
25
- *
26
- * Protocol:
27
- * 1. Treat hash hex as UTF-8 bytes (NOT hex decode)
28
- * 2. SHA-512 hash
29
- * 3. Truncate to 32 bytes (handled internally by dag4)
30
- * 4. Verify ECDSA signature
31
- *
32
- * @param hashHex - SHA-256 hash as 64-character hex string
33
- * @param signature - DER-encoded signature in hex format
34
- * @param publicKeyId - Public key in hex (with or without 04 prefix)
35
- * @returns true if signature is valid
36
- */
37
- export declare function verifyHash(hashHex: string, signature: string, publicKeyId: string): Promise<boolean>;
38
- /**
39
- * Verify a single signature proof against data
40
- *
41
- * @param data - The original data that was signed
42
- * @param proof - The signature proof to verify
43
- * @param isDataUpdate - Whether data was signed as DataUpdate
44
- * @returns true if signature is valid
45
- */
46
- export declare function verifySignature<T>(data: T, proof: SignatureProof, isDataUpdate?: boolean): Promise<boolean>;
47
- /**
48
- * Normalize a DER-encoded signature to use low-S value.
49
- *
50
- * BIP 62/146 requires S values to be in the lower half of the curve order.
51
- * Some signing implementations produce high-S signatures which are mathematically
52
- * valid but rejected by strict verifiers. This normalizes high-S to low-S by
53
- * computing S' = N - S where N is the curve order.
54
- */
55
- export declare function normalizeSignatureToLowS(signatureHex: string): string;
@@ -1,70 +0,0 @@
1
- /**
2
- * Wallet and Key Management Utilities
3
- *
4
- * Functions for generating and managing cryptographic keys.
5
- */
6
- import { KeyPair } from './types.js';
7
- /**
8
- * Generate a new random key pair
9
- *
10
- * @returns KeyPair with private key, public key, and DAG address
11
- *
12
- * @example
13
- * ```typescript
14
- * const keyPair = generateKeyPair();
15
- * console.log(keyPair.address); // DAG address
16
- * console.log(keyPair.privateKey); // 64 char hex
17
- * console.log(keyPair.publicKey); // 130 char hex (with 04 prefix)
18
- * ```
19
- */
20
- export declare function generateKeyPair(): KeyPair;
21
- /**
22
- * Derive a key pair from an existing private key
23
- *
24
- * @param privateKey - Private key in hex format (64 characters)
25
- * @returns KeyPair with private key, public key, and DAG address
26
- *
27
- * @example
28
- * ```typescript
29
- * const keyPair = keyPairFromPrivateKey(existingPrivateKey);
30
- * ```
31
- */
32
- export declare function keyPairFromPrivateKey(privateKey: string): KeyPair;
33
- /**
34
- * Get the public key hex from a private key
35
- *
36
- * @param privateKey - Private key in hex format
37
- * @param compressed - If true, returns compressed public key (33 bytes)
38
- * @returns Public key in hex format
39
- */
40
- export declare function getPublicKeyHex(privateKey: string, compressed?: boolean): string;
41
- /**
42
- * Get the public key ID (without 04 prefix) from a private key
43
- *
44
- * This format is used in SignatureProof.id
45
- *
46
- * @param privateKey - Private key in hex format
47
- * @returns Public key ID (128 characters, no 04 prefix)
48
- */
49
- export declare function getPublicKeyId(privateKey: string): string;
50
- /**
51
- * Get DAG address from a public key
52
- *
53
- * @param publicKey - Public key in hex format (with or without 04 prefix)
54
- * @returns DAG address string
55
- */
56
- export declare function getAddress(publicKey: string): string;
57
- /**
58
- * Validate that a private key is correctly formatted
59
- *
60
- * @param privateKey - Private key to validate
61
- * @returns true if valid hex string of correct length
62
- */
63
- export declare function isValidPrivateKey(privateKey: string): boolean;
64
- /**
65
- * Validate that a public key is correctly formatted
66
- *
67
- * @param publicKey - Public key to validate
68
- * @returns true if valid hex string of correct length
69
- */
70
- export declare function isValidPublicKey(publicKey: string): boolean;
File without changes
File without changes