@omegax/protocol-sdk 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ export declare function stableStringify(value: unknown): string;
2
+ export declare function sha256Hex(value: Uint8Array | string): string;
3
+ export declare function sha256Bytes(value: Uint8Array | string): Uint8Array;
4
+ export declare function toIsoString(value: Date | string): string;
5
+ export declare function nowIso(): string;
6
+ export declare function newId(prefix: string): string;
7
+ export declare function anchorDiscriminator(namespace: string, name: string): Buffer;
8
+ export declare function encodeU64Le(value: bigint): Buffer;
9
+ export declare function encodeI64Le(value: bigint): Buffer;
10
+ export declare function encodeU32Le(value: number): Buffer;
11
+ export declare function encodeU16Le(value: number): Buffer;
12
+ export declare function encodeString(value: string): Buffer;
13
+ export declare function readU32Le(buffer: Buffer, offset: number): number;
14
+ export declare function readU16Le(buffer: Buffer, offset: number): number;
15
+ export declare function readU64Le(buffer: Buffer, offset: number): bigint;
16
+ export declare function readI64Le(buffer: Buffer, offset: number): bigint;
17
+ export declare function readString(buffer: Buffer, offset: number): {
18
+ value: string;
19
+ offset: number;
20
+ };
21
+ export declare function toHex(bytes: Uint8Array): string;
22
+ export declare function fromHex(value: string, expectedLength?: number): Uint8Array;
23
+ export declare function hashStringTo32(value: string): Uint8Array;
package/dist/utils.js ADDED
@@ -0,0 +1,98 @@
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ export function stableStringify(value) {
3
+ if (value === null || typeof value !== 'object') {
4
+ return JSON.stringify(value);
5
+ }
6
+ if (Array.isArray(value)) {
7
+ return `[${value.map(stableStringify).join(',')}]`;
8
+ }
9
+ const entries = Object.entries(value).sort(([a], [b]) => a.localeCompare(b));
10
+ return `{${entries
11
+ .map(([key, v]) => `${JSON.stringify(key)}:${stableStringify(v)}`)
12
+ .join(',')}}`;
13
+ }
14
+ export function sha256Hex(value) {
15
+ const hash = createHash('sha256');
16
+ hash.update(value);
17
+ return hash.digest('hex');
18
+ }
19
+ export function sha256Bytes(value) {
20
+ const hash = createHash('sha256');
21
+ hash.update(value);
22
+ return new Uint8Array(hash.digest());
23
+ }
24
+ export function toIsoString(value) {
25
+ if (typeof value === 'string')
26
+ return new Date(value).toISOString();
27
+ return value.toISOString();
28
+ }
29
+ export function nowIso() {
30
+ return new Date().toISOString();
31
+ }
32
+ export function newId(prefix) {
33
+ return `${prefix}_${randomUUID()}`;
34
+ }
35
+ export function anchorDiscriminator(namespace, name) {
36
+ const preimage = `${namespace}:${name}`;
37
+ const digest = createHash('sha256').update(preimage).digest();
38
+ return digest.subarray(0, 8);
39
+ }
40
+ export function encodeU64Le(value) {
41
+ const out = Buffer.alloc(8);
42
+ out.writeBigUInt64LE(value);
43
+ return out;
44
+ }
45
+ export function encodeI64Le(value) {
46
+ const out = Buffer.alloc(8);
47
+ out.writeBigInt64LE(value);
48
+ return out;
49
+ }
50
+ export function encodeU32Le(value) {
51
+ const out = Buffer.alloc(4);
52
+ out.writeUInt32LE(value >>> 0);
53
+ return out;
54
+ }
55
+ export function encodeU16Le(value) {
56
+ const out = Buffer.alloc(2);
57
+ out.writeUInt16LE(value & 0xffff);
58
+ return out;
59
+ }
60
+ export function encodeString(value) {
61
+ const bytes = Buffer.from(value, 'utf8');
62
+ return Buffer.concat([encodeU32Le(bytes.length), bytes]);
63
+ }
64
+ export function readU32Le(buffer, offset) {
65
+ return buffer.readUInt32LE(offset);
66
+ }
67
+ export function readU16Le(buffer, offset) {
68
+ return buffer.readUInt16LE(offset);
69
+ }
70
+ export function readU64Le(buffer, offset) {
71
+ return buffer.readBigUInt64LE(offset);
72
+ }
73
+ export function readI64Le(buffer, offset) {
74
+ return buffer.readBigInt64LE(offset);
75
+ }
76
+ export function readString(buffer, offset) {
77
+ const length = readU32Le(buffer, offset);
78
+ const start = offset + 4;
79
+ const end = start + length;
80
+ return {
81
+ value: buffer.subarray(start, end).toString('utf8'),
82
+ offset: end,
83
+ };
84
+ }
85
+ export function toHex(bytes) {
86
+ return Buffer.from(bytes).toString('hex');
87
+ }
88
+ export function fromHex(value, expectedLength) {
89
+ const normalized = value.trim().toLowerCase().replace(/^0x/, '');
90
+ const bytes = Buffer.from(normalized, 'hex');
91
+ if (typeof expectedLength === 'number' && bytes.length !== expectedLength) {
92
+ throw new Error(`invalid hex length: expected ${expectedLength}, got ${bytes.length}`);
93
+ }
94
+ return new Uint8Array(bytes);
95
+ }
96
+ export function hashStringTo32(value) {
97
+ return sha256Bytes(Buffer.from(value, 'utf8'));
98
+ }
package/package.json ADDED
@@ -0,0 +1,97 @@
1
+ {
2
+ "name": "@omegax/protocol-sdk",
3
+ "version": "0.4.0",
4
+ "description": "TypeScript SDK for OmegaX protocol oracle, reward, and coverage integrations on Solana.",
5
+ "keywords": [
6
+ "omegax",
7
+ "solana",
8
+ "protocol",
9
+ "oracle",
10
+ "sdk",
11
+ "health"
12
+ ],
13
+ "license": "Apache-2.0",
14
+ "private": false,
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/OmegaX-Health/omegax-sdk.git"
21
+ },
22
+ "homepage": "https://github.com/OmegaX-Health/omegax-sdk#readme",
23
+ "bugs": {
24
+ "url": "https://github.com/OmegaX-Health/omegax-sdk/issues"
25
+ },
26
+ "type": "module",
27
+ "main": "dist/index.js",
28
+ "types": "dist/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.js"
33
+ },
34
+ "./claims": {
35
+ "types": "./dist/claims.d.ts",
36
+ "import": "./dist/claims.js"
37
+ },
38
+ "./protocol": {
39
+ "types": "./dist/protocol.d.ts",
40
+ "import": "./dist/protocol.js"
41
+ },
42
+ "./protocol_seeds": {
43
+ "types": "./dist/protocol_seeds.d.ts",
44
+ "import": "./dist/protocol_seeds.js"
45
+ },
46
+ "./rpc": {
47
+ "types": "./dist/rpc.d.ts",
48
+ "import": "./dist/rpc.js"
49
+ },
50
+ "./oracle": {
51
+ "types": "./dist/oracle.d.ts",
52
+ "import": "./dist/oracle.js"
53
+ },
54
+ "./types": {
55
+ "types": "./dist/types.d.ts",
56
+ "import": "./dist/types.js"
57
+ },
58
+ "./utils": {
59
+ "types": "./dist/utils.d.ts",
60
+ "import": "./dist/utils.js"
61
+ },
62
+ "./package.json": "./package.json"
63
+ },
64
+ "files": [
65
+ "dist"
66
+ ],
67
+ "scripts": {
68
+ "clean": "rm -rf dist",
69
+ "build": "tsc -p tsconfig.json",
70
+ "prepare": "npm run build",
71
+ "prepack": "npm run build",
72
+ "sync:idl-fixture": "node scripts/sync-idl-fixture.mjs",
73
+ "docs:check": "node scripts/verify-doc-symbols.mjs",
74
+ "docs:sync:check": "node scripts/check-omegax-docs-sync.mjs",
75
+ "docs:sync:check:strict": "node scripts/check-omegax-docs-sync.mjs --strict",
76
+ "docs:sync:update": "node scripts/update-docs-sync-manifest.mjs",
77
+ "test": "node --import tsx --test $(find tests -name '*.test.ts' -print)",
78
+ "dev": "tsx watch src/index.ts"
79
+ },
80
+ "dependencies": {
81
+ "@solana/web3.js": "^1.98.4",
82
+ "bs58": "^6.0.0",
83
+ "tweetnacl": "^1.0.3"
84
+ },
85
+ "overrides": {
86
+ "bn.js": "^5.2.3"
87
+ },
88
+ "devDependencies": {
89
+ "@types/bs58": "^4.0.4",
90
+ "@types/node": "^20.17.16",
91
+ "tsx": "^4.19.2",
92
+ "typescript": "^5.7.3"
93
+ },
94
+ "engines": {
95
+ "node": ">=20"
96
+ }
97
+ }