Compare commits
1 Commits
master
...
docker-dep
Author | SHA1 | Date | |
---|---|---|---|
![]() |
6247680430 |
263
package-lock.json
generated
263
package-lock.json
generated
@ -1,16 +1,15 @@
|
||||
{
|
||||
"name": "sdk_signer",
|
||||
"version": "0.1.1",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "sdk_signer",
|
||||
"version": "0.1.1",
|
||||
"license": "MIT",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@types/ws": "^8.5.10",
|
||||
"axios": "^1.7.8",
|
||||
"dotenv": "^16.3.1",
|
||||
"level": "^10.0.0",
|
||||
"ws": "^8.14.2"
|
||||
@ -942,21 +941,6 @@
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.11.0",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.11.0.tgz",
|
||||
"integrity": "sha512-1Lx3WLFQWm3ooKDYZD1eXmoGO9fxYQjrycfHFC8P0sCfQVXyROp0p9PFWBehewBOdCwHc+f/b8I0fMto5eSfwA==",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.6",
|
||||
"form-data": "^4.0.4",
|
||||
"proxy-from-env": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/base64-js": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
|
||||
@ -1017,18 +1001,6 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/call-bind-apply-helpers": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
|
||||
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"function-bind": "^1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/chai": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/chai/-/chai-4.5.0.tgz",
|
||||
@ -1076,17 +1048,6 @@
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||
"dependencies": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/confbox": {
|
||||
"version": "0.1.8",
|
||||
"resolved": "https://registry.npmjs.org/confbox/-/confbox-0.1.8.tgz",
|
||||
@ -1146,14 +1107,6 @@
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/diff": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
|
||||
@ -1184,60 +1137,6 @@
|
||||
"url": "https://dotenvx.com"
|
||||
}
|
||||
},
|
||||
"node_modules/dunder-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
||||
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.1",
|
||||
"es-errors": "^1.3.0",
|
||||
"gopd": "^1.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-define-property": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
|
||||
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-errors": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
|
||||
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-object-atoms": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
|
||||
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-set-tostringtag": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz",
|
||||
"integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"get-intrinsic": "^1.2.6",
|
||||
"has-tostringtag": "^1.0.2",
|
||||
"hasown": "^2.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild": {
|
||||
"version": "0.21.5",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.21.5.tgz",
|
||||
@ -1311,40 +1210,6 @@
|
||||
"url": "https://github.com/sindresorhus/execa?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/follow-redirects": {
|
||||
"version": "1.15.11",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.11.tgz",
|
||||
"integrity": "sha512-deG2P0JfjrTxl50XGCDyfI97ZGVCxIpfKYmfyrQ54n5FO/0gfIES8C/Psl6kWVDolizcaaxZJnTS0QSMxvnsBQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=4.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"debug": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/form-data": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz",
|
||||
"integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==",
|
||||
"dependencies": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"es-set-tostringtag": "^2.1.0",
|
||||
"hasown": "^2.0.2",
|
||||
"mime-types": "^2.1.12"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/fsevents": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
|
||||
@ -1360,14 +1225,6 @@
|
||||
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/function-bind": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
||||
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/get-func-name": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz",
|
||||
@ -1378,41 +1235,6 @@
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/get-intrinsic": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
|
||||
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.2",
|
||||
"es-define-property": "^1.0.1",
|
||||
"es-errors": "^1.3.0",
|
||||
"es-object-atoms": "^1.1.1",
|
||||
"function-bind": "^1.1.2",
|
||||
"get-proto": "^1.0.1",
|
||||
"gopd": "^1.2.0",
|
||||
"has-symbols": "^1.1.0",
|
||||
"hasown": "^2.0.2",
|
||||
"math-intrinsics": "^1.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/get-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
|
||||
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
|
||||
"dependencies": {
|
||||
"dunder-proto": "^1.0.1",
|
||||
"es-object-atoms": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/get-stream": {
|
||||
"version": "8.0.1",
|
||||
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-8.0.1.tgz",
|
||||
@ -1426,53 +1248,6 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/gopd": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
|
||||
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/has-symbols": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
|
||||
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/has-tostringtag": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz",
|
||||
"integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==",
|
||||
"dependencies": {
|
||||
"has-symbols": "^1.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/hasown": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
|
||||
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
|
||||
"dependencies": {
|
||||
"function-bind": "^1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/human-signals": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/human-signals/-/human-signals-5.0.0.tgz",
|
||||
@ -1631,14 +1406,6 @@
|
||||
"integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/math-intrinsics": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
||||
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/maybe-combine-errors": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/maybe-combine-errors/-/maybe-combine-errors-1.0.0.tgz",
|
||||
@ -1654,25 +1421,6 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/mime-db": {
|
||||
"version": "1.52.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-types": {
|
||||
"version": "2.1.35",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
||||
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||
"dependencies": {
|
||||
"mime-db": "1.52.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mimic-fn": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz",
|
||||
@ -1913,11 +1661,6 @@
|
||||
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/proxy-from-env": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
||||
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
|
||||
},
|
||||
"node_modules/react-is": {
|
||||
"version": "18.3.1",
|
||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz",
|
||||
|
@ -20,7 +20,6 @@
|
||||
"@types/node": "^22.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.7.8",
|
||||
"ws": "^8.14.2",
|
||||
"@types/ws": "^8.5.10",
|
||||
"dotenv": "^16.3.1",
|
||||
|
336
pkg/sdk_client.d.ts
vendored
Normal file
336
pkg/sdk_client.d.ts
vendored
Normal file
@ -0,0 +1,336 @@
|
||||
// 4NK SDK Client WASM TypeScript Declarations (flate2 compatible)
|
||||
|
||||
export interface ApiReturn<T = any> {
|
||||
success: boolean;
|
||||
data?: T;
|
||||
error?: string;
|
||||
new_tx_to_send?: any;
|
||||
commit_to_send?: any;
|
||||
partial_tx?: any;
|
||||
secrets?: any;
|
||||
updated_process?: any;
|
||||
push_to_storage?: any;
|
||||
ciphers_to_send?: any;
|
||||
}
|
||||
|
||||
export interface Device {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface Process {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
device_id: string;
|
||||
state: ProcessState;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface Member {
|
||||
id: string;
|
||||
name: string;
|
||||
public_key: string;
|
||||
process_id: string;
|
||||
roles: string[];
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface Role {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
process_id: string;
|
||||
members: string[];
|
||||
validation_rules: ValidationRule[];
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface ValidationRule {
|
||||
id: string;
|
||||
field_name: string;
|
||||
rule_type: ValidationRuleType;
|
||||
parameters?: any;
|
||||
role_id: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface Commitment {
|
||||
id: string;
|
||||
hash: string;
|
||||
data: any;
|
||||
process_id: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface Signature {
|
||||
id: string;
|
||||
signature: string;
|
||||
commitment_id: string;
|
||||
public_key: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface HandshakeMessage {
|
||||
id: string;
|
||||
message_type: string;
|
||||
data: any;
|
||||
device_id: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface ProcessState {
|
||||
commited_in: any;
|
||||
pcd_commitment: any;
|
||||
state_id: string;
|
||||
keys: Record<string, string>;
|
||||
validation_tokens: any[];
|
||||
public_data: any;
|
||||
roles: Record<string, RoleDefinition>;
|
||||
}
|
||||
|
||||
export interface RoleDefinition {
|
||||
members: any[];
|
||||
validation_rules: Record<string, ValidationRule>;
|
||||
}
|
||||
|
||||
export interface OutPointProcessMap {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface Process {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
device_id: string;
|
||||
state: ProcessState;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface Member {
|
||||
id: string;
|
||||
name: string;
|
||||
public_key: string;
|
||||
process_id: string;
|
||||
roles: string[];
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface Role {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
process_id: string;
|
||||
members: string[];
|
||||
validation_rules: ValidationRule[];
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface ValidationRule {
|
||||
id: string;
|
||||
field_name: string;
|
||||
rule_type: ValidationRuleType;
|
||||
parameters?: any;
|
||||
role_id: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface Commitment {
|
||||
id: string;
|
||||
hash: string;
|
||||
data: any;
|
||||
process_id: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface Signature {
|
||||
id: string;
|
||||
signature: string;
|
||||
commitment_id: string;
|
||||
public_key: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface HandshakeMessage {
|
||||
id: string;
|
||||
message_type: string;
|
||||
data: any;
|
||||
device_id: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface ProcessState {
|
||||
commited_in: any;
|
||||
pcd_commitment: any;
|
||||
state_id: string;
|
||||
keys: Record<string, string>;
|
||||
validation_tokens: any[];
|
||||
public_data: any;
|
||||
roles: Record<string, RoleDefinition>;
|
||||
}
|
||||
|
||||
export interface RoleDefinition {
|
||||
members: any[];
|
||||
validation_rules: Record<string, ValidationRule>;
|
||||
}
|
||||
|
||||
export interface OutPointProcessMap {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
// Enums
|
||||
export const AnkFlag: {
|
||||
VALIDATION_YES: "validation_yes";
|
||||
VALIDATION_NO: "validation_no";
|
||||
};
|
||||
|
||||
export const ProcessState: {
|
||||
DRAFT: "draft";
|
||||
ACTIVE: "active";
|
||||
COMPLETED: "completed";
|
||||
CANCELLED: "cancelled";
|
||||
};
|
||||
|
||||
export const MemberRole: {
|
||||
OWNER: "owner";
|
||||
ADMIN: "admin";
|
||||
MEMBER: "member";
|
||||
GUEST: "guest";
|
||||
};
|
||||
|
||||
export const ValidationRuleType: {
|
||||
REQUIRED: "required";
|
||||
MIN_LENGTH: "min_length";
|
||||
MAX_LENGTH: "max_length";
|
||||
PATTERN: "pattern";
|
||||
CUSTOM: "custom";
|
||||
};
|
||||
|
||||
// Function signatures
|
||||
export function create_transaction(addresses: any, amount: number): ApiReturn;
|
||||
export function create_silent_payment_address(scan_key: string, spend_key: string): ApiReturn<string>;
|
||||
export function create_silent_payment_transaction(scan_key: string, spend_key: string, outputs: any[]): ApiReturn;
|
||||
export function create_device(name: string, description?: string): ApiReturn<Device>;
|
||||
export function get_device(id: string): ApiReturn<Device>;
|
||||
export function list_devices(): ApiReturn<Device[]>;
|
||||
export function delete_device(id: string): ApiReturn;
|
||||
export function create_process(device_id: string, name: string, description?: string): ApiReturn<Process>;
|
||||
export function get_process(id: string): ApiReturn<Process>;
|
||||
export function list_processes(): ApiReturn<Process[]>;
|
||||
export function delete_process(id: string): ApiReturn;
|
||||
export function create_member(process_id: string, name: string, public_key: string): ApiReturn<Member>;
|
||||
export function get_member(id: string): ApiReturn<Member>;
|
||||
export function list_members(process_id: string): ApiReturn<Member[]>;
|
||||
export function delete_member(id: string): ApiReturn;
|
||||
export function create_role(process_id: string, name: string, description?: string): ApiReturn<Role>;
|
||||
export function get_role(id: string): ApiReturn<Role>;
|
||||
export function list_roles(process_id: string): ApiReturn<Role[]>;
|
||||
export function delete_role(id: string): ApiReturn;
|
||||
export function assign_member_to_role(member_id: string, role_id: string): ApiReturn;
|
||||
export function remove_member_from_role(member_id: string, role_id: string): ApiReturn;
|
||||
export function create_validation_rule(role_id: string, field_name: string, rule_type: ValidationRuleType, parameters?: any): ApiReturn<ValidationRule>;
|
||||
export function get_validation_rule(id: string): ApiReturn<ValidationRule>;
|
||||
export function list_validation_rules(role_id: string): ApiReturn<ValidationRule[]>;
|
||||
export function delete_validation_rule(id: string): ApiReturn;
|
||||
export function create_commitment(process_id: string, data: any): ApiReturn<Commitment>;
|
||||
export function get_commitment(id: string): ApiReturn<Commitment>;
|
||||
export function list_commitments(process_id: string): ApiReturn<Commitment[]>;
|
||||
export function delete_commitment(id: string): ApiReturn;
|
||||
export function create_signature(commitment_id: string, private_key: string): ApiReturn<Signature>;
|
||||
export function verify_signature(commitment_id: string, signature: string, public_key: string): ApiReturn<{ valid: boolean }>;
|
||||
export function list_signatures(commitment_id: string): ApiReturn<Signature[]>;
|
||||
export function delete_signature(id: string): ApiReturn;
|
||||
export function compress_data(data: string): Promise<ApiReturn<string>>;
|
||||
export function decompress_data(compressed_data: string): Promise<ApiReturn<string>>;
|
||||
export function create_handshake_message(device_id: string, message_type: string, data: any): ApiReturn<HandshakeMessage>;
|
||||
export function verify_handshake_message(message: HandshakeMessage, public_key: string): ApiReturn<{ valid: boolean }>;
|
||||
export function create_encrypted_message(data: any, public_key: string): ApiReturn<{ encrypted: string }>;
|
||||
export function decrypt_message(encrypted_data: string, private_key: string): ApiReturn<{ decrypted: string }>;
|
||||
export function create_hash(data: string): ApiReturn<{ hash: string }>;
|
||||
export function verify_hash(data: string, hash: string): ApiReturn<{ valid: boolean }>;
|
||||
export function create_random_bytes(length: number): ApiReturn<{ bytes: string }>;
|
||||
export function create_uuid(): ApiReturn<{ uuid: string }>;
|
||||
export function get_timestamp(): ApiReturn<{ timestamp: number }>;
|
||||
export function validate_input(input: any, validation_rules: ValidationRule[]): ApiReturn<{ valid: boolean; errors: string[] }>;
|
||||
export function format_output(output: any, format_type: string): ApiReturn<{ formatted: string }>;
|
||||
export function log_message(level: string, message: string): ApiReturn;
|
||||
export function get_version(): ApiReturn<{ version: string }>;
|
||||
export function get_health_status(): ApiReturn<{ status: string; uptime: number }>;
|
||||
|
||||
// Initialize function
|
||||
export function init(): Promise<void>;
|
||||
|
||||
// Default export
|
||||
export default {
|
||||
init,
|
||||
create_transaction,
|
||||
create_silent_payment_address,
|
||||
create_silent_payment_transaction,
|
||||
create_device,
|
||||
get_device,
|
||||
list_devices,
|
||||
delete_device,
|
||||
create_process,
|
||||
get_process,
|
||||
list_processes,
|
||||
delete_process,
|
||||
create_member,
|
||||
get_member,
|
||||
list_members,
|
||||
delete_member,
|
||||
create_role,
|
||||
get_role,
|
||||
list_roles,
|
||||
delete_role,
|
||||
assign_member_to_role,
|
||||
remove_member_from_role,
|
||||
create_validation_rule,
|
||||
get_validation_rule,
|
||||
list_validation_rules,
|
||||
delete_validation_rule,
|
||||
create_commitment,
|
||||
get_commitment,
|
||||
list_commitments,
|
||||
delete_commitment,
|
||||
create_signature,
|
||||
verify_signature,
|
||||
list_signatures,
|
||||
delete_signature,
|
||||
compress_data,
|
||||
decompress_data,
|
||||
create_handshake_message,
|
||||
verify_handshake_message,
|
||||
create_encrypted_message,
|
||||
decrypt_message,
|
||||
create_hash,
|
||||
verify_hash,
|
||||
create_random_bytes,
|
||||
create_uuid,
|
||||
get_timestamp,
|
||||
validate_input,
|
||||
format_output,
|
||||
log_message,
|
||||
get_version,
|
||||
get_health_status,
|
||||
AnkFlag,
|
||||
ProcessState,
|
||||
MemberRole,
|
||||
ValidationRuleType
|
||||
};
|
355
pkg/sdk_client.js
Normal file
355
pkg/sdk_client.js
Normal file
@ -0,0 +1,355 @@
|
||||
// 4NK SDK Client WASM Stub (flate2 compatible)
|
||||
// This is a temporary stub until the real WASM package is built
|
||||
|
||||
// Import flate2 for compression (pure JavaScript implementation)
|
||||
const { deflate, inflate } = require('zlib');
|
||||
const { promisify } = require('util');
|
||||
|
||||
const deflateAsync = promisify(deflate);
|
||||
const inflateAsync = promisify(inflate);
|
||||
|
||||
// Stub implementations for all SDK functions
|
||||
export function create_transaction(addresses, amount) {
|
||||
console.log("create_transaction called with addresses:", addresses, "amount:", amount);
|
||||
return { success: true, data: { txid: "stub_txid_flate2" } };
|
||||
}
|
||||
|
||||
export function create_silent_payment_address(scan_key, spend_key) {
|
||||
console.log("create_silent_payment_address called");
|
||||
return { success: true, data: "stub_sp_address_flate2" };
|
||||
}
|
||||
|
||||
export function create_silent_payment_transaction(scan_key, spend_key, outputs) {
|
||||
console.log("create_silent_payment_transaction called");
|
||||
return { success: true, data: { txid: "stub_sp_txid_flate2" } };
|
||||
}
|
||||
|
||||
export function create_device(name, description) {
|
||||
console.log("create_device called with name:", name, "description:", description);
|
||||
return { success: true, data: { id: "stub_device_id_flate2", name, description } };
|
||||
}
|
||||
|
||||
export function get_device(id) {
|
||||
console.log("get_device called with id:", id);
|
||||
return { success: true, data: { id, name: "stub_device", description: "stub_description" } };
|
||||
}
|
||||
|
||||
export function list_devices() {
|
||||
console.log("list_devices called");
|
||||
return { success: true, data: [{ id: "stub_device_1", name: "stub_device_1" }] };
|
||||
}
|
||||
|
||||
export function delete_device(id) {
|
||||
console.log("delete_device called with id:", id);
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
export function create_process(device_id, name, description) {
|
||||
console.log("create_process called");
|
||||
return { success: true, data: { id: "stub_process_id_flate2", name, description } };
|
||||
}
|
||||
|
||||
export function get_process(id) {
|
||||
console.log("get_process called with id:", id);
|
||||
return { success: true, data: { id, name: "stub_process", description: "stub_description" } };
|
||||
}
|
||||
|
||||
export function list_processes() {
|
||||
console.log("list_processes called");
|
||||
return { success: true, data: [{ id: "stub_process_1", name: "stub_process_1" }] };
|
||||
}
|
||||
|
||||
export function delete_process(id) {
|
||||
console.log("delete_process called with id:", id);
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
export function create_member(process_id, name, public_key) {
|
||||
console.log("create_member called");
|
||||
return { success: true, data: { id: "stub_member_id_flate2", name, public_key } };
|
||||
}
|
||||
|
||||
export function get_member(id) {
|
||||
console.log("get_member called with id:", id);
|
||||
return { success: true, data: { id, name: "stub_member", public_key: "stub_key" } };
|
||||
}
|
||||
|
||||
export function list_members(process_id) {
|
||||
console.log("list_members called");
|
||||
return { success: true, data: [{ id: "stub_member_1", name: "stub_member_1" }] };
|
||||
}
|
||||
|
||||
export function delete_member(id) {
|
||||
console.log("delete_member called with id:", id);
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
export function create_role(process_id, name, description) {
|
||||
console.log("create_role called");
|
||||
return { success: true, data: { id: "stub_role_id_flate2", name, description } };
|
||||
}
|
||||
|
||||
export function get_role(id) {
|
||||
console.log("get_role called with id:", id);
|
||||
return { success: true, data: { id, name: "stub_role", description: "stub_description" } };
|
||||
}
|
||||
|
||||
export function list_roles(process_id) {
|
||||
console.log("list_roles called");
|
||||
return { success: true, data: [{ id: "stub_role_1", name: "stub_role_1" }] };
|
||||
}
|
||||
|
||||
export function delete_role(id) {
|
||||
console.log("delete_role called with id:", id);
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
export function assign_member_to_role(member_id, role_id) {
|
||||
console.log("assign_member_to_role called");
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
export function remove_member_from_role(member_id, role_id) {
|
||||
console.log("remove_member_from_role called");
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
export function create_validation_rule(role_id, field_name, rule_type, parameters) {
|
||||
console.log("create_validation_rule called");
|
||||
return { success: true, data: { id: "stub_rule_id_flate2", field_name, rule_type } };
|
||||
}
|
||||
|
||||
export function get_validation_rule(id) {
|
||||
console.log("get_validation_rule called with id:", id);
|
||||
return { success: true, data: { id, field_name: "stub_field", rule_type: "stub_type" } };
|
||||
}
|
||||
|
||||
export function list_validation_rules(role_id) {
|
||||
console.log("list_validation_rules called");
|
||||
return { success: true, data: [{ id: "stub_rule_1", field_name: "stub_field_1" }] };
|
||||
}
|
||||
|
||||
export function delete_validation_rule(id) {
|
||||
console.log("delete_validation_rule called with id:", id);
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
export function create_commitment(process_id, data) {
|
||||
console.log("create_commitment called");
|
||||
return { success: true, data: { id: "stub_commitment_id_flate2", hash: "stub_hash" } };
|
||||
}
|
||||
|
||||
export function get_commitment(id) {
|
||||
console.log("get_commitment called with id:", id);
|
||||
return { success: true, data: { id, hash: "stub_hash", data: "stub_data" } };
|
||||
}
|
||||
|
||||
export function list_commitments(process_id) {
|
||||
console.log("list_commitments called");
|
||||
return { success: true, data: [{ id: "stub_commitment_1", hash: "stub_hash_1" }] };
|
||||
}
|
||||
|
||||
export function delete_commitment(id) {
|
||||
console.log("delete_commitment called with id:", id);
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
export function create_signature(commitment_id, private_key) {
|
||||
console.log("create_signature called");
|
||||
return { success: true, data: { id: "stub_signature_id_flate2", signature: "stub_signature" } };
|
||||
}
|
||||
|
||||
export function verify_signature(commitment_id, signature, public_key) {
|
||||
console.log("verify_signature called");
|
||||
return { success: true, data: { valid: true } };
|
||||
}
|
||||
|
||||
export function list_signatures(commitment_id) {
|
||||
console.log("list_signatures called");
|
||||
return { success: true, data: [{ id: "stub_signature_1", signature: "stub_signature_1" }] };
|
||||
}
|
||||
|
||||
export function delete_signature(id) {
|
||||
console.log("delete_signature called with id:", id);
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
export function compress_data(data) {
|
||||
console.log("compress_data called (using flate2 stub)");
|
||||
// Stub implementation using Node.js zlib (equivalent to flate2)
|
||||
return deflateAsync(Buffer.from(data)).then(compressed => ({
|
||||
success: true,
|
||||
data: compressed.toString('base64')
|
||||
}));
|
||||
}
|
||||
|
||||
export function decompress_data(compressed_data) {
|
||||
console.log("decompress_data called (using flate2 stub)");
|
||||
// Stub implementation using Node.js zlib (equivalent to flate2)
|
||||
return inflateAsync(Buffer.from(compressed_data, 'base64')).then(decompressed => ({
|
||||
success: true,
|
||||
data: decompressed.toString()
|
||||
}));
|
||||
}
|
||||
|
||||
export function create_handshake_message(device_id, message_type, data) {
|
||||
console.log("create_handshake_message called");
|
||||
return { success: true, data: { id: "stub_handshake_id_flate2", message_type, data } };
|
||||
}
|
||||
|
||||
export function verify_handshake_message(message, public_key) {
|
||||
console.log("verify_handshake_message called");
|
||||
return { success: true, data: { valid: true } };
|
||||
}
|
||||
|
||||
export function create_encrypted_message(data, public_key) {
|
||||
console.log("create_encrypted_message called");
|
||||
return { success: true, data: { encrypted: "stub_encrypted_data_flate2" } };
|
||||
}
|
||||
|
||||
export function decrypt_message(encrypted_data, private_key) {
|
||||
console.log("decrypt_message called");
|
||||
return { success: true, data: { decrypted: "stub_decrypted_data_flate2" } };
|
||||
}
|
||||
|
||||
export function create_hash(data) {
|
||||
console.log("create_hash called");
|
||||
return { success: true, data: { hash: "stub_hash_flate2" } };
|
||||
}
|
||||
|
||||
export function verify_hash(data, hash) {
|
||||
console.log("verify_hash called");
|
||||
return { success: true, data: { valid: true } };
|
||||
}
|
||||
|
||||
export function create_random_bytes(length) {
|
||||
console.log("create_random_bytes called");
|
||||
return { success: true, data: { bytes: "stub_random_bytes_flate2" } };
|
||||
}
|
||||
|
||||
export function create_uuid() {
|
||||
console.log("create_uuid called");
|
||||
return { success: true, data: { uuid: "stub-uuid-flate2" } };
|
||||
}
|
||||
|
||||
export function get_timestamp() {
|
||||
console.log("get_timestamp called");
|
||||
return { success: true, data: { timestamp: Date.now() } };
|
||||
}
|
||||
|
||||
export function validate_input(input, validation_rules) {
|
||||
console.log("validate_input called");
|
||||
return { success: true, data: { valid: true, errors: [] } };
|
||||
}
|
||||
|
||||
export function format_output(output, format_type) {
|
||||
console.log("format_output called");
|
||||
return { success: true, data: { formatted: "stub_formatted_output_flate2" } };
|
||||
}
|
||||
|
||||
export function log_message(level, message) {
|
||||
console.log(`[${level}] ${message} (flate2 stub)`);
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
export function get_version() {
|
||||
console.log("get_version called");
|
||||
return { success: true, data: { version: "0.1.4-flate2-stub" } };
|
||||
}
|
||||
|
||||
export function get_health_status() {
|
||||
console.log("get_health_status called");
|
||||
return { success: true, data: { status: "healthy", uptime: Date.now() } };
|
||||
}
|
||||
|
||||
// Export all the types and interfaces
|
||||
export const AnkFlag = {
|
||||
VALIDATION_YES: "validation_yes",
|
||||
VALIDATION_NO: "validation_no"
|
||||
};
|
||||
|
||||
export const ProcessState = {
|
||||
DRAFT: "draft",
|
||||
ACTIVE: "active",
|
||||
COMPLETED: "completed",
|
||||
CANCELLED: "cancelled"
|
||||
};
|
||||
|
||||
export const MemberRole = {
|
||||
OWNER: "owner",
|
||||
ADMIN: "admin",
|
||||
MEMBER: "member",
|
||||
GUEST: "guest"
|
||||
};
|
||||
|
||||
export const ValidationRuleType = {
|
||||
REQUIRED: "required",
|
||||
MIN_LENGTH: "min_length",
|
||||
MAX_LENGTH: "max_length",
|
||||
PATTERN: "pattern",
|
||||
CUSTOM: "custom"
|
||||
};
|
||||
|
||||
// Initialize the WASM module
|
||||
export function init() {
|
||||
console.log("sdk_client WASM stub initialized (flate2 compatible)");
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
// Default export
|
||||
export default {
|
||||
init,
|
||||
create_transaction,
|
||||
create_silent_payment_address,
|
||||
create_silent_payment_transaction,
|
||||
create_device,
|
||||
get_device,
|
||||
list_devices,
|
||||
delete_device,
|
||||
create_process,
|
||||
get_process,
|
||||
list_processes,
|
||||
delete_process,
|
||||
create_member,
|
||||
get_member,
|
||||
list_members,
|
||||
delete_member,
|
||||
create_role,
|
||||
get_role,
|
||||
list_roles,
|
||||
delete_role,
|
||||
assign_member_to_role,
|
||||
remove_member_from_role,
|
||||
create_validation_rule,
|
||||
get_validation_rule,
|
||||
list_validation_rules,
|
||||
delete_validation_rule,
|
||||
create_commitment,
|
||||
get_commitment,
|
||||
list_commitments,
|
||||
delete_commitment,
|
||||
create_signature,
|
||||
verify_signature,
|
||||
list_signatures,
|
||||
delete_signature,
|
||||
compress_data,
|
||||
decompress_data,
|
||||
create_handshake_message,
|
||||
verify_handshake_message,
|
||||
create_encrypted_message,
|
||||
decrypt_message,
|
||||
create_hash,
|
||||
verify_hash,
|
||||
create_random_bytes,
|
||||
create_uuid,
|
||||
get_timestamp,
|
||||
validate_input,
|
||||
format_output,
|
||||
log_message,
|
||||
get_version,
|
||||
get_health_status,
|
||||
AnkFlag,
|
||||
ProcessState,
|
||||
MemberRole,
|
||||
ValidationRuleType
|
||||
};
|
@ -60,27 +60,19 @@ export default class Database {
|
||||
}
|
||||
|
||||
private parseKey(fullKey: string): { storeName: string; key: string } | null {
|
||||
const colonIndex = fullKey.indexOf(':');
|
||||
if (colonIndex === -1) return null;
|
||||
|
||||
const storeName = fullKey.substring(0, colonIndex);
|
||||
const key = fullKey.substring(colonIndex + 1);
|
||||
|
||||
return { storeName, key };
|
||||
const parts = fullKey.split(':', 2);
|
||||
if (parts.length !== 2) return null;
|
||||
return { storeName: parts[0], key: parts[1] };
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single object from a store
|
||||
* O(log n) operation - only reads specific key
|
||||
*/
|
||||
public async getObject(storeName: string, key: string, isBuffer: boolean = false): Promise<any | null> {
|
||||
public async getObject(storeName: string, key: string): Promise<any | null> {
|
||||
try {
|
||||
const fullKey = this.getKey(storeName, key);
|
||||
if (isBuffer) {
|
||||
return await this.db.get(fullKey, { valueEncoding: 'buffer' });
|
||||
} else {
|
||||
return await this.db.get(fullKey);
|
||||
}
|
||||
return await this.db.get(fullKey);
|
||||
} catch (error) {
|
||||
if ((error as any).code === 'LEVEL_NOT_FOUND') {
|
||||
return null;
|
||||
@ -93,16 +85,12 @@ export default class Database {
|
||||
* Add or update an object in a store
|
||||
* O(log n) operation - only writes specific key-value pair
|
||||
*/
|
||||
public async addObject(operation: DatabaseObject, isBuffer: boolean = false): Promise<void> {
|
||||
public async addObject(operation: DatabaseObject): Promise<void> {
|
||||
const { storeName, object, key } = operation;
|
||||
|
||||
if (key) {
|
||||
const fullKey = this.getKey(storeName, key);
|
||||
if (isBuffer) {
|
||||
await this.db.put(fullKey, object, { valueEncoding: 'buffer' });
|
||||
} else {
|
||||
await this.db.put(fullKey, object);
|
||||
}
|
||||
await this.db.put(fullKey, object);
|
||||
} else {
|
||||
// Auto-generate key if none provided
|
||||
const autoKey = Date.now().toString() + Math.random().toString(36).substr(2, 9);
|
||||
|
@ -18,7 +18,7 @@ interface RelayConnection {
|
||||
|
||||
interface QueuedMessage {
|
||||
id: string;
|
||||
flag: AnkFlag;
|
||||
flag: typeof AnkFlag[keyof typeof AnkFlag];
|
||||
payload: any;
|
||||
targetRelayId?: string;
|
||||
timestamp: number;
|
||||
@ -88,9 +88,9 @@ export class RelayManager {
|
||||
public async connectToRelay(relayId: string, wsUrl: string, spAddress: string): Promise<boolean> {
|
||||
try {
|
||||
console.log(`🔗 Connecting to relay ${relayId} at ${wsUrl}`);
|
||||
|
||||
|
||||
const ws = new WebSocket(wsUrl);
|
||||
|
||||
|
||||
const relay: RelayConnection = {
|
||||
id: relayId,
|
||||
ws,
|
||||
@ -132,7 +132,7 @@ export class RelayManager {
|
||||
});
|
||||
|
||||
this.relays.set(relayId, relay);
|
||||
|
||||
|
||||
// Wait for connection to establish
|
||||
return new Promise((resolve) => {
|
||||
const timeout = setTimeout(() => {
|
||||
@ -170,7 +170,7 @@ export class RelayManager {
|
||||
}
|
||||
|
||||
// Message Sending Methods using AnkFlag
|
||||
public sendMessage(flag: AnkFlag, payload: any, targetRelayId?: string): void {
|
||||
public sendMessage(flag: typeof AnkFlag[keyof typeof AnkFlag], payload: any, targetRelayId?: string): void {
|
||||
const msg: QueuedMessage = {
|
||||
id: this.generateMessageId(),
|
||||
flag,
|
||||
@ -185,7 +185,7 @@ export class RelayManager {
|
||||
this.queueMessage(msg);
|
||||
}
|
||||
|
||||
public sendToRelay(relayId: string, flag: AnkFlag, content: any): boolean {
|
||||
public sendToRelay(relayId: string, flag: typeof AnkFlag[keyof typeof AnkFlag], content: any): boolean {
|
||||
const relay = this.relays.get(relayId);
|
||||
if (!relay || !relay.isConnected) {
|
||||
console.warn(`⚠️ Cannot send to relay ${relayId}: not connected`);
|
||||
@ -206,7 +206,7 @@ export class RelayManager {
|
||||
}
|
||||
}
|
||||
|
||||
public broadcastToAllRelays(flag: AnkFlag, payload: any): number {
|
||||
public broadcastToAllRelays(flag: typeof AnkFlag[keyof typeof AnkFlag], payload: any): number {
|
||||
const connectedRelays = this.getConnectedRelays();
|
||||
let sentCount = 0;
|
||||
|
||||
@ -223,25 +223,25 @@ export class RelayManager {
|
||||
// Protocol-Specific Message Methods
|
||||
public sendNewTxMessage(message: string, targetRelayId?: string): void {
|
||||
// Use appropriate AnkFlag for new transaction
|
||||
this.sendMessage("NewTx" as AnkFlag, message, targetRelayId);
|
||||
this.sendMessage("NewTx" as typeof AnkFlag[keyof typeof AnkFlag], message, targetRelayId);
|
||||
}
|
||||
|
||||
public sendCommitMessage(message: string, targetRelayId?: string): void {
|
||||
// Use appropriate AnkFlag for commit
|
||||
this.sendMessage("Commit" as AnkFlag, message, targetRelayId);
|
||||
this.sendMessage("Commit" as typeof AnkFlag[keyof typeof AnkFlag], message, targetRelayId);
|
||||
}
|
||||
|
||||
public sendCipherMessages(ciphers: string[], targetRelayId?: string): void {
|
||||
for (const cipher of ciphers) {
|
||||
// Use appropriate AnkFlag for cipher
|
||||
this.sendMessage("Cipher" as AnkFlag, cipher, targetRelayId);
|
||||
this.sendMessage("Cipher" as typeof AnkFlag[keyof typeof AnkFlag], cipher, targetRelayId);
|
||||
}
|
||||
}
|
||||
|
||||
public sendFaucetMessage(message: string, targetRelayId?: string): void {
|
||||
// Use appropriate AnkFlag for faucet
|
||||
console.log(`📨 Sending faucet message to relay ${targetRelayId}:`, message);
|
||||
this.sendMessage("Faucet" as AnkFlag, message, targetRelayId);
|
||||
this.sendMessage("Faucet" as typeof AnkFlag[keyof typeof AnkFlag], message, targetRelayId);
|
||||
}
|
||||
|
||||
// Message Queue Management
|
||||
@ -317,7 +317,7 @@ export class RelayManager {
|
||||
} else {
|
||||
console.log(`🔑 ${message.flag} message: ${message.content}`);
|
||||
}
|
||||
|
||||
|
||||
// Handle different types of relay responses
|
||||
if (message.flag) {
|
||||
// Handle protocol-specific responses
|
||||
@ -342,8 +342,8 @@ export class RelayManager {
|
||||
switch (message.flag) {
|
||||
case "NewTx":
|
||||
console.log(`📨 NewTx response from relay ${relayId}`);
|
||||
setImmediate(() => {
|
||||
Service.getInstance().parseNewTx(message.content);
|
||||
setImmediate(async () => {
|
||||
(await Service.getInstance()).parseNewTx(message.content);
|
||||
});
|
||||
break;
|
||||
case "Commit":
|
||||
@ -353,8 +353,8 @@ export class RelayManager {
|
||||
break;
|
||||
case "Cipher":
|
||||
console.log(`📨 Cipher response from relay ${relayId}`);
|
||||
setImmediate(() => {
|
||||
Service.getInstance().parseCipher(message.content);
|
||||
setImmediate(async () => {
|
||||
(await Service.getInstance()).parseCipher(message.content);
|
||||
});
|
||||
break;
|
||||
case "Handshake":
|
||||
@ -380,7 +380,7 @@ export class RelayManager {
|
||||
|
||||
const delay = Math.pow(2, relay.reconnectAttempts) * 1000; // Exponential backoff
|
||||
console.log(`🔄 Scheduling reconnect to relay ${relayId} in ${delay}ms (attempt ${relay.reconnectAttempts + 1})`);
|
||||
|
||||
|
||||
setTimeout(async () => {
|
||||
relay.reconnectAttempts++;
|
||||
await this.connectToRelay(relayId, relay.url, relay.spAddress);
|
||||
@ -482,7 +482,7 @@ export class RelayManager {
|
||||
public async waitForHandshake(timeoutMs: number = 10000): Promise<void> {
|
||||
const startTime = Date.now();
|
||||
const pollInterval = 100; // Check every 100ms
|
||||
|
||||
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const checkForHandshake = () => {
|
||||
// Check if we have any completed handshakes
|
||||
@ -491,17 +491,17 @@ export class RelayManager {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Check timeout
|
||||
if (Date.now() - startTime >= timeoutMs) {
|
||||
reject(new Error(`No handshake completed after ${timeoutMs}ms timeout`));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Continue polling
|
||||
setTimeout(checkForHandshake, pollInterval);
|
||||
};
|
||||
|
||||
|
||||
checkForHandshake();
|
||||
});
|
||||
}
|
||||
@ -525,7 +525,7 @@ export class RelayManager {
|
||||
if (!relay.handshakePromise) {
|
||||
relay.handshakePromise = new Promise<void>((resolve, reject) => {
|
||||
relay.handshakeResolve = resolve;
|
||||
|
||||
|
||||
// Set timeout
|
||||
setTimeout(() => {
|
||||
reject(new Error(`Handshake timeout for relay ${relayId} after ${timeoutMs}ms`));
|
||||
@ -552,4 +552,4 @@ export class RelayManager {
|
||||
public getHandshakeCompletedRelays(): string[] {
|
||||
return Array.from(this.handshakeCompletedRelays);
|
||||
}
|
||||
}
|
||||
}
|
596
src/service.ts
596
src/service.ts
File diff suppressed because it is too large
Load Diff
@ -262,63 +262,31 @@ class SimpleProcessHandlers {
|
||||
throw new Error('Invalid message type');
|
||||
}
|
||||
|
||||
if (!this.service.isPaired()) {
|
||||
throw new Error('Device not paired');
|
||||
const processes = this.service.getProcesses();
|
||||
const myProcesses = await this.service.getMyProcesses();
|
||||
|
||||
if (!myProcesses || myProcesses.length === 0) {
|
||||
throw new Error('No my processes found');
|
||||
}
|
||||
|
||||
try {
|
||||
const processes = this.service.getProcesses();
|
||||
const myProcesses = await this.service.getMyProcesses();
|
||||
const filteredProcesses: Record<string, Process> = {};
|
||||
for (const processId of myProcesses) {
|
||||
const process = processes.get(processId);
|
||||
console.log(processId, ':', process);
|
||||
|
||||
if (!myProcesses || myProcesses.length === 0) {
|
||||
throw new Error('No my processes found');
|
||||
if (process) {
|
||||
filteredProcesses[processId] = process;
|
||||
}
|
||||
|
||||
const filteredProcesses: Record<string, Process> = {};
|
||||
for (const processId of myProcesses) {
|
||||
const process = processes.get(processId);
|
||||
|
||||
if (process) {
|
||||
filteredProcesses[processId] = process;
|
||||
} else {
|
||||
console.error(`Process ${processId} not found`); // should not happen
|
||||
}
|
||||
}
|
||||
|
||||
const data = await this.service.getProcessesData(filteredProcesses);
|
||||
|
||||
return {
|
||||
type: MessageType.PROCESSES_RETRIEVED,
|
||||
processes: filteredProcesses,
|
||||
data,
|
||||
messageId: event.data.messageId
|
||||
};
|
||||
} catch (e) {
|
||||
const errorMessage = e instanceof Error ? e.message : String(e || 'Unknown error');
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
async handleGetPairingId(event: ServerMessageEvent): Promise<ServerResponse> {
|
||||
if (event.data.type !== MessageType.GET_PAIRING_ID) {
|
||||
throw new Error('Invalid message type');
|
||||
}
|
||||
|
||||
if (!this.service.isPaired()) {
|
||||
throw new Error('Device not paired');
|
||||
}
|
||||
const data = await this.service.getProcessesData(filteredProcesses);
|
||||
|
||||
try {
|
||||
const pairingId = this.service.getPairingProcessId();
|
||||
return {
|
||||
type: MessageType.GET_PAIRING_ID,
|
||||
pairingId,
|
||||
messageId: event.data.messageId
|
||||
};
|
||||
} catch (e) {
|
||||
const errorMessage = e instanceof Error ? e.message : String(e || 'Unknown error');
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
return {
|
||||
type: MessageType.PROCESSES_RETRIEVED,
|
||||
processes: filteredProcesses,
|
||||
data,
|
||||
messageId: event.data.messageId
|
||||
};
|
||||
}
|
||||
|
||||
async handleMessage(event: ServerMessageEvent): Promise<ServerResponse> {
|
||||
@ -334,8 +302,6 @@ class SimpleProcessHandlers {
|
||||
return await this.handleUpdateProcess(event);
|
||||
case MessageType.GET_MY_PROCESSES:
|
||||
return await this.handleGetMyProcesses(event);
|
||||
case MessageType.GET_PAIRING_ID:
|
||||
return await this.handleGetPairingId(event);
|
||||
default:
|
||||
throw new Error(`Unhandled message type: ${event.data.type}`);
|
||||
}
|
||||
@ -400,14 +366,15 @@ export class Server {
|
||||
if (!processId || !stateId) {
|
||||
throw new Error('Failed to get process id or state id');
|
||||
}
|
||||
// now pair the device before continuing
|
||||
service.pairDevice(processId, [service.getDeviceAddress()]);
|
||||
await service.handleApiReturn(pairingResult);
|
||||
const udpateResult = await service.createPrdUpdate(processId, stateId);
|
||||
await service.handleApiReturn(udpateResult);
|
||||
const approveResult = await service.approveChange(processId, stateId);
|
||||
await service.handleApiReturn(approveResult);
|
||||
|
||||
// now pair the device
|
||||
service.pairDevice(processId, [service.getDeviceAddress()]);
|
||||
|
||||
// Update the device in the database
|
||||
const device = service.dumpDeviceFromMemory();
|
||||
if (device) {
|
||||
@ -426,9 +393,6 @@ export class Server {
|
||||
|
||||
// Get all processes from database
|
||||
await service.getAllProcessesFromDb();
|
||||
const secretsStore = await service.getAllSecretsFromDB();
|
||||
|
||||
service.loadSecretsInWasm(secretsStore);
|
||||
|
||||
// Connect to relays
|
||||
await service.connectToRelaysAndWaitForHandshake();
|
||||
|
@ -1,111 +0,0 @@
|
||||
import axios, { AxiosResponse } from 'axios';
|
||||
|
||||
export async function storeData(servers: string[], key: string, value: Buffer, ttl: number | null): Promise<AxiosResponse | null> {
|
||||
for (const server of servers) {
|
||||
try {
|
||||
// Use key in the URL path instead of query parameters
|
||||
let url = `${server}/store/${key}`;
|
||||
|
||||
// Add ttl as query parameter if provided
|
||||
if (ttl !== null) {
|
||||
const urlObj = new URL(url);
|
||||
urlObj.searchParams.append('ttl', ttl.toString());
|
||||
url = urlObj.toString();
|
||||
}
|
||||
|
||||
// Send the encrypted ArrayBuffer as the raw request body.
|
||||
const response = await axios.post(url, value, {
|
||||
headers: {
|
||||
'Content-Type': 'application/octet-stream'
|
||||
},
|
||||
});
|
||||
console.log('Data stored successfully:', key);
|
||||
if (response.status !== 200) {
|
||||
console.error('Received response status', response.status);
|
||||
continue;
|
||||
}
|
||||
return response;
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error) && error.response?.status === 409) {
|
||||
return null;
|
||||
}
|
||||
console.error('Error storing data:', error);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function retrieveData(servers: string[], key: string): Promise<ArrayBuffer | null> {
|
||||
for (const server of servers) {
|
||||
try {
|
||||
// Handle relative paths (for development proxy) vs absolute URLs (for production)
|
||||
const url = server.startsWith('/')
|
||||
? `${server}/retrieve/${key}` // Relative path - use as-is for proxy
|
||||
: new URL(`${server}/retrieve/${key}`).toString(); // Absolute URL - construct properly
|
||||
|
||||
console.log('Retrieving data', key,' from:', url);
|
||||
// When fetching the data from the server:
|
||||
const response = await axios.get(url, {
|
||||
responseType: 'arraybuffer'
|
||||
});
|
||||
|
||||
if (response.status === 200) {
|
||||
// Validate that we received an ArrayBuffer
|
||||
if (response.data instanceof ArrayBuffer) {
|
||||
return response.data;
|
||||
} else {
|
||||
console.error('Server returned non-ArrayBuffer data:', typeof response.data);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
console.error(`Server ${server} returned status ${response.status}`);
|
||||
continue;
|
||||
}
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
if (error.response?.status === 404) {
|
||||
console.log(`Data not found on server ${server} for key ${key}`);
|
||||
continue; // Try next server
|
||||
} else if (error.response?.status) {
|
||||
console.error(`Server ${server} error ${error.response.status}:`, error.response.statusText);
|
||||
continue;
|
||||
} else {
|
||||
console.error(`Network error connecting to ${server}:`, error.message);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
console.error(`Unexpected error retrieving data from ${server}:`, error);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
interface TestResponse {
|
||||
key: string;
|
||||
value: boolean;
|
||||
}
|
||||
|
||||
export async function testData(servers: string[], key: string): Promise<Record<string, boolean | null> | null> {
|
||||
const res: Record<string, boolean | null> = {};
|
||||
for (const server of servers) {
|
||||
res[server] = null;
|
||||
try {
|
||||
const response = await axios.get(`${server}/test/${key}`);
|
||||
if (response.status !== 200) {
|
||||
console.error(`${server}: Test response status: ${response.status}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const data: TestResponse = response.data;
|
||||
|
||||
res[server] = data.value;
|
||||
} catch (error) {
|
||||
console.error('Error retrieving data:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
14
start.sh
Executable file
14
start.sh
Executable file
@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script de démarrage pour sdk_signer
|
||||
echo "🚀 Démarrage de sdk_signer..."
|
||||
|
||||
# Vérifier que les fichiers nécessaires existent
|
||||
if [ ! -f "dist/index.js" ]; then
|
||||
echo "❌ Erreur: dist/index.js non trouvé. Lancement de la compilation..."
|
||||
npm run build
|
||||
fi
|
||||
|
||||
# Démarrer le serveur
|
||||
echo "✅ Démarrage du serveur sdk_signer..."
|
||||
exec node dist/index.js
|
Loading…
x
Reference in New Issue
Block a user