@degenerate/generic 0.4.0 → 0.7.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/_settings/cryptography-settings.d.ts +5 -1
- package/dist/_settings/cryptography-settings.d.ts.map +1 -1
- package/dist/_settings/cryptography-settings.js +5 -1
- package/dist/crypto/index.d.ts +5 -9
- package/dist/crypto/index.d.ts.map +1 -1
- package/dist/crypto/index.js +7 -9
- package/dist/crypto/private-public-keys/create-ed25519-keys-from-mnemonic.d.ts +22 -0
- package/dist/crypto/private-public-keys/create-ed25519-keys-from-mnemonic.d.ts.map +1 -0
- package/dist/crypto/private-public-keys/create-ed25519-keys-from-mnemonic.js +65 -0
- package/dist/crypto/private-public-keys/get-ed25519-public-key-from-private-key.d.ts +11 -0
- package/dist/crypto/private-public-keys/get-ed25519-public-key-from-private-key.d.ts.map +1 -0
- package/dist/crypto/private-public-keys/get-ed25519-public-key-from-private-key.js +15 -0
- package/dist/crypto/signature/create-ed25519-signature.d.ts +16 -0
- package/dist/crypto/signature/create-ed25519-signature.d.ts.map +1 -0
- package/dist/crypto/signature/create-ed25519-signature.js +26 -0
- package/dist/crypto/signature/ed25519-primitives.d.ts +25 -0
- package/dist/crypto/signature/ed25519-primitives.d.ts.map +1 -0
- package/dist/crypto/signature/ed25519-primitives.js +65 -0
- package/dist/crypto/signature/verify-ed25519-signature.d.ts +13 -0
- package/dist/crypto/signature/verify-ed25519-signature.d.ts.map +1 -0
- package/dist/crypto/signature/verify-ed25519-signature.js +31 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +2 -0
- package/dist/errors/library/library-errors.d.ts +101 -0
- package/dist/errors/library/library-errors.d.ts.map +1 -0
- package/dist/errors/library/library-errors.js +133 -0
- package/dist/errors/settlement/settlement-errors.d.ts +74 -0
- package/dist/errors/settlement/settlement-errors.d.ts.map +1 -0
- package/dist/errors/settlement/settlement-errors.js +93 -0
- package/dist/errors/share-data/share-data-errors.d.ts +21 -0
- package/dist/errors/share-data/share-data-errors.d.ts.map +1 -1
- package/dist/errors/share-data/share-data-errors.js +30 -1
- package/dist/helpers/apply-share-function.d.ts +23 -0
- package/dist/helpers/apply-share-function.d.ts.map +1 -0
- package/dist/helpers/apply-share-function.js +32 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/library/authorize-library.d.ts +17 -0
- package/dist/library/authorize-library.d.ts.map +1 -0
- package/dist/library/authorize-library.js +39 -0
- package/dist/library/build-library.d.ts +49 -0
- package/dist/library/build-library.d.ts.map +1 -0
- package/dist/library/build-library.js +119 -0
- package/dist/library/caching-library-store.d.ts +19 -0
- package/dist/library/caching-library-store.d.ts.map +1 -0
- package/dist/library/caching-library-store.js +56 -0
- package/dist/library/canonical-json.d.ts +12 -0
- package/dist/library/canonical-json.d.ts.map +1 -0
- package/dist/library/canonical-json.js +30 -0
- package/dist/library/compile-rule-source.d.ts +21 -0
- package/dist/library/compile-rule-source.d.ts.map +1 -0
- package/dist/library/compile-rule-source.js +91 -0
- package/dist/library/evaluate-library-rules.d.ts +36 -0
- package/dist/library/evaluate-library-rules.d.ts.map +1 -0
- package/dist/library/evaluate-library-rules.js +47 -0
- package/dist/library/evaluate-library.d.ts +34 -0
- package/dist/library/evaluate-library.d.ts.map +1 -0
- package/dist/library/evaluate-library.js +66 -0
- package/dist/library/in-memory-library-store.d.ts +22 -0
- package/dist/library/in-memory-library-store.d.ts.map +1 -0
- package/dist/library/in-memory-library-store.js +92 -0
- package/dist/library/index.d.ts +18 -0
- package/dist/library/index.d.ts.map +1 -0
- package/dist/library/index.js +33 -0
- package/dist/library/library-hash.d.ts +9 -0
- package/dist/library/library-hash.d.ts.map +1 -0
- package/dist/library/library-hash.js +14 -0
- package/dist/library/library-models.d.ts +134 -0
- package/dist/library/library-models.d.ts.map +1 -0
- package/dist/library/library-models.js +84 -0
- package/dist/library/library-proof.d.ts +40 -0
- package/dist/library/library-proof.d.ts.map +1 -0
- package/dist/library/library-proof.js +44 -0
- package/dist/library/library-reference.d.ts +75 -0
- package/dist/library/library-reference.d.ts.map +1 -0
- package/dist/library/library-reference.js +98 -0
- package/dist/library/library-server.d.ts +17 -0
- package/dist/library/library-server.d.ts.map +1 -0
- package/dist/library/library-server.js +45 -0
- package/dist/library/library-store.d.ts +37 -0
- package/dist/library/library-store.d.ts.map +1 -0
- package/dist/library/library-store.js +2 -0
- package/dist/library/remote-library-models.d.ts +54 -0
- package/dist/library/remote-library-models.d.ts.map +1 -0
- package/dist/library/remote-library-models.js +2 -0
- package/dist/library/remote-library-store.d.ts +15 -0
- package/dist/library/remote-library-store.d.ts.map +1 -0
- package/dist/library/remote-library-store.js +59 -0
- package/dist/library/verify-library.d.ts +21 -0
- package/dist/library/verify-library.d.ts.map +1 -0
- package/dist/library/verify-library.js +86 -0
- package/dist/models/functions/share-data-function-models.d.ts +6 -74
- package/dist/models/functions/share-data-function-models.d.ts.map +1 -1
- package/dist/models/functions/share-data-function-models.js +7 -65
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +1 -0
- package/dist/models/safe/transactions/sharedata-transactions-models.d.ts +5 -0
- package/dist/models/safe/transactions/sharedata-transactions-models.d.ts.map +1 -1
- package/dist/models/settlement/settlement-models.d.ts +221 -0
- package/dist/models/settlement/settlement-models.d.ts.map +1 -0
- package/dist/models/settlement/settlement-models.js +152 -0
- package/dist/models/share-data/share-data-models.d.ts +12 -0
- package/dist/models/share-data/share-data-models.d.ts.map +1 -1
- package/dist/models/share-data/share-data-persistence-models.d.ts +3 -0
- package/dist/models/share-data/share-data-persistence-models.d.ts.map +1 -1
- package/dist/models/shareblock/shareblock-models.d.ts +179 -3
- package/dist/models/shareblock/shareblock-models.d.ts.map +1 -1
- package/dist/models/shareblock/shareblock-models.js +99 -7
- package/dist/sandbox/in-process-executor.d.ts +13 -0
- package/dist/sandbox/in-process-executor.d.ts.map +1 -0
- package/dist/sandbox/in-process-executor.js +31 -0
- package/dist/sandbox/index.d.ts +8 -0
- package/dist/sandbox/index.d.ts.map +1 -0
- package/dist/sandbox/index.js +23 -0
- package/dist/sandbox/remote-sandbox-executor.d.ts +12 -0
- package/dist/sandbox/remote-sandbox-executor.d.ts.map +1 -0
- package/dist/sandbox/remote-sandbox-executor.js +49 -0
- package/dist/sandbox/remote-sandbox-models.d.ts +37 -0
- package/dist/sandbox/remote-sandbox-models.d.ts.map +1 -0
- package/dist/sandbox/remote-sandbox-models.js +2 -0
- package/dist/sandbox/rule-evaluator.d.ts +32 -0
- package/dist/sandbox/rule-evaluator.d.ts.map +1 -0
- package/dist/sandbox/rule-evaluator.js +23 -0
- package/dist/sandbox/run-sandboxed.d.ts +24 -0
- package/dist/sandbox/run-sandboxed.d.ts.map +1 -0
- package/dist/sandbox/run-sandboxed.js +88 -0
- package/dist/sandbox/sandbox-models.d.ts +40 -0
- package/dist/sandbox/sandbox-models.d.ts.map +1 -0
- package/dist/sandbox/sandbox-models.js +2 -0
- package/dist/sandbox/sandbox-server.d.ts +22 -0
- package/dist/sandbox/sandbox-server.d.ts.map +1 -0
- package/dist/sandbox/sandbox-server.js +62 -0
- package/package.json +3 -4
- package/dist/crypto/private-public-keys/create-key-pair-from-mnemonic.d.ts +0 -12
- package/dist/crypto/private-public-keys/create-key-pair-from-mnemonic.d.ts.map +0 -1
- package/dist/crypto/private-public-keys/create-key-pair-from-mnemonic.js +0 -54
- package/dist/crypto/private-public-keys/create-key-pair-from-private-key.d.ts +0 -11
- package/dist/crypto/private-public-keys/create-key-pair-from-private-key.d.ts.map +0 -1
- package/dist/crypto/private-public-keys/create-key-pair-from-private-key.js +0 -50
- package/dist/crypto/private-public-keys/create-key-pair-from-public-key.d.ts +0 -11
- package/dist/crypto/private-public-keys/create-key-pair-from-public-key.d.ts.map +0 -1
- package/dist/crypto/private-public-keys/create-key-pair-from-public-key.js +0 -51
- package/dist/crypto/private-public-keys/generation/create-entropy-for-elliptical-curve.d.ts +0 -10
- package/dist/crypto/private-public-keys/generation/create-entropy-for-elliptical-curve.d.ts.map +0 -1
- package/dist/crypto/private-public-keys/generation/create-entropy-for-elliptical-curve.js +0 -51
- package/dist/crypto/private-public-keys/generation/generate-key-pair.d.ts +0 -11
- package/dist/crypto/private-public-keys/generation/generate-key-pair.d.ts.map +0 -1
- package/dist/crypto/private-public-keys/generation/generate-key-pair.js +0 -49
- package/dist/crypto/private-public-keys/generation/get-private-public-key-from-keypair.d.ts +0 -15
- package/dist/crypto/private-public-keys/generation/get-private-public-key-from-keypair.d.ts.map +0 -1
- package/dist/crypto/private-public-keys/generation/get-private-public-key-from-keypair.js +0 -21
- package/dist/crypto/signature/create-crypto-signature.d.ts +0 -20
- package/dist/crypto/signature/create-crypto-signature.d.ts.map +0 -1
- package/dist/crypto/signature/create-crypto-signature.js +0 -26
- package/dist/crypto/signature/verify-crypto-signature-by-data.d.ts +0 -17
- package/dist/crypto/signature/verify-crypto-signature-by-data.d.ts.map +0 -1
- package/dist/crypto/signature/verify-crypto-signature-by-data.js +0 -61
- package/dist/crypto/signature/verify-crypto-signature-by-hash.d.ts +0 -17
- package/dist/crypto/signature/verify-crypto-signature-by-hash.d.ts.map +0 -1
- package/dist/crypto/signature/verify-crypto-signature-by-hash.js +0 -58
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-sandbox-models.d.ts","sourceRoot":"","sources":["../../src/sandbox/remote-sandbox-models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACjC,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,UAAU,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,sDAAsD;AACtD,MAAM,WAAW,qBAAqB;IAClC,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,qBAAqB,CAAC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,gBAAgB;IAC7B,IAAI,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACvE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { IShareData } from '../models/share-data/share-data-models';
|
|
2
|
+
/**
|
|
3
|
+
* A request to evaluate a rule's `source` against a proposed transition. A
|
|
4
|
+
* library rule is a pure predicate `({ current, proposed }) => boolean`.
|
|
5
|
+
*/
|
|
6
|
+
export interface RuleEvaluationRequest {
|
|
7
|
+
source: string;
|
|
8
|
+
current: IShareData;
|
|
9
|
+
proposed: IShareData;
|
|
10
|
+
gasLimit: number;
|
|
11
|
+
}
|
|
12
|
+
export type RuleEvaluationFailure = 'gas-exceeded' | 'threw' | 'invalid-output';
|
|
13
|
+
export interface RuleEvaluationResult {
|
|
14
|
+
ok: boolean;
|
|
15
|
+
passed?: boolean;
|
|
16
|
+
failure?: RuleEvaluationFailure;
|
|
17
|
+
error?: string;
|
|
18
|
+
gasUsed: number;
|
|
19
|
+
executionTime: number;
|
|
20
|
+
}
|
|
21
|
+
/** Evaluates rule source out of the host call stack — the rule counterpart of {@link FunctionExecutor}. */
|
|
22
|
+
export interface RuleEvaluator {
|
|
23
|
+
evaluate(request: RuleEvaluationRequest): Promise<RuleEvaluationResult>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* In-process {@link RuleEvaluator} over the shared sandbox core. Runs
|
|
27
|
+
* `({ current, proposed }) => boolean`; a non-boolean return is rejected as
|
|
28
|
+
* `invalid-output`. Same gas + determinism guarantees (and same non-isolation
|
|
29
|
+
* caveat) as the in-process function executor.
|
|
30
|
+
*/
|
|
31
|
+
export declare const createInProcessRuleEvaluator: () => RuleEvaluator;
|
|
32
|
+
//# sourceMappingURL=rule-evaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-evaluator.d.ts","sourceRoot":"","sources":["../../src/sandbox/rule-evaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AAGpE;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,UAAU,CAAC;IACpB,QAAQ,EAAE,UAAU,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,qBAAqB,GAAG,cAAc,GAAG,OAAO,GAAG,gBAAgB,CAAC;AAEhF,MAAM,WAAW,oBAAoB;IACjC,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,qBAAqB,CAAC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACzB;AAED,2GAA2G;AAC3G,MAAM,WAAW,aAAa;IAC1B,QAAQ,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;CAC3E;AAED;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,QAAO,aAe9C,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createInProcessRuleEvaluator = void 0;
|
|
4
|
+
const run_sandboxed_1 = require("./run-sandboxed");
|
|
5
|
+
/**
|
|
6
|
+
* In-process {@link RuleEvaluator} over the shared sandbox core. Runs
|
|
7
|
+
* `({ current, proposed }) => boolean`; a non-boolean return is rejected as
|
|
8
|
+
* `invalid-output`. Same gas + determinism guarantees (and same non-isolation
|
|
9
|
+
* caveat) as the in-process function executor.
|
|
10
|
+
*/
|
|
11
|
+
const createInProcessRuleEvaluator = () => ({
|
|
12
|
+
async evaluate(request) {
|
|
13
|
+
const run = (0, run_sandboxed_1.runSandboxed)(request.source, { current: request.current, proposed: request.proposed }, request.gasLimit);
|
|
14
|
+
if (!run.ok) {
|
|
15
|
+
return { ok: false, failure: run.failure, error: run.error, gasUsed: run.gasUsed, executionTime: run.executionTime };
|
|
16
|
+
}
|
|
17
|
+
if (typeof run.value !== 'boolean') {
|
|
18
|
+
return { ok: false, failure: 'invalid-output', gasUsed: run.gasUsed, executionTime: run.executionTime };
|
|
19
|
+
}
|
|
20
|
+
return { ok: true, passed: run.value, gasUsed: run.gasUsed, executionTime: run.executionTime };
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
exports.createInProcessRuleEvaluator = createInProcessRuleEvaluator;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Raw outcome of running source in the sandbox, before any output typing. */
|
|
2
|
+
export interface SandboxRunResult {
|
|
3
|
+
ok: boolean;
|
|
4
|
+
value?: unknown;
|
|
5
|
+
failure?: 'gas-exceeded' | 'threw';
|
|
6
|
+
error?: string;
|
|
7
|
+
gasUsed: number;
|
|
8
|
+
executionTime: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The shared sandbox primitive: runs `(source)(arg)` in a deterministic,
|
|
12
|
+
* gas-bounded `vm` context and returns the raw return value. Output typing
|
|
13
|
+
* (must-be-a-state-object for functions, must-be-a-boolean for rules) is left to
|
|
14
|
+
* the caller.
|
|
15
|
+
*
|
|
16
|
+
* NOT a security sandbox — `vm` shares the heap. It enforces the gas ceiling
|
|
17
|
+
* (`gasLimit * 100ms`, terminating runaway synchronous code) and determinism
|
|
18
|
+
* (`Date` / `Math.random` neutralised; Node globals are absent). Source must be
|
|
19
|
+
* a pure synchronous `(arg) => result`.
|
|
20
|
+
*/
|
|
21
|
+
export declare const runSandboxed: (source: string, arg: unknown, gasLimit: number) => SandboxRunResult;
|
|
22
|
+
export declare const clone: <T>(value: T) => T;
|
|
23
|
+
export declare const gasFrom: (executionTime: number) => number;
|
|
24
|
+
//# sourceMappingURL=run-sandboxed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-sandboxed.d.ts","sourceRoot":"","sources":["../../src/sandbox/run-sandboxed.ts"],"names":[],"mappings":"AAGA,8EAA8E;AAC9E,MAAM,WAAW,gBAAgB;IAC7B,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACzB;AAQD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,EAAE,KAAK,OAAO,EAAE,UAAU,MAAM,KAAG,gBAmB7E,CAAC;AAEF,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,CAAsC,CAAC;AAE3E,eAAO,MAAM,OAAO,GAAI,eAAe,MAAM,KAAG,MAA6D,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.gasFrom = exports.clone = exports.runSandboxed = void 0;
|
|
37
|
+
const vm = __importStar(require("vm"));
|
|
38
|
+
const library_models_1 = require("../library/library-models");
|
|
39
|
+
// Runs inside the context (where the intrinsics live) to remove the
|
|
40
|
+
// non-deterministic ones. `globalThis` resolves to the context's global, so
|
|
41
|
+
// these assignments definitely take effect (unlike pre-seeding the sandbox,
|
|
42
|
+
// which the intrinsics may shadow).
|
|
43
|
+
const DETERMINISM_PRELUDE = 'globalThis.Date=undefined;globalThis.Math.random=undefined;';
|
|
44
|
+
/**
|
|
45
|
+
* The shared sandbox primitive: runs `(source)(arg)` in a deterministic,
|
|
46
|
+
* gas-bounded `vm` context and returns the raw return value. Output typing
|
|
47
|
+
* (must-be-a-state-object for functions, must-be-a-boolean for rules) is left to
|
|
48
|
+
* the caller.
|
|
49
|
+
*
|
|
50
|
+
* NOT a security sandbox — `vm` shares the heap. It enforces the gas ceiling
|
|
51
|
+
* (`gasLimit * 100ms`, terminating runaway synchronous code) and determinism
|
|
52
|
+
* (`Date` / `Math.random` neutralised; Node globals are absent). Source must be
|
|
53
|
+
* a pure synchronous `(arg) => result`.
|
|
54
|
+
*/
|
|
55
|
+
const runSandboxed = (source, arg, gasLimit) => {
|
|
56
|
+
const timeoutMs = gasLimit * library_models_1.GAS_UNIT_MS;
|
|
57
|
+
// Deep-clone the arg into the context so the function cannot mutate the
|
|
58
|
+
// caller's objects, and so nothing leaks in by reference.
|
|
59
|
+
const context = vm.createContext({ __arg: arg === undefined ? undefined : (0, exports.clone)(arg) });
|
|
60
|
+
const code = `${DETERMINISM_PRELUDE}(${source})(__arg)`;
|
|
61
|
+
const startedAt = Date.now();
|
|
62
|
+
try {
|
|
63
|
+
const value = vm.runInContext(code, context, { timeout: timeoutMs });
|
|
64
|
+
const executionTime = Date.now() - startedAt;
|
|
65
|
+
return { ok: true, value, gasUsed: (0, exports.gasFrom)(executionTime), executionTime };
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
const executionTime = Date.now() - startedAt;
|
|
69
|
+
if (isTimeout(err)) {
|
|
70
|
+
return { ok: false, failure: 'gas-exceeded', gasUsed: gasLimit, executionTime };
|
|
71
|
+
}
|
|
72
|
+
return { ok: false, failure: 'threw', error: messageOf(err), gasUsed: (0, exports.gasFrom)(executionTime), executionTime };
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
exports.runSandboxed = runSandboxed;
|
|
76
|
+
const clone = (value) => JSON.parse(JSON.stringify(value));
|
|
77
|
+
exports.clone = clone;
|
|
78
|
+
const gasFrom = (executionTime) => Math.max(1, Math.ceil(executionTime / library_models_1.GAS_UNIT_MS));
|
|
79
|
+
exports.gasFrom = gasFrom;
|
|
80
|
+
const isTimeout = (err) => {
|
|
81
|
+
if (typeof err !== 'object' || err === null) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
const code = err.code;
|
|
85
|
+
const message = String(err.message ?? '');
|
|
86
|
+
return code === 'ERR_SCRIPT_EXECUTION_TIMEOUT' || /timed out/i.test(message);
|
|
87
|
+
};
|
|
88
|
+
const messageOf = (err) => (err instanceof Error ? err.message : String(err));
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { IShareData } from '../models/share-data/share-data-models';
|
|
2
|
+
/**
|
|
3
|
+
* A request to execute a stored function's `source` against `current` state and
|
|
4
|
+
* an `input`, bounded by `gasLimit`. See `plans/FUNCTION_LEDGER_PLAN.html` and
|
|
5
|
+
* `documentation/functions/functions.md`.
|
|
6
|
+
*/
|
|
7
|
+
export interface FunctionExecutionRequest {
|
|
8
|
+
/** Stringified function source — a pure `({ current, input }) => state`. */
|
|
9
|
+
source: string;
|
|
10
|
+
current: IShareData;
|
|
11
|
+
input: unknown;
|
|
12
|
+
/** Gas units (100ms each). The hard wall-clock ceiling is gasLimit * 100ms. */
|
|
13
|
+
gasLimit: number;
|
|
14
|
+
}
|
|
15
|
+
/** Why an execution did not produce a usable proposed state. */
|
|
16
|
+
export type FunctionExecutionFailure = 'gas-exceeded' | 'threw' | 'invalid-output';
|
|
17
|
+
/**
|
|
18
|
+
* The outcome of an execution. `ok` is true only when a plain proposed-state
|
|
19
|
+
* object was produced; otherwise `failure` says why. `gasUsed` and
|
|
20
|
+
* `executionTime` are always reported so a verifier can reproduce with an
|
|
21
|
+
* adequate budget.
|
|
22
|
+
*/
|
|
23
|
+
export interface FunctionExecutionResult {
|
|
24
|
+
ok: boolean;
|
|
25
|
+
output?: IShareData;
|
|
26
|
+
failure?: FunctionExecutionFailure;
|
|
27
|
+
error?: string;
|
|
28
|
+
gasUsed: number;
|
|
29
|
+
executionTime: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Executes stored function source out of the host call stack. Pluggable: an
|
|
33
|
+
* in-process implementation for trusted standard functions and tests, and a
|
|
34
|
+
* remote-sandbox implementation for untrusted library source. `execute` is
|
|
35
|
+
* async so both implementations share one interface.
|
|
36
|
+
*/
|
|
37
|
+
export interface FunctionExecutor {
|
|
38
|
+
execute(request: FunctionExecutionRequest): Promise<FunctionExecutionResult>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=sandbox-models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-models.d.ts","sourceRoot":"","sources":["../../src/sandbox/sandbox-models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AAEpE;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACrC,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,UAAU,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;IACf,+EAA+E;IAC/E,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,gEAAgE;AAChE,MAAM,MAAM,wBAAwB,GAC9B,cAAc,GACd,OAAO,GACP,gBAAgB,CAAC;AAEvB;;;;;GAKG;AACH,MAAM,WAAW,uBAAuB;IACpC,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,OAAO,CAAC,EAAE,wBAAwB,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC7B,OAAO,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;CAChF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RemoteSandboxRequest, RemoteSandboxResponse } from './remote-sandbox-models';
|
|
2
|
+
export interface SandboxServerOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The hard ceiling on gas the server will honour, regardless of what the
|
|
5
|
+
* client requests. Defaults to (and is itself capped at) {@link MAX_GAS_UNITS}.
|
|
6
|
+
*/
|
|
7
|
+
maxGasUnits?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface SandboxServer {
|
|
10
|
+
handle(request: RemoteSandboxRequest): Promise<RemoteSandboxResponse>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The transport-agnostic sandbox server: it receives a {@link RemoteSandboxRequest},
|
|
14
|
+
* runs it through the in-process executor/evaluator, and returns a
|
|
15
|
+
* {@link RemoteSandboxResponse}. The CONSUMER wires this handler to their HTTP
|
|
16
|
+
* server (an Express route, etc.) — the server itself takes no transport dep.
|
|
17
|
+
*
|
|
18
|
+
* The server is the authority on gas: it clamps the requested `gasLimit` to its
|
|
19
|
+
* own cap, so a client cannot ask for more than the server permits.
|
|
20
|
+
*/
|
|
21
|
+
export declare const createSandboxServer: (options?: SandboxServerOptions) => SandboxServer;
|
|
22
|
+
//# sourceMappingURL=sandbox-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-server.d.ts","sourceRoot":"","sources":["../../src/sandbox/sandbox-server.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAGtF,MAAM,WAAW,oBAAoB;IACjC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,aAAa;IAC1B,MAAM,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACzE;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,GAAI,UAAS,oBAAyB,KAAG,aA0CxE,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSandboxServer = void 0;
|
|
4
|
+
const library_models_1 = require("../library/library-models");
|
|
5
|
+
const in_process_executor_1 = require("./in-process-executor");
|
|
6
|
+
const rule_evaluator_1 = require("./rule-evaluator");
|
|
7
|
+
/**
|
|
8
|
+
* The transport-agnostic sandbox server: it receives a {@link RemoteSandboxRequest},
|
|
9
|
+
* runs it through the in-process executor/evaluator, and returns a
|
|
10
|
+
* {@link RemoteSandboxResponse}. The CONSUMER wires this handler to their HTTP
|
|
11
|
+
* server (an Express route, etc.) — the server itself takes no transport dep.
|
|
12
|
+
*
|
|
13
|
+
* The server is the authority on gas: it clamps the requested `gasLimit` to its
|
|
14
|
+
* own cap, so a client cannot ask for more than the server permits.
|
|
15
|
+
*/
|
|
16
|
+
const createSandboxServer = (options = {}) => {
|
|
17
|
+
const cap = Math.min(options.maxGasUnits ?? library_models_1.MAX_GAS_UNITS, library_models_1.MAX_GAS_UNITS);
|
|
18
|
+
const functionExecutor = (0, in_process_executor_1.createInProcessFunctionExecutor)();
|
|
19
|
+
const ruleEvaluator = (0, rule_evaluator_1.createInProcessRuleEvaluator)();
|
|
20
|
+
return {
|
|
21
|
+
async handle(request) {
|
|
22
|
+
const gasLimit = clampGas(request.gasLimit, cap);
|
|
23
|
+
if (request.kind === 'rule') {
|
|
24
|
+
const result = await ruleEvaluator.evaluate({
|
|
25
|
+
source: request.source,
|
|
26
|
+
current: request.current,
|
|
27
|
+
proposed: (request.proposed ?? {}),
|
|
28
|
+
gasLimit,
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
ok: result.ok,
|
|
32
|
+
passed: result.passed,
|
|
33
|
+
failure: result.failure,
|
|
34
|
+
error: result.error,
|
|
35
|
+
gasUsed: result.gasUsed,
|
|
36
|
+
executionTime: result.executionTime,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const result = await functionExecutor.execute({
|
|
40
|
+
source: request.source,
|
|
41
|
+
current: request.current,
|
|
42
|
+
input: request.input,
|
|
43
|
+
gasLimit,
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
ok: result.ok,
|
|
47
|
+
output: result.output,
|
|
48
|
+
failure: result.failure,
|
|
49
|
+
error: result.error,
|
|
50
|
+
gasUsed: result.gasUsed,
|
|
51
|
+
executionTime: result.executionTime,
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
exports.createSandboxServer = createSandboxServer;
|
|
57
|
+
const clampGas = (requested, cap) => {
|
|
58
|
+
if (!Number.isFinite(requested) || requested < 1) {
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
return Math.min(Math.floor(requested), cap);
|
|
62
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@degenerate/generic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "This contains the generic information needed for the ShareData Adaptive Framework Ecosystem (SAFE) network",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -38,14 +38,13 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://github.com/syncrude/safe#readme",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@
|
|
41
|
+
"@noble/ed25519": "3.1.0",
|
|
42
42
|
"bip39": "^3.1.0",
|
|
43
|
-
"elliptic": "^6.6.1",
|
|
44
43
|
"firebase-admin": "^13.9.0",
|
|
45
44
|
"jsonwebtoken": "^9.0.3",
|
|
46
45
|
"zod": "^4.4.3"
|
|
47
46
|
},
|
|
48
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "1f747e160c9022863c7b2d7b8a6a157f204be95b",
|
|
49
48
|
"devDependencies": {
|
|
50
49
|
"@eslint/js": "^10.0.1",
|
|
51
50
|
"@types/eslint__js": "^8.42.3",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as Elliptic from 'elliptic';
|
|
2
|
-
import { EllipticalCurvesSigning, EllipticalCurvesEncryption } from '../../_settings/cryptography-settings';
|
|
3
|
-
/**
|
|
4
|
-
* This function creates a key pair from a mnemonic using the elliptic library.
|
|
5
|
-
*
|
|
6
|
-
* @param curve the elliptical curve to create the key pair for.
|
|
7
|
-
* @param mnemonic the mnemonic to create the key pair from.
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
declare const createKeyPairFromMnemonic: (curve: EllipticalCurvesSigning | EllipticalCurvesEncryption, mnemonic: string) => Elliptic.ec.KeyPair;
|
|
11
|
-
export { createKeyPairFromMnemonic };
|
|
12
|
-
//# sourceMappingURL=create-key-pair-from-mnemonic.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-key-pair-from-mnemonic.d.ts","sourceRoot":"","sources":["../../../src/crypto/private-public-keys/create-key-pair-from-mnemonic.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAErC,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAkB,MAAM,uCAAuC,CAAC;AAE5H;;;;;;GAMG;AACH,QAAA,MAAM,yBAAyB,GAAI,OAAO,uBAAuB,GAAG,0BAA0B,EAAE,UAAU,MAAM,KAAG,QAAQ,CAAC,EAAE,CAAC,OAO9H,CAAC;AAEF,OAAO,EAAE,yBAAyB,EAAE,CAAC"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.createKeyPairFromMnemonic = void 0;
|
|
37
|
-
/* eslint-disable new-cap */
|
|
38
|
-
const Elliptic = __importStar(require("elliptic"));
|
|
39
|
-
const crypto = __importStar(require("crypto"));
|
|
40
|
-
const cryptography_settings_1 = require("../../_settings/cryptography-settings");
|
|
41
|
-
/**
|
|
42
|
-
* This function creates a key pair from a mnemonic using the elliptic library.
|
|
43
|
-
*
|
|
44
|
-
* @param curve the elliptical curve to create the key pair for.
|
|
45
|
-
* @param mnemonic the mnemonic to create the key pair from.
|
|
46
|
-
* @returns
|
|
47
|
-
*/
|
|
48
|
-
const createKeyPairFromMnemonic = (curve, mnemonic) => {
|
|
49
|
-
const ellipticalCurve = new Elliptic.ec(curve);
|
|
50
|
-
const hash = crypto.createHash(cryptography_settings_1.CryptoSettings.Hash.Algorithm).update(mnemonic, cryptography_settings_1.CryptoSettings.TextEncoding).digest(cryptography_settings_1.CryptoSettings.Hash.Digest);
|
|
51
|
-
const keyPair = ellipticalCurve.keyFromPrivate(hash);
|
|
52
|
-
return keyPair;
|
|
53
|
-
};
|
|
54
|
-
exports.createKeyPairFromMnemonic = createKeyPairFromMnemonic;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as Elliptic from 'elliptic';
|
|
2
|
-
import { EllipticalCurvesSigning, EllipticalCurvesEncryption } from '../../_settings/cryptography-settings';
|
|
3
|
-
/**
|
|
4
|
-
* This function creates a key pair from a private key using the elliptic library.
|
|
5
|
-
* @param curve the elliptical curve to create the key pair for.
|
|
6
|
-
* @param privateKey the private key in hexadecimal format.
|
|
7
|
-
* @returns
|
|
8
|
-
*/
|
|
9
|
-
declare const createKeyPairFromPrivateKey: (curve: EllipticalCurvesSigning | EllipticalCurvesEncryption, privateKey: string) => Elliptic.ec.KeyPair;
|
|
10
|
-
export { createKeyPairFromPrivateKey };
|
|
11
|
-
//# sourceMappingURL=create-key-pair-from-private-key.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-key-pair-from-private-key.d.ts","sourceRoot":"","sources":["../../../src/crypto/private-public-keys/create-key-pair-from-private-key.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AAE5G;;;;;GAKG;AACH,QAAA,MAAM,2BAA2B,GAAI,OAAO,uBAAuB,GAAG,0BAA0B,EAC5F,YAAY,MAAM,KAAG,QAAQ,CAAC,EAAE,CAAC,OAKpC,CAAC;AAEF,OAAO,EAAE,2BAA2B,EAAE,CAAC"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.createKeyPairFromPrivateKey = void 0;
|
|
37
|
-
/* eslint-disable new-cap */
|
|
38
|
-
const Elliptic = __importStar(require("elliptic"));
|
|
39
|
-
/**
|
|
40
|
-
* This function creates a key pair from a private key using the elliptic library.
|
|
41
|
-
* @param curve the elliptical curve to create the key pair for.
|
|
42
|
-
* @param privateKey the private key in hexadecimal format.
|
|
43
|
-
* @returns
|
|
44
|
-
*/
|
|
45
|
-
const createKeyPairFromPrivateKey = (curve, privateKey) => {
|
|
46
|
-
const ellipticalCurve = new Elliptic.ec(curve);
|
|
47
|
-
const keyPair = ellipticalCurve.keyFromPrivate(privateKey, 'hex');
|
|
48
|
-
return keyPair;
|
|
49
|
-
};
|
|
50
|
-
exports.createKeyPairFromPrivateKey = createKeyPairFromPrivateKey;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as Elliptic from 'elliptic';
|
|
2
|
-
import { EllipticalCurvesEncryption, EllipticalCurvesSigning } from '../../_settings/cryptography-settings';
|
|
3
|
-
/**
|
|
4
|
-
* This function creates a key pair from a public key using the elliptic library.
|
|
5
|
-
*
|
|
6
|
-
* @param curve the elliptical curve to create the key pair for.
|
|
7
|
-
* @param publicKey the public key in hexadecimal format.
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
export declare const createKeyPairFromPublicKey: (curve: EllipticalCurvesSigning | EllipticalCurvesEncryption, publicKey: string, encoding?: BufferEncoding) => Elliptic.ec.KeyPair;
|
|
11
|
-
//# sourceMappingURL=create-key-pair-from-public-key.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-key-pair-from-public-key.d.ts","sourceRoot":"","sources":["../../../src/crypto/private-public-keys/create-key-pair-from-public-key.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAE5G;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GACnC,OAAO,uBAAuB,GAAG,0BAA0B,EAC3D,WAAW,MAAM,EACjB,WAAU,cAAsB,KACjC,QAAQ,CAAC,EAAE,CAAC,OAKd,CAAC"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.createKeyPairFromPublicKey = void 0;
|
|
37
|
-
/* eslint-disable new-cap */
|
|
38
|
-
const Elliptic = __importStar(require("elliptic"));
|
|
39
|
-
/**
|
|
40
|
-
* This function creates a key pair from a public key using the elliptic library.
|
|
41
|
-
*
|
|
42
|
-
* @param curve the elliptical curve to create the key pair for.
|
|
43
|
-
* @param publicKey the public key in hexadecimal format.
|
|
44
|
-
* @returns
|
|
45
|
-
*/
|
|
46
|
-
const createKeyPairFromPublicKey = (curve, publicKey, encoding = 'hex') => {
|
|
47
|
-
const ellipticalCurve = new Elliptic.ec(curve);
|
|
48
|
-
const keyPair = ellipticalCurve.keyFromPublic(publicKey, encoding);
|
|
49
|
-
return keyPair;
|
|
50
|
-
};
|
|
51
|
-
exports.createKeyPairFromPublicKey = createKeyPairFromPublicKey;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { EllipticalCurvesEncryption, EllipticalCurvesSigning } from '../../../_settings/cryptography-settings';
|
|
2
|
-
/**
|
|
3
|
-
* Creates entropy for an elliptical curve.
|
|
4
|
-
*
|
|
5
|
-
* @param signingCurve - The elliptical curve to create entropy for.
|
|
6
|
-
* @returns The entropy for the elliptical curve. string in hexadecimal format.
|
|
7
|
-
*/
|
|
8
|
-
declare const createEntropyForEllipitalCurve: (curve: EllipticalCurvesSigning | EllipticalCurvesEncryption) => string;
|
|
9
|
-
export { createEntropyForEllipitalCurve };
|
|
10
|
-
//# sourceMappingURL=create-entropy-for-elliptical-curve.d.ts.map
|
package/dist/crypto/private-public-keys/generation/create-entropy-for-elliptical-curve.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-entropy-for-elliptical-curve.d.ts","sourceRoot":"","sources":["../../../../src/crypto/private-public-keys/generation/create-entropy-for-elliptical-curve.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AAG/G;;;;;GAKG;AACH,QAAA,MAAM,8BAA8B,GAAI,OAAO,uBAAuB,GAAG,0BAA0B,KAAG,MAQrG,CAAC;AAEF,OAAO,EAAE,8BAA8B,EAAE,CAAC"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.createEntropyForEllipitalCurve = void 0;
|
|
37
|
-
const Elliptic = __importStar(require("elliptic"));
|
|
38
|
-
/**
|
|
39
|
-
* Creates entropy for an elliptical curve.
|
|
40
|
-
*
|
|
41
|
-
* @param signingCurve - The elliptical curve to create entropy for.
|
|
42
|
-
* @returns The entropy for the elliptical curve. string in hexadecimal format.
|
|
43
|
-
*/
|
|
44
|
-
const createEntropyForEllipitalCurve = (curve) => {
|
|
45
|
-
const ecKey = new Elliptic.ec(curve);
|
|
46
|
-
const hashStrength = ecKey.hash.hmacStrength;
|
|
47
|
-
const entropy = Elliptic.rand(hashStrength);
|
|
48
|
-
const entropyHex = entropy.toString('hex');
|
|
49
|
-
return entropyHex;
|
|
50
|
-
};
|
|
51
|
-
exports.createEntropyForEllipitalCurve = createEntropyForEllipitalCurve;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { EllipticalCurvesSigning, EllipticalCurvesEncryption } from '../../../_settings/cryptography-settings';
|
|
2
|
-
import * as Elliptic from 'elliptic';
|
|
3
|
-
/**
|
|
4
|
-
* This function generates a key pair from a private key and entropy using the elliptic library.
|
|
5
|
-
*
|
|
6
|
-
* @param privateKey the private key in hexadecimal format
|
|
7
|
-
* @param entropy the entropy in hexadecimal format
|
|
8
|
-
*/
|
|
9
|
-
declare const generateKeyPair: (curve: EllipticalCurvesSigning | EllipticalCurvesEncryption, privateKey: string, entropy: string) => Elliptic.ec.KeyPair;
|
|
10
|
-
export { generateKeyPair };
|
|
11
|
-
//# sourceMappingURL=generate-key-pair.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-key-pair.d.ts","sourceRoot":"","sources":["../../../../src/crypto/private-public-keys/generation/generate-key-pair.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAC;AAC/G,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAErC;;;;;GAKG;AACH,QAAA,MAAM,eAAe,GAAI,OAAO,uBAAuB,GAAG,0BAA0B,EAAE,YAAY,MAAM,EACpG,SAAS,MAAM,KAAG,QAAQ,CAAC,EAAE,CAAC,OAMjC,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,CAAC"}
|