@degenerate/sharedata 0.2.6 → 0.3.1
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/README.md +31 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -0
- package/dist/manager/share-data-manager-events.d.ts +27 -0
- package/dist/manager/share-data-manager-events.d.ts.map +1 -0
- package/dist/manager/share-data-manager-events.js +2 -0
- package/dist/manager/share-data-manager.d.ts +84 -0
- package/dist/manager/share-data-manager.d.ts.map +1 -0
- package/dist/manager/share-data-manager.js +210 -0
- package/dist/persistence/block-factory-registry.d.ts +51 -0
- package/dist/persistence/block-factory-registry.d.ts.map +1 -0
- package/dist/persistence/block-factory-registry.js +36 -0
- package/dist/persistence/deserialize-share-data.d.ts +18 -0
- package/dist/persistence/deserialize-share-data.d.ts.map +1 -0
- package/dist/persistence/deserialize-share-data.js +144 -0
- package/dist/persistence/file-share-data-repository.d.ts +30 -0
- package/dist/persistence/file-share-data-repository.d.ts.map +1 -0
- package/dist/persistence/file-share-data-repository.js +147 -0
- package/dist/persistence/firestore-share-data-repository.d.ts +38 -0
- package/dist/persistence/firestore-share-data-repository.d.ts.map +1 -0
- package/dist/persistence/firestore-share-data-repository.js +78 -0
- package/dist/persistence/in-memory-share-data-repository.d.ts +19 -0
- package/dist/persistence/in-memory-share-data-repository.d.ts.map +1 -0
- package/dist/persistence/in-memory-share-data-repository.js +48 -0
- package/dist/persistence/serialize-share-data.d.ts +22 -0
- package/dist/persistence/serialize-share-data.d.ts.map +1 -0
- package/dist/persistence/serialize-share-data.js +62 -0
- package/dist/persistence/share-data-repository.d.ts +49 -0
- package/dist/persistence/share-data-repository.d.ts.map +1 -0
- package/dist/persistence/share-data-repository.js +2 -0
- package/dist/share-data/creation/create-share-data-initial-crypto.d.ts +11 -0
- package/dist/share-data/creation/create-share-data-initial-crypto.d.ts.map +1 -0
- package/dist/share-data/creation/create-share-data-initial-crypto.js +26 -0
- package/dist/share-data/helpers/calculate-share-data-string.d.ts +21 -0
- package/dist/share-data/helpers/calculate-share-data-string.d.ts.map +1 -0
- package/dist/share-data/helpers/calculate-share-data-string.js +71 -0
- package/dist/share-data/helpers/config/default-share-data-string.config.d.ts +7 -0
- package/dist/share-data/helpers/config/default-share-data-string.config.d.ts.map +1 -0
- package/dist/share-data/helpers/config/default-share-data-string.config.js +25 -0
- package/dist/share-data/helpers/config/stringify.d.ts +5 -0
- package/dist/share-data/helpers/config/stringify.d.ts.map +1 -0
- package/dist/share-data/helpers/config/stringify.js +10 -0
- package/dist/share-data/helpers/get-array-string.d.ts +6 -0
- package/dist/share-data/helpers/get-array-string.d.ts.map +1 -0
- package/dist/share-data/helpers/get-array-string.js +17 -0
- package/dist/share-data/proofs/creation/build-transaction-proposal-signer.d.ts +57 -0
- package/dist/share-data/proofs/creation/build-transaction-proposal-signer.d.ts.map +1 -0
- package/dist/share-data/proofs/creation/build-transaction-proposal-signer.js +36 -0
- package/dist/share-data/proofs/creation/create-share-data-proposal-proof.d.ts +12 -0
- package/dist/share-data/proofs/creation/create-share-data-proposal-proof.d.ts.map +1 -0
- package/dist/share-data/proofs/creation/create-share-data-proposal-proof.js +41 -0
- package/dist/share-data/proofs/creation/create-transaction-proposal-proof.d.ts +27 -0
- package/dist/share-data/proofs/creation/create-transaction-proposal-proof.d.ts.map +1 -0
- package/dist/share-data/proofs/creation/create-transaction-proposal-proof.js +58 -0
- package/dist/share-data/proofs/helpers/create-share-data-string-to-sign.d.ts +12 -0
- package/dist/share-data/proofs/helpers/create-share-data-string-to-sign.d.ts.map +1 -0
- package/dist/share-data/proofs/helpers/create-share-data-string-to-sign.js +17 -0
- package/dist/share-data/proofs/helpers/create-transaction-proposal-string-to-sign.d.ts +24 -0
- package/dist/share-data/proofs/helpers/create-transaction-proposal-string-to-sign.d.ts.map +1 -0
- package/dist/share-data/proofs/helpers/create-transaction-proposal-string-to-sign.js +29 -0
- package/dist/share-data/proofs/helpers/get-previous-hash-from-share-data.d.ts +9 -0
- package/dist/share-data/proofs/helpers/get-previous-hash-from-share-data.d.ts.map +1 -0
- package/dist/share-data/proofs/helpers/get-previous-hash-from-share-data.js +28 -0
- package/dist/share-data/proofs/helpers/hash-proposed-state.d.ts +12 -0
- package/dist/share-data/proofs/helpers/hash-proposed-state.d.ts.map +1 -0
- package/dist/share-data/proofs/helpers/hash-proposed-state.js +18 -0
- package/dist/share-data/proofs/testing/test-proof-signer.d.ts +53 -0
- package/dist/share-data/proofs/testing/test-proof-signer.d.ts.map +1 -0
- package/dist/share-data/proofs/testing/test-proof-signer.js +113 -0
- package/dist/share-data/proofs/verification/verify-share-data-proposal-proof.d.ts +40 -0
- package/dist/share-data/proofs/verification/verify-share-data-proposal-proof.d.ts.map +1 -0
- package/dist/share-data/proofs/verification/verify-share-data-proposal-proof.js +126 -0
- package/dist/share-data/proofs/verification/verify-transaction-proposal-proof.d.ts +37 -0
- package/dist/share-data/proofs/verification/verify-transaction-proposal-proof.d.ts.map +1 -0
- package/dist/share-data/proofs/verification/verify-transaction-proposal-proof.js +125 -0
- package/dist/share-data/share-data.d.ts +180 -27
- package/dist/share-data/share-data.d.ts.map +1 -1
- package/dist/share-data/share-data.js +303 -60
- package/package.json +33 -12
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"share-data-repository.d.ts","sourceRoot":"","sources":["../../src/persistence/share-data-repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AASrD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,mBAAmB;IAChC,6EAA6E;IAC7E,IAAI,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAElD;;;;OAIG;IACH,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;IAEjD;;;;OAIG;IACH,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IAEhC;;;;;;;;OAQG;IACH,gBAAgB,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAElD,wEAAwE;IACxE,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EllipticalCurvesSigning, IShareDataInitialCryptoData } from '@degenerate/generic';
|
|
2
|
+
import { ShareData } from '../share-data';
|
|
3
|
+
/**
|
|
4
|
+
* This function creates the initial crypto data for the share data.
|
|
5
|
+
*
|
|
6
|
+
* @param constructedShareData
|
|
7
|
+
*/
|
|
8
|
+
export declare const createShareDataInitialCrypto: (privateKey: string, // the private key in hex format
|
|
9
|
+
shareData: ShareData, // the share data to create the initial crypto for
|
|
10
|
+
signingCurve?: EllipticalCurvesSigning) => IShareDataInitialCryptoData;
|
|
11
|
+
//# sourceMappingURL=create-share-data-initial-crypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-share-data-initial-crypto.d.ts","sourceRoot":"","sources":["../../../src/share-data/creation/create-share-data-initial-crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,uBAAuB,EACvB,2BAA2B,EAC9B,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG1C;;;;GAIG;AACH,eAAO,MAAM,4BAA4B,GACrC,YAAY,MAAM,EAAE,gCAAgC;AACpD,WAAW,SAAS,EAAE,kDAAkD;AACxE,eAAc,uBAA4D,KAC3E,2BAYF,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createShareDataInitialCrypto = void 0;
|
|
4
|
+
const generic_1 = require("@degenerate/generic");
|
|
5
|
+
const calculate_share_data_string_1 = require("../helpers/calculate-share-data-string");
|
|
6
|
+
/**
|
|
7
|
+
* This function creates the initial crypto data for the share data.
|
|
8
|
+
*
|
|
9
|
+
* @param constructedShareData
|
|
10
|
+
*/
|
|
11
|
+
const createShareDataInitialCrypto = (privateKey, // the private key in hex format
|
|
12
|
+
shareData, // the share data to create the initial crypto for
|
|
13
|
+
signingCurve = generic_1.EllipticalCurvesSigning.Curve25519) => {
|
|
14
|
+
const keyPair = (0, generic_1.createKeyPairFromPrivateKey)(signingCurve, privateKey);
|
|
15
|
+
const shareDataString = (0, calculate_share_data_string_1.calculateShareDataString)(shareData);
|
|
16
|
+
const shareDataHash = (0, generic_1.calculateHash)(shareDataString);
|
|
17
|
+
const shareDataSignature = (0, generic_1.createEllipticalCurveSignature)(keyPair, shareDataHash);
|
|
18
|
+
const initialCryptoData = {
|
|
19
|
+
publicKey: keyPair.getPublic('hex'),
|
|
20
|
+
shareDataHash,
|
|
21
|
+
shareDataSignature,
|
|
22
|
+
timestamp: Date.now(),
|
|
23
|
+
};
|
|
24
|
+
return initialCryptoData;
|
|
25
|
+
};
|
|
26
|
+
exports.createShareDataInitialCrypto = createShareDataInitialCrypto;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IShareDataAdditionalValuesToInclude, IShareDataConfig } from '@degenerate/generic';
|
|
2
|
+
import { ShareData } from '../share-data';
|
|
3
|
+
/**
|
|
4
|
+
* This function calculates the share data string from the share data object.
|
|
5
|
+
*
|
|
6
|
+
* When `additionalValuesToInclude` is supplied, its `purpose` field is folded
|
|
7
|
+
* into the output as a `|purpose:<value>` suffix. This is load-bearing: it
|
|
8
|
+
* guarantees that two proofs taken over the same share-data state but for
|
|
9
|
+
* different purposes (e.g. `'deposit'` vs `'rule-balance'`) sign over
|
|
10
|
+
* different strings, so verification cannot accept one proof in place of
|
|
11
|
+
* another even when state happens to be identical.
|
|
12
|
+
*
|
|
13
|
+
* @param shareData the share data object
|
|
14
|
+
* @param config the configuration for the share data string
|
|
15
|
+
* @param additionalValuesToInclude extra values to fold in. `purpose` is
|
|
16
|
+
* required when this argument is supplied (enforced by the schema type).
|
|
17
|
+
* @returns the share data string
|
|
18
|
+
*/
|
|
19
|
+
export declare const calculateShareDataString: (shareData: ShareData, config?: IShareDataConfig, // Default config
|
|
20
|
+
additionalValuesToInclude?: IShareDataAdditionalValuesToInclude) => string;
|
|
21
|
+
//# sourceMappingURL=calculate-share-data-string.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculate-share-data-string.d.ts","sourceRoot":"","sources":["../../../src/share-data/helpers/calculate-share-data-string.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,mCAAmC,EACnC,gBAAgB,EAEnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG1C;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,wBAAwB,GACjC,WAAW,SAAS,EACpB,SAAQ,gBAA+C,EAAE,iBAAiB;AAC1E,4BAA4B,mCAAmC,WAqDlE,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateShareDataString = void 0;
|
|
4
|
+
const generic_1 = require("@degenerate/generic");
|
|
5
|
+
const default_share_data_string_config_1 = require("./config/default-share-data-string.config");
|
|
6
|
+
/**
|
|
7
|
+
* This function calculates the share data string from the share data object.
|
|
8
|
+
*
|
|
9
|
+
* When `additionalValuesToInclude` is supplied, its `purpose` field is folded
|
|
10
|
+
* into the output as a `|purpose:<value>` suffix. This is load-bearing: it
|
|
11
|
+
* guarantees that two proofs taken over the same share-data state but for
|
|
12
|
+
* different purposes (e.g. `'deposit'` vs `'rule-balance'`) sign over
|
|
13
|
+
* different strings, so verification cannot accept one proof in place of
|
|
14
|
+
* another even when state happens to be identical.
|
|
15
|
+
*
|
|
16
|
+
* @param shareData the share data object
|
|
17
|
+
* @param config the configuration for the share data string
|
|
18
|
+
* @param additionalValuesToInclude extra values to fold in. `purpose` is
|
|
19
|
+
* required when this argument is supplied (enforced by the schema type).
|
|
20
|
+
* @returns the share data string
|
|
21
|
+
*/
|
|
22
|
+
const calculateShareDataString = (shareData, config = default_share_data_string_config_1.defaultShareDataStringConfig, // Default config
|
|
23
|
+
additionalValuesToInclude) => {
|
|
24
|
+
generic_1.IShareDataConfigSchema.parse(config);
|
|
25
|
+
// Enforce the `purpose: z.string().min(1)` constraint declared on the
|
|
26
|
+
// schema. Without this, callers can pass an empty-string or omitted
|
|
27
|
+
// purpose and proofs verify normally, softening the cross-purpose
|
|
28
|
+
// replay protection. Only the purpose is enforced here; the optional
|
|
29
|
+
// rules/functions/transactionHistory/events arrays are forwarded
|
|
30
|
+
// without re-parsing (callers controlling those are typically internal,
|
|
31
|
+
// and full schema parse here was too strict in practice).
|
|
32
|
+
if (additionalValuesToInclude !== undefined) {
|
|
33
|
+
const purpose = additionalValuesToInclude.purpose;
|
|
34
|
+
if (typeof purpose !== 'string' || purpose.length < 1) {
|
|
35
|
+
throw new Error('calculateShareDataString: additionalValuesToInclude.purpose is required and must be a non-empty string');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
let fullString = '';
|
|
39
|
+
for (const configItem of config) {
|
|
40
|
+
const key = configItem.key.startsWith('_') ? configItem.key : `_${configItem.key}`;
|
|
41
|
+
if (key in shareData) {
|
|
42
|
+
const liveValue = shareData[key]; // Type assertion for dynamic access
|
|
43
|
+
// Default: hash whatever the share-data already holds. When the
|
|
44
|
+
// caller supplied a matching additional-values array, hash a
|
|
45
|
+
// freshly-merged copy so the live ShareData arrays stay
|
|
46
|
+
// untouched. The old `liveValue.push(...)` form permanently
|
|
47
|
+
// corrupted state across every signing call.
|
|
48
|
+
let value = liveValue;
|
|
49
|
+
if (typeof liveValue !== 'undefined' &&
|
|
50
|
+
Array.isArray(liveValue) &&
|
|
51
|
+
additionalValuesToInclude &&
|
|
52
|
+
configItem.key in additionalValuesToInclude) {
|
|
53
|
+
value = [...liveValue, ...additionalValuesToInclude[configItem.key]];
|
|
54
|
+
}
|
|
55
|
+
// Process the value if a process function is provided
|
|
56
|
+
if (configItem.process) {
|
|
57
|
+
fullString += configItem.process(value);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
fullString += value;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (additionalValuesToInclude) {
|
|
65
|
+
// Bind the signed snapshot to a specific purpose so a proof signed
|
|
66
|
+
// for one purpose cannot be replayed as a proof for another.
|
|
67
|
+
fullString += `|purpose:${additionalValuesToInclude.purpose}`;
|
|
68
|
+
}
|
|
69
|
+
return fullString;
|
|
70
|
+
};
|
|
71
|
+
exports.calculateShareDataString = calculateShareDataString;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IShareDataConfig } from '@degenerate/generic';
|
|
2
|
+
/**
|
|
3
|
+
* This contains the default configuration for the share data.
|
|
4
|
+
* strigify function.
|
|
5
|
+
*/
|
|
6
|
+
export declare const defaultShareDataStringConfig: IShareDataConfig;
|
|
7
|
+
//# sourceMappingURL=default-share-data-string.config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-share-data-string.config.d.ts","sourceRoot":"","sources":["../../../../src/share-data/helpers/config/default-share-data-string.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAIvD;;;GAGG;AACH,eAAO,MAAM,4BAA4B,EAAE,gBAe1C,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultShareDataStringConfig = void 0;
|
|
4
|
+
const get_array_string_1 = require("../get-array-string");
|
|
5
|
+
const stringify_1 = require("./stringify");
|
|
6
|
+
/**
|
|
7
|
+
* This contains the default configuration for the share data.
|
|
8
|
+
* strigify function.
|
|
9
|
+
*/
|
|
10
|
+
exports.defaultShareDataStringConfig = [
|
|
11
|
+
{ key: 'id' },
|
|
12
|
+
{ key: 'version' },
|
|
13
|
+
{ key: 'lastUpdated' },
|
|
14
|
+
{ key: 'isLocked' },
|
|
15
|
+
{ key: 'creationPublicKey' },
|
|
16
|
+
{ key: 'currentState', process: stringify_1.stringify },
|
|
17
|
+
{ key: 'cryptoProofs', process: get_array_string_1.getArrayString },
|
|
18
|
+
{ key: 'structuralProofs', process: get_array_string_1.getArrayString },
|
|
19
|
+
{ key: 'events', process: get_array_string_1.getArrayString },
|
|
20
|
+
{ key: 'functions', process: get_array_string_1.getArrayString },
|
|
21
|
+
{ key: 'rules', process: get_array_string_1.getArrayString },
|
|
22
|
+
{ key: 'transactionHistory', process: get_array_string_1.getArrayString },
|
|
23
|
+
{ key: 'creationHash' },
|
|
24
|
+
{ key: 'creationSignature' },
|
|
25
|
+
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringify.d.ts","sourceRoot":"","sources":["../../../../src/share-data/helpers/config/stringify.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,SAAS,GAAI,QAAQ,GAAG,EAAE,GAAG,MAAM,OAAO,EAAE,KAAG,MAE3D,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringify = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Create a wrapper function with the expected signature
|
|
6
|
+
*/
|
|
7
|
+
const stringify = (args_0, ...args) => {
|
|
8
|
+
return JSON.stringify(args_0, ...args);
|
|
9
|
+
};
|
|
10
|
+
exports.stringify = stringify;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-array-string.d.ts","sourceRoot":"","sources":["../../../src/share-data/helpers/get-array-string.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,GAAG,EAAE,WAO1C,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getArrayString = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* This function joins an array of strings into a single string.
|
|
6
|
+
* It explicitly converts undefined values to null before stringifying.
|
|
7
|
+
*/
|
|
8
|
+
const getArrayString = (array) => {
|
|
9
|
+
if (array.length === 0)
|
|
10
|
+
return '';
|
|
11
|
+
return array.map(item => {
|
|
12
|
+
// Explicitly convert undefined to null
|
|
13
|
+
const valueToStringify = item === undefined ? null : item;
|
|
14
|
+
return JSON.stringify(valueToStringify);
|
|
15
|
+
}).join('');
|
|
16
|
+
};
|
|
17
|
+
exports.getArrayString = getArrayString;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { EllipticalCurvesSigning, IShareData, IShareDataCryptoProof } from '@degenerate/generic';
|
|
2
|
+
import { ShareData } from '../../share-data';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for the production transaction-proposal signer returned by
|
|
5
|
+
* {@link buildTransactionProposalSigner}.
|
|
6
|
+
*/
|
|
7
|
+
export interface ITransactionProposalSignerConfig {
|
|
8
|
+
/**
|
|
9
|
+
* Hex-encoded private key authorized to mutate the target share-data
|
|
10
|
+
* (must correspond to its `creationPublicKey`). Captured in the returned
|
|
11
|
+
* closure and never leaves it. In production this should come from a
|
|
12
|
+
* secure key manager (KMS / HSM / encrypted environment value), not a
|
|
13
|
+
* literal string in code.
|
|
14
|
+
*/
|
|
15
|
+
privateKey: string;
|
|
16
|
+
/**
|
|
17
|
+
* Elliptical curve to sign with. Defaults to `Curve25519`, matching the
|
|
18
|
+
* `ShareData` constructor default.
|
|
19
|
+
*/
|
|
20
|
+
curve?: EllipticalCurvesSigning;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A bound signer that mints a transaction proposal proof authorizing one
|
|
24
|
+
* exact state change. Hand it the proposed state, the function producing
|
|
25
|
+
* that state, and the live share-data, and it returns a proof the runtime
|
|
26
|
+
* mutation path (`ShareData.addTransaction` / `ShareDataManager.applyTransaction`)
|
|
27
|
+
* will accept.
|
|
28
|
+
*/
|
|
29
|
+
export type TransactionProposalSigner = (proposedState: IShareData, functionId: string, shareData: ShareData) => IShareDataCryptoProof;
|
|
30
|
+
/**
|
|
31
|
+
* Returns a production-ready {@link TransactionProposalSigner} that signs each
|
|
32
|
+
* runtime transaction with `config.privateKey`. This is the transaction-path
|
|
33
|
+
* analog of `buildEllipticalCurvesProofFor` (from `@degenerate/shareblock`):
|
|
34
|
+
* where that one mints *structural* proofs as a block is assembled, this one
|
|
35
|
+
* mints *transaction* proofs that authorize mutating an already-built,
|
|
36
|
+
* already-locked block at runtime.
|
|
37
|
+
*
|
|
38
|
+
* Wire it into the proposer adapter that drives the events/realtime mutation
|
|
39
|
+
* path:
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* const sign = buildTransactionProposalSigner({
|
|
43
|
+
* privateKey: keyManager.getSigningKey(shareDataId),
|
|
44
|
+
* });
|
|
45
|
+
* const proof = sign(proposedState, functionId, shareData);
|
|
46
|
+
* manager.applyTransaction(shareDataId, proposedState, fn, proof);
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* Unlike the structural signer, this one performs **no** crypto
|
|
50
|
+
* initialization: at runtime the block's crypto chain is already established
|
|
51
|
+
* and the block is locked, so `createTransactionProposalProof` has a previous
|
|
52
|
+
* hash to chain to. The proof binds the proposed-state hash and `functionId`
|
|
53
|
+
* into the signature, so it authorizes exactly one state change and cannot be
|
|
54
|
+
* replayed for a different amount or a different function.
|
|
55
|
+
*/
|
|
56
|
+
export declare const buildTransactionProposalSigner: (config: ITransactionProposalSignerConfig) => TransactionProposalSigner;
|
|
57
|
+
//# sourceMappingURL=build-transaction-proposal-signer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-transaction-proposal-signer.d.ts","sourceRoot":"","sources":["../../../../src/share-data/proofs/creation/build-transaction-proposal-signer.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,uBAAuB,EACvB,UAAU,EACV,qBAAqB,EACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG7C;;;GAGG;AACH,MAAM,WAAW,gCAAgC;IAC7C;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,KAAK,CAAC,EAAE,uBAAuB,CAAC;CACnC;AAED;;;;;;GAMG;AACH,MAAM,MAAM,yBAAyB,GAAG,CACpC,aAAa,EAAE,UAAU,EACzB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,SAAS,KACnB,qBAAqB,CAAC;AAE3B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,8BAA8B,GACvC,QAAQ,gCAAgC,KACzC,yBAUF,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildTransactionProposalSigner = void 0;
|
|
4
|
+
const generic_1 = require("@degenerate/generic");
|
|
5
|
+
const create_transaction_proposal_proof_1 = require("./create-transaction-proposal-proof");
|
|
6
|
+
/**
|
|
7
|
+
* Returns a production-ready {@link TransactionProposalSigner} that signs each
|
|
8
|
+
* runtime transaction with `config.privateKey`. This is the transaction-path
|
|
9
|
+
* analog of `buildEllipticalCurvesProofFor` (from `@degenerate/shareblock`):
|
|
10
|
+
* where that one mints *structural* proofs as a block is assembled, this one
|
|
11
|
+
* mints *transaction* proofs that authorize mutating an already-built,
|
|
12
|
+
* already-locked block at runtime.
|
|
13
|
+
*
|
|
14
|
+
* Wire it into the proposer adapter that drives the events/realtime mutation
|
|
15
|
+
* path:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* const sign = buildTransactionProposalSigner({
|
|
19
|
+
* privateKey: keyManager.getSigningKey(shareDataId),
|
|
20
|
+
* });
|
|
21
|
+
* const proof = sign(proposedState, functionId, shareData);
|
|
22
|
+
* manager.applyTransaction(shareDataId, proposedState, fn, proof);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* Unlike the structural signer, this one performs **no** crypto
|
|
26
|
+
* initialization: at runtime the block's crypto chain is already established
|
|
27
|
+
* and the block is locked, so `createTransactionProposalProof` has a previous
|
|
28
|
+
* hash to chain to. The proof binds the proposed-state hash and `functionId`
|
|
29
|
+
* into the signature, so it authorizes exactly one state change and cannot be
|
|
30
|
+
* replayed for a different amount or a different function.
|
|
31
|
+
*/
|
|
32
|
+
const buildTransactionProposalSigner = (config) => {
|
|
33
|
+
const curve = config.curve ?? generic_1.EllipticalCurvesSigning.Curve25519;
|
|
34
|
+
return (proposedState, functionId, shareData) => (0, create_transaction_proposal_proof_1.createTransactionProposalProof)(config.privateKey, shareData, proposedState, functionId, curve);
|
|
35
|
+
};
|
|
36
|
+
exports.buildTransactionProposalSigner = buildTransactionProposalSigner;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EllipticalCurvesSigning, IShareDataAdditionalValuesToInclude, IShareDataCryptoProof } from '@degenerate/generic';
|
|
2
|
+
import { ShareData } from '../../share-data';
|
|
3
|
+
/**
|
|
4
|
+
* This function creates a share data proposal proof.
|
|
5
|
+
* @param privateKey the private key to sign the share data proof
|
|
6
|
+
* @param shareData the share data object
|
|
7
|
+
* @param additionalValuesToInclude the additional values to include in the share data string
|
|
8
|
+
* @param ellipticalCurve the elliptical curve to use for signing
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export declare const createShareDataProposalProof: (privateKey: string, shareData: ShareData, additionalValuesToInclude: IShareDataAdditionalValuesToInclude, ellipticalCurve?: EllipticalCurvesSigning) => IShareDataCryptoProof;
|
|
12
|
+
//# sourceMappingURL=create-share-data-proposal-proof.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-share-data-proposal-proof.d.ts","sourceRoot":"","sources":["../../../../src/share-data/proofs/creation/create-share-data-proposal-proof.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,uBAAuB,EACvB,mCAAmC,EACnC,qBAAqB,EACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAI7C;;;;;;;GAOG;AACH,eAAO,MAAM,4BAA4B,GACrC,YAAY,MAAM,EAClB,WAAW,SAAS,EACpB,2BAA2B,mCAAmC,EAC9D,kBAAiB,uBAA4D,KAC9E,qBA0BF,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createShareDataProposalProof = void 0;
|
|
4
|
+
const generic_1 = require("@degenerate/generic");
|
|
5
|
+
const calculate_share_data_string_1 = require("../../helpers/calculate-share-data-string");
|
|
6
|
+
const get_previous_hash_from_share_data_1 = require("../helpers/get-previous-hash-from-share-data");
|
|
7
|
+
const create_share_data_string_to_sign_1 = require("../helpers/create-share-data-string-to-sign");
|
|
8
|
+
/**
|
|
9
|
+
* This function creates a share data proposal proof.
|
|
10
|
+
* @param privateKey the private key to sign the share data proof
|
|
11
|
+
* @param shareData the share data object
|
|
12
|
+
* @param additionalValuesToInclude the additional values to include in the share data string
|
|
13
|
+
* @param ellipticalCurve the elliptical curve to use for signing
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
const createShareDataProposalProof = (privateKey, shareData, additionalValuesToInclude, ellipticalCurve = generic_1.EllipticalCurvesSigning.Curve25519) => {
|
|
17
|
+
const keyPair = (0, generic_1.createKeyPairFromPrivateKey)(ellipticalCurve, privateKey);
|
|
18
|
+
const shareDataString = (0, calculate_share_data_string_1.calculateShareDataString)(shareData, undefined, additionalValuesToInclude);
|
|
19
|
+
const shareDataPreviousHash = (0, get_previous_hash_from_share_data_1.getPreviousHashFromShareData)(shareData);
|
|
20
|
+
const shareDataHash = (0, generic_1.calculateHash)(shareDataString);
|
|
21
|
+
const currentTimestamp = Date.now();
|
|
22
|
+
// calculate the current signature for the share data proof
|
|
23
|
+
const shareDataSignatureString = (0, create_share_data_string_to_sign_1.createShareDataStringToSign)(shareDataHash, shareDataPreviousHash, currentTimestamp);
|
|
24
|
+
const shareDataSignature = (0, generic_1.createEllipticalCurveSignature)(keyPair, shareDataSignatureString);
|
|
25
|
+
const shareDataCryptoProof = {
|
|
26
|
+
publicKey: keyPair.getPublic('hex'),
|
|
27
|
+
shareDataHash,
|
|
28
|
+
shareDataPreviousHash,
|
|
29
|
+
shareDataSignature,
|
|
30
|
+
// Reuse the timestamp folded into the signed string above. Calling
|
|
31
|
+
// Date.now() a second time here would let a millisecond tick
|
|
32
|
+
// between the two reads, so the proof's `timestamp` would not match
|
|
33
|
+
// what was signed — verification would then fail intermittently.
|
|
34
|
+
timestamp: currentTimestamp,
|
|
35
|
+
// The proof carries its own purpose so verifiers don't need a
|
|
36
|
+
// separate parameter at the boundary — see schema docs.
|
|
37
|
+
purpose: additionalValuesToInclude.purpose,
|
|
38
|
+
};
|
|
39
|
+
return shareDataCryptoProof;
|
|
40
|
+
};
|
|
41
|
+
exports.createShareDataProposalProof = createShareDataProposalProof;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EllipticalCurvesSigning, IShareData, IShareDataCryptoProof } from '@degenerate/generic';
|
|
2
|
+
import { ShareData } from '../../share-data';
|
|
3
|
+
/**
|
|
4
|
+
* Mint a transaction proposal proof: a signed attestation that the holder of
|
|
5
|
+
* `privateKey` authorizes applying `functionId` to move `shareData` from its
|
|
6
|
+
* current state to exactly `proposedState`.
|
|
7
|
+
*
|
|
8
|
+
* Unlike a structural proof (which binds only the current state + a purpose),
|
|
9
|
+
* this proof folds the *proposed* state hash and the function id into the
|
|
10
|
+
* signed string. That closes the runtime replay hole: the signature is valid
|
|
11
|
+
* only for the one proposed state it was minted for, so it cannot be replayed
|
|
12
|
+
* to authorize a different amount or a different function.
|
|
13
|
+
*
|
|
14
|
+
* The wire shape is the existing `IShareDataCryptoProof`: `purpose` carries
|
|
15
|
+
* the `functionId`, and the proposed-state binding lives entirely in the
|
|
16
|
+
* signature. The verifier recomputes the proposed-state hash from the proposed
|
|
17
|
+
* state it is handed at apply time, so it never needs to be stored in the
|
|
18
|
+
* proof — keeping the wire / persistence / history shape unchanged.
|
|
19
|
+
*
|
|
20
|
+
* @param privateKey hex private key authorized for this share-data
|
|
21
|
+
* @param shareData the share-data the transaction will mutate
|
|
22
|
+
* @param proposedState the exact state the function proposes to apply
|
|
23
|
+
* @param functionId stable id of the function producing `proposedState`
|
|
24
|
+
* @param ellipticalCurve the signing curve (defaults to Curve25519)
|
|
25
|
+
*/
|
|
26
|
+
export declare const createTransactionProposalProof: (privateKey: string, shareData: ShareData, proposedState: IShareData, functionId: string, ellipticalCurve?: EllipticalCurvesSigning) => IShareDataCryptoProof;
|
|
27
|
+
//# sourceMappingURL=create-transaction-proposal-proof.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-transaction-proposal-proof.d.ts","sourceRoot":"","sources":["../../../../src/share-data/proofs/creation/create-transaction-proposal-proof.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,uBAAuB,EACvB,UAAU,EACV,qBAAqB,EACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAK7C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,8BAA8B,GACvC,YAAY,MAAM,EAClB,WAAW,SAAS,EACpB,eAAe,UAAU,EACzB,YAAY,MAAM,EAClB,kBAAiB,uBAA4D,KAC9E,qBAkCF,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTransactionProposalProof = void 0;
|
|
4
|
+
const generic_1 = require("@degenerate/generic");
|
|
5
|
+
const calculate_share_data_string_1 = require("../../helpers/calculate-share-data-string");
|
|
6
|
+
const get_previous_hash_from_share_data_1 = require("../helpers/get-previous-hash-from-share-data");
|
|
7
|
+
const create_transaction_proposal_string_to_sign_1 = require("../helpers/create-transaction-proposal-string-to-sign");
|
|
8
|
+
const hash_proposed_state_1 = require("../helpers/hash-proposed-state");
|
|
9
|
+
/**
|
|
10
|
+
* Mint a transaction proposal proof: a signed attestation that the holder of
|
|
11
|
+
* `privateKey` authorizes applying `functionId` to move `shareData` from its
|
|
12
|
+
* current state to exactly `proposedState`.
|
|
13
|
+
*
|
|
14
|
+
* Unlike a structural proof (which binds only the current state + a purpose),
|
|
15
|
+
* this proof folds the *proposed* state hash and the function id into the
|
|
16
|
+
* signed string. That closes the runtime replay hole: the signature is valid
|
|
17
|
+
* only for the one proposed state it was minted for, so it cannot be replayed
|
|
18
|
+
* to authorize a different amount or a different function.
|
|
19
|
+
*
|
|
20
|
+
* The wire shape is the existing `IShareDataCryptoProof`: `purpose` carries
|
|
21
|
+
* the `functionId`, and the proposed-state binding lives entirely in the
|
|
22
|
+
* signature. The verifier recomputes the proposed-state hash from the proposed
|
|
23
|
+
* state it is handed at apply time, so it never needs to be stored in the
|
|
24
|
+
* proof — keeping the wire / persistence / history shape unchanged.
|
|
25
|
+
*
|
|
26
|
+
* @param privateKey hex private key authorized for this share-data
|
|
27
|
+
* @param shareData the share-data the transaction will mutate
|
|
28
|
+
* @param proposedState the exact state the function proposes to apply
|
|
29
|
+
* @param functionId stable id of the function producing `proposedState`
|
|
30
|
+
* @param ellipticalCurve the signing curve (defaults to Curve25519)
|
|
31
|
+
*/
|
|
32
|
+
const createTransactionProposalProof = (privateKey, shareData, proposedState, functionId, ellipticalCurve = generic_1.EllipticalCurvesSigning.Curve25519) => {
|
|
33
|
+
if (typeof functionId !== 'string' || functionId.length < 1) {
|
|
34
|
+
throw new Error('createTransactionProposalProof: functionId is required and must be a non-empty string');
|
|
35
|
+
}
|
|
36
|
+
const keyPair = (0, generic_1.createKeyPairFromPrivateKey)(ellipticalCurve, privateKey);
|
|
37
|
+
// Current-state hash uses functionId as the purpose, mirroring how the
|
|
38
|
+
// verifier recomputes it from `proof.purpose`.
|
|
39
|
+
const currentString = (0, calculate_share_data_string_1.calculateShareDataString)(shareData, undefined, { purpose: functionId });
|
|
40
|
+
const currentHash = (0, generic_1.calculateHash)(currentString);
|
|
41
|
+
const proposedStateHash = (0, hash_proposed_state_1.hashProposedState)(proposedState);
|
|
42
|
+
const previousHash = (0, get_previous_hash_from_share_data_1.getPreviousHashFromShareData)(shareData);
|
|
43
|
+
const timestamp = Date.now();
|
|
44
|
+
const signedString = (0, create_transaction_proposal_string_to_sign_1.createTransactionProposalStringToSign)(currentHash, proposedStateHash, functionId, previousHash, timestamp);
|
|
45
|
+
const signature = (0, generic_1.createEllipticalCurveSignature)(keyPair, signedString);
|
|
46
|
+
// Field order mirrors IShareDataCryptoProofSchema exactly — load-bearing,
|
|
47
|
+
// see the schema docs in share-data-crypto-models.ts.
|
|
48
|
+
const proof = {
|
|
49
|
+
publicKey: keyPair.getPublic('hex'),
|
|
50
|
+
shareDataHash: currentHash,
|
|
51
|
+
shareDataPreviousHash: previousHash,
|
|
52
|
+
shareDataSignature: signature,
|
|
53
|
+
timestamp,
|
|
54
|
+
purpose: functionId,
|
|
55
|
+
};
|
|
56
|
+
return proof;
|
|
57
|
+
};
|
|
58
|
+
exports.createTransactionProposalProof = createTransactionProposalProof;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function creates the string to sign for the crypto proof
|
|
3
|
+
*
|
|
4
|
+
* @param currentShareDataHash the current share data hash
|
|
5
|
+
* @param previousShareDataHash the previous share data hash
|
|
6
|
+
* @param timeStamp the timestamp of the crypto proof
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare const createShareDataStringToSign: (currentShareDataHash: string, // the current share data hash
|
|
10
|
+
previousShareDataHash: string, // the previous share data hash
|
|
11
|
+
timeStamp: number) => string;
|
|
12
|
+
//# sourceMappingURL=create-share-data-string-to-sign.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-share-data-string-to-sign.d.ts","sourceRoot":"","sources":["../../../../src/share-data/proofs/helpers/create-share-data-string-to-sign.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,2BAA2B,GACpC,sBAAsB,MAAM,EAAE,8BAA8B;AAC5D,uBAAuB,MAAM,EAAE,+BAA+B;AAC9D,WAAW,MAAM,KAClB,MAEF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createShareDataStringToSign = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* This function creates the string to sign for the crypto proof
|
|
6
|
+
*
|
|
7
|
+
* @param currentShareDataHash the current share data hash
|
|
8
|
+
* @param previousShareDataHash the previous share data hash
|
|
9
|
+
* @param timeStamp the timestamp of the crypto proof
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
const createShareDataStringToSign = (currentShareDataHash, // the current share data hash
|
|
13
|
+
previousShareDataHash, // the previous share data hash
|
|
14
|
+
timeStamp) => {
|
|
15
|
+
return `${currentShareDataHash}${previousShareDataHash}${timeStamp}`;
|
|
16
|
+
};
|
|
17
|
+
exports.createShareDataStringToSign = createShareDataStringToSign;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the canonical string a transaction proposal proof signs over.
|
|
3
|
+
*
|
|
4
|
+
* Deliberately distinct from `createShareDataStringToSign` (the structural /
|
|
5
|
+
* creation proof payload). A structural proof signs
|
|
6
|
+
* `${hash}${previousHash}${timestamp}` with no delimiters; this payload adds a
|
|
7
|
+
* `tx:` prefix, pipe delimiters, the *proposed* state hash, and the function
|
|
8
|
+
* id. Because the two signed strings can never collide, a structural proof's
|
|
9
|
+
* signature can never satisfy transaction verification and vice versa — the
|
|
10
|
+
* proof kinds are cryptographically non-interchangeable even though they share
|
|
11
|
+
* the `IShareDataCryptoProof` wire shape.
|
|
12
|
+
*
|
|
13
|
+
* The `proposedStateHash` component is what closes the runtime replay hole:
|
|
14
|
+
* the signature binds the exact post-transaction state, so a proof minted for
|
|
15
|
+
* a 1000-unit deposit cannot authorize a 9000-unit deposit.
|
|
16
|
+
*
|
|
17
|
+
* @param currentShareDataHash hash of the share-data state before the transaction
|
|
18
|
+
* @param proposedStateHash hash of the proposed (post-transaction) state
|
|
19
|
+
* @param functionId id of the function authorized to produce the proposed state
|
|
20
|
+
* @param previousShareDataHash previous hash anchoring the chain position
|
|
21
|
+
* @param timeStamp the timestamp folded into the signature
|
|
22
|
+
*/
|
|
23
|
+
export declare const createTransactionProposalStringToSign: (currentShareDataHash: string, proposedStateHash: string, functionId: string, previousShareDataHash: string, timeStamp: number) => string;
|
|
24
|
+
//# sourceMappingURL=create-transaction-proposal-string-to-sign.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-transaction-proposal-string-to-sign.d.ts","sourceRoot":"","sources":["../../../../src/share-data/proofs/helpers/create-transaction-proposal-string-to-sign.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,qCAAqC,GAC9C,sBAAsB,MAAM,EAC5B,mBAAmB,MAAM,EACzB,YAAY,MAAM,EAClB,uBAAuB,MAAM,EAC7B,WAAW,MAAM,KAClB,MAEF,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTransactionProposalStringToSign = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Builds the canonical string a transaction proposal proof signs over.
|
|
6
|
+
*
|
|
7
|
+
* Deliberately distinct from `createShareDataStringToSign` (the structural /
|
|
8
|
+
* creation proof payload). A structural proof signs
|
|
9
|
+
* `${hash}${previousHash}${timestamp}` with no delimiters; this payload adds a
|
|
10
|
+
* `tx:` prefix, pipe delimiters, the *proposed* state hash, and the function
|
|
11
|
+
* id. Because the two signed strings can never collide, a structural proof's
|
|
12
|
+
* signature can never satisfy transaction verification and vice versa — the
|
|
13
|
+
* proof kinds are cryptographically non-interchangeable even though they share
|
|
14
|
+
* the `IShareDataCryptoProof` wire shape.
|
|
15
|
+
*
|
|
16
|
+
* The `proposedStateHash` component is what closes the runtime replay hole:
|
|
17
|
+
* the signature binds the exact post-transaction state, so a proof minted for
|
|
18
|
+
* a 1000-unit deposit cannot authorize a 9000-unit deposit.
|
|
19
|
+
*
|
|
20
|
+
* @param currentShareDataHash hash of the share-data state before the transaction
|
|
21
|
+
* @param proposedStateHash hash of the proposed (post-transaction) state
|
|
22
|
+
* @param functionId id of the function authorized to produce the proposed state
|
|
23
|
+
* @param previousShareDataHash previous hash anchoring the chain position
|
|
24
|
+
* @param timeStamp the timestamp folded into the signature
|
|
25
|
+
*/
|
|
26
|
+
const createTransactionProposalStringToSign = (currentShareDataHash, proposedStateHash, functionId, previousShareDataHash, timeStamp) => {
|
|
27
|
+
return `tx:${currentShareDataHash}|${proposedStateHash}|${functionId}|${previousShareDataHash}|${timeStamp}`;
|
|
28
|
+
};
|
|
29
|
+
exports.createTransactionProposalStringToSign = createTransactionProposalStringToSign;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ShareData } from '../../share-data';
|
|
2
|
+
/**
|
|
3
|
+
* This gets the previous hash from the share data object.
|
|
4
|
+
*
|
|
5
|
+
* @param shareData the share data object
|
|
6
|
+
* @returns the previous hash
|
|
7
|
+
*/
|
|
8
|
+
export declare const getPreviousHashFromShareData: (shareData: ShareData) => string;
|
|
9
|
+
//# sourceMappingURL=get-previous-hash-from-share-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-previous-hash-from-share-data.d.ts","sourceRoot":"","sources":["../../../../src/share-data/proofs/helpers/get-previous-hash-from-share-data.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,GAAI,WAAW,SAAS,KAAG,MAmBnE,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPreviousHashFromShareData = void 0;
|
|
4
|
+
const generic_1 = require("@degenerate/generic");
|
|
5
|
+
/**
|
|
6
|
+
* This gets the previous hash from the share data object.
|
|
7
|
+
*
|
|
8
|
+
* @param shareData the share data object
|
|
9
|
+
* @returns the previous hash
|
|
10
|
+
*/
|
|
11
|
+
const getPreviousHashFromShareData = (shareData) => {
|
|
12
|
+
if (shareData.isLocked) {
|
|
13
|
+
if (shareData.cryptoProofs.length !== 0) {
|
|
14
|
+
return shareData.cryptoProofs[shareData.cryptoProofs.length - 1].shareDataHash;
|
|
15
|
+
}
|
|
16
|
+
return shareData.structuralProofs[shareData.structuralProofs.length - 1].shareDataHash;
|
|
17
|
+
}
|
|
18
|
+
if (shareData.structuralProofs.length !== 0) {
|
|
19
|
+
return shareData.structuralProofs[shareData.structuralProofs.length - 1].shareDataHash;
|
|
20
|
+
}
|
|
21
|
+
// If the share data is not locked and there are no structural proofs,
|
|
22
|
+
// then the creation hash is the previous hash
|
|
23
|
+
if (!shareData.creationHash) {
|
|
24
|
+
throw new generic_1.ShareDataPreviousHashNotAvailableError(shareData.id);
|
|
25
|
+
}
|
|
26
|
+
return shareData.creationHash;
|
|
27
|
+
};
|
|
28
|
+
exports.getPreviousHashFromShareData = getPreviousHashFromShareData;
|