@degenerate/sharedata 0.3.1 → 0.6.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/persistence/block-factory-registry.d.ts +8 -2
- package/dist/persistence/block-factory-registry.d.ts.map +1 -1
- package/dist/persistence/deserialize-share-data.d.ts.map +1 -1
- package/dist/persistence/deserialize-share-data.js +8 -3
- package/dist/persistence/serialize-share-data.d.ts.map +1 -1
- package/dist/persistence/serialize-share-data.js +4 -0
- package/dist/share-data/creation/create-share-data-initial-crypto.d.ts +4 -5
- package/dist/share-data/creation/create-share-data-initial-crypto.d.ts.map +1 -1
- package/dist/share-data/creation/create-share-data-initial-crypto.js +6 -7
- package/dist/share-data/helpers/config/default-share-data-string.config.d.ts.map +1 -1
- package/dist/share-data/helpers/config/default-share-data-string.config.js +5 -0
- package/dist/share-data/proofs/creation/build-transaction-proposal-signer.d.ts +5 -10
- package/dist/share-data/proofs/creation/build-transaction-proposal-signer.d.ts.map +1 -1
- package/dist/share-data/proofs/creation/build-transaction-proposal-signer.js +1 -3
- package/dist/share-data/proofs/creation/create-share-data-proposal-proof.d.ts +3 -4
- package/dist/share-data/proofs/creation/create-share-data-proposal-proof.d.ts.map +1 -1
- package/dist/share-data/proofs/creation/create-share-data-proposal-proof.js +5 -6
- package/dist/share-data/proofs/creation/create-transaction-proposal-proof.d.ts +3 -4
- package/dist/share-data/proofs/creation/create-transaction-proposal-proof.d.ts.map +1 -1
- package/dist/share-data/proofs/creation/create-transaction-proposal-proof.js +5 -6
- package/dist/share-data/proofs/testing/test-proof-signer.d.ts +8 -8
- package/dist/share-data/proofs/testing/test-proof-signer.d.ts.map +1 -1
- package/dist/share-data/proofs/testing/test-proof-signer.js +17 -19
- package/dist/share-data/proofs/verification/verify-share-data-proposal-proof.d.ts +4 -6
- package/dist/share-data/proofs/verification/verify-share-data-proposal-proof.d.ts.map +1 -1
- package/dist/share-data/proofs/verification/verify-share-data-proposal-proof.js +8 -57
- package/dist/share-data/proofs/verification/verify-transaction-proposal-proof.d.ts +4 -4
- package/dist/share-data/proofs/verification/verify-transaction-proposal-proof.d.ts.map +1 -1
- package/dist/share-data/proofs/verification/verify-transaction-proposal-proof.js +8 -54
- package/dist/share-data/share-data.d.ts +61 -9
- package/dist/share-data/share-data.d.ts.map +1 -1
- package/dist/share-data/share-data.js +101 -14
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IShareDataInitialCryptoData, PersistedCreationConfig, ShareBlockType, ShareDataProofs } from '@degenerate/generic';
|
|
1
|
+
import { IAuthorizedSigner, IShareDataInitialCryptoData, PersistedCreationConfig, ShareBlockType, ShareDataProofs } from '@degenerate/generic';
|
|
2
2
|
import { ShareData } from '../share-data/share-data';
|
|
3
3
|
/**
|
|
4
4
|
* The inputs a block builder needs to replay construction of a persisted
|
|
@@ -10,12 +10,18 @@ import { ShareData } from '../share-data/share-data';
|
|
|
10
10
|
* - `initialCrypto` — the client-computed creation crypto, applied to the
|
|
11
11
|
* in-construction block on the first proof lookup.
|
|
12
12
|
* - `structuralProofs` — the per-purpose proof bundle, replayed in place of
|
|
13
|
-
* a live signer so the rebuilt block carries byte-identical proofs.
|
|
13
|
+
* a live signer so the rebuilt block carries byte-identical proofs. This
|
|
14
|
+
* bundle also contains the delegate registration proofs (keyed by their
|
|
15
|
+
* `delegate:<key>:<ids>` purpose).
|
|
16
|
+
* - `authorizedSigners` — the delegated-signer grant tuples to re-apply via
|
|
17
|
+
* `addAuthorizedSigner`, so the rebuilt block re-derives the same signer
|
|
18
|
+
* set (and canonical hash) it had live. Empty for non-delegating blocks.
|
|
14
19
|
*/
|
|
15
20
|
export interface ShareBlockBuilderInput {
|
|
16
21
|
creationConfig: PersistedCreationConfig;
|
|
17
22
|
initialCrypto: IShareDataInitialCryptoData;
|
|
18
23
|
structuralProofs: ShareDataProofs;
|
|
24
|
+
authorizedSigners: IAuthorizedSigner[];
|
|
19
25
|
}
|
|
20
26
|
/**
|
|
21
27
|
* Rebuilds a ShareData of a single block type from its persisted recipe.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-factory-registry.d.ts","sourceRoot":"","sources":["../../src/persistence/block-factory-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,2BAA2B,EAC3B,uBAAuB,EACvB,cAAc,EACd,eAAe,EAClB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAgBrD
|
|
1
|
+
{"version":3,"file":"block-factory-registry.d.ts","sourceRoot":"","sources":["../../src/persistence/block-factory-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,iBAAiB,EACjB,2BAA2B,EAC3B,uBAAuB,EACvB,cAAc,EACd,eAAe,EAClB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAgBrD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,sBAAsB;IACnC,cAAc,EAAE,uBAAuB,CAAC;IACxC,aAAa,EAAE,2BAA2B,CAAC;IAC3C,gBAAgB,EAAE,eAAe,CAAC;IAClC,iBAAiB,EAAE,iBAAiB,EAAE,CAAC;CAC1C;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,sBAAsB,KAAK,SAAS,CAAC;AAQ7E;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GAClC,WAAW,cAAc,EACzB,SAAS,iBAAiB,KAC3B,IAEF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAC7B,WAAW,cAAc,KAC1B,iBAAiB,GAAG,SAAoC,CAAC;AAE5D,gEAAgE;AAChE,eAAO,MAAM,oBAAoB,GAAI,WAAW,cAAc,KAAG,OACtC,CAAC;AAE5B;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,QAAO,IAE1C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deserialize-share-data.d.ts","sourceRoot":"","sources":["../../src/persistence/deserialize-share-data.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAYrD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,oBAAoB,GAAI,UAAU,OAAO,KAAG,
|
|
1
|
+
{"version":3,"file":"deserialize-share-data.d.ts","sourceRoot":"","sources":["../../src/persistence/deserialize-share-data.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAYrD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,oBAAoB,GAAI,UAAU,OAAO,KAAG,SAoHxD,CAAC"}
|
|
@@ -55,6 +55,7 @@ const deserializeShareData = (snapshot) => {
|
|
|
55
55
|
creationConfig: parsed.creationConfig,
|
|
56
56
|
initialCrypto: parsed.initialCrypto,
|
|
57
57
|
structuralProofs: parsed.structuralProofs,
|
|
58
|
+
authorizedSigners: parsed.authorizedSigners,
|
|
58
59
|
});
|
|
59
60
|
// Replay the transaction log in recorded order.
|
|
60
61
|
for (const entry of parsed.transactionLog) {
|
|
@@ -68,8 +69,12 @@ const deserializeShareData = (snapshot) => {
|
|
|
68
69
|
// verification, so the proposer-identity gate (the same one
|
|
69
70
|
// addTransaction enforces live) must run on replay too. Checked first
|
|
70
71
|
// so a swapped key fails as a not-authorized error rather than a
|
|
71
|
-
// signature mismatch.
|
|
72
|
-
|
|
72
|
+
// signature mismatch. Uses the same widened predicate as the live gate:
|
|
73
|
+
// the creation key for any function, or a delegate for its granted
|
|
74
|
+
// function (`entry.proof.purpose` is the function id). The signer set was
|
|
75
|
+
// re-derived from re-verified registration proofs during construction
|
|
76
|
+
// above, so an injected grant with no valid proof never reaches here.
|
|
77
|
+
if (!block.isAuthorizedSigner(entry.proof.publicKey, entry.proof.purpose)) {
|
|
73
78
|
throw new generic_1.ShareDataTransactionNotAuthorizedError(parsed.id, entry.proof.publicKey);
|
|
74
79
|
}
|
|
75
80
|
// Re-verify the transaction proof against the block at its pre-entry
|
|
@@ -79,7 +84,7 @@ const deserializeShareData = (snapshot) => {
|
|
|
79
84
|
// throws ShareDataTransactionProofFailedError here rather than being
|
|
80
85
|
// loaded. Verifying before the apply keeps the recomputed current hash
|
|
81
86
|
// aligned with what the signer signed over.
|
|
82
|
-
(0, verify_transaction_proposal_proof_1.verifyTransactionProposalProof)(entry.proof, block, entry.proposedState
|
|
87
|
+
(0, verify_transaction_proposal_proof_1.verifyTransactionProposalProof)(entry.proof, block, entry.proposedState);
|
|
83
88
|
// addTransactionAlreadyValidated derives its accept/reject outcome
|
|
84
89
|
// from (proposedResult && currentResult). Setting both to the stored
|
|
85
90
|
// boolean replays the original outcome exactly: currentState is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize-share-data.d.ts","sourceRoot":"","sources":["../../src/persistence/serialize-share-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,EACpB,cAAc,EAEjB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAUrD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,kBAAkB,GAC3B,WAAW,cAAc,EACzB,gBAAgB,uBAAuB,EACvC,OAAO,SAAS,EAChB,gBAAgB,oBAAoB,EAAE,KACvC,
|
|
1
|
+
{"version":3,"file":"serialize-share-data.d.ts","sourceRoot":"","sources":["../../src/persistence/serialize-share-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,EACpB,cAAc,EAEjB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAUrD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,kBAAkB,GAC3B,WAAW,cAAc,EACzB,gBAAgB,uBAAuB,EACvC,OAAO,SAAS,EAChB,gBAAgB,oBAAoB,EAAE,KACvC,kBAoCF,CAAC"}
|
|
@@ -51,6 +51,10 @@ const serializeShareData = (blockType, creationConfig, block, transactionLog) =>
|
|
|
51
51
|
},
|
|
52
52
|
creationConfig,
|
|
53
53
|
structuralProofs,
|
|
54
|
+
// The grant tuples re-applied via `addAuthorizedSigner` on replay; the
|
|
55
|
+
// matching registration proofs are already carried in `structuralProofs`
|
|
56
|
+
// (keyed by their `delegate:` purpose). Empty for non-delegating blocks.
|
|
57
|
+
authorizedSigners: block.authorizedSigners,
|
|
54
58
|
transactionLog,
|
|
55
59
|
expectedCurrentState: block.currentState,
|
|
56
60
|
expectedCreationHash: block.creationHash,
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IShareDataInitialCryptoData } from '@degenerate/generic';
|
|
2
2
|
import { ShareData } from '../share-data';
|
|
3
3
|
/**
|
|
4
4
|
* This function creates the initial crypto data for the share data.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
6
|
+
* @param privateKey the 32-byte Ed25519 secret seed (hex) to sign with
|
|
7
|
+
* @param shareData the share data to create the initial crypto for
|
|
7
8
|
*/
|
|
8
|
-
export declare const createShareDataInitialCrypto: (privateKey: string,
|
|
9
|
-
shareData: ShareData, // the share data to create the initial crypto for
|
|
10
|
-
signingCurve?: EllipticalCurvesSigning) => IShareDataInitialCryptoData;
|
|
9
|
+
export declare const createShareDataInitialCrypto: (privateKey: string, shareData: ShareData) => IShareDataInitialCryptoData;
|
|
11
10
|
//# sourceMappingURL=create-share-data-initial-crypto.d.ts.map
|
|
@@ -1 +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,
|
|
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,2BAA2B,EAC9B,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG1C;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,GACrC,YAAY,MAAM,EAClB,WAAW,SAAS,KACrB,2BAYF,CAAA"}
|
|
@@ -6,17 +6,16 @@ const calculate_share_data_string_1 = require("../helpers/calculate-share-data-s
|
|
|
6
6
|
/**
|
|
7
7
|
* This function creates the initial crypto data for the share data.
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
9
|
+
* @param privateKey the 32-byte Ed25519 secret seed (hex) to sign with
|
|
10
|
+
* @param shareData the share data to create the initial crypto for
|
|
10
11
|
*/
|
|
11
|
-
const createShareDataInitialCrypto = (privateKey,
|
|
12
|
-
|
|
13
|
-
signingCurve = generic_1.EllipticalCurvesSigning.Curve25519) => {
|
|
14
|
-
const keyPair = (0, generic_1.createKeyPairFromPrivateKey)(signingCurve, privateKey);
|
|
12
|
+
const createShareDataInitialCrypto = (privateKey, shareData) => {
|
|
13
|
+
const publicKey = (0, generic_1.getEd25519PublicKeyFromPrivateKey)(privateKey);
|
|
15
14
|
const shareDataString = (0, calculate_share_data_string_1.calculateShareDataString)(shareData);
|
|
16
15
|
const shareDataHash = (0, generic_1.calculateHash)(shareDataString);
|
|
17
|
-
const shareDataSignature = (0, generic_1.
|
|
16
|
+
const shareDataSignature = (0, generic_1.createEd25519Signature)(privateKey, shareDataHash);
|
|
18
17
|
const initialCryptoData = {
|
|
19
|
-
publicKey
|
|
18
|
+
publicKey,
|
|
20
19
|
shareDataHash,
|
|
21
20
|
shareDataSignature,
|
|
22
21
|
timestamp: Date.now(),
|
|
@@ -1 +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,
|
|
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,gBAoB1C,CAAC"}
|
|
@@ -16,6 +16,11 @@ exports.defaultShareDataStringConfig = [
|
|
|
16
16
|
{ key: 'currentState', process: stringify_1.stringify },
|
|
17
17
|
{ key: 'cryptoProofs', process: get_array_string_1.getArrayString },
|
|
18
18
|
{ key: 'structuralProofs', process: get_array_string_1.getArrayString },
|
|
19
|
+
// Folds the delegated authorized-signer set into the signed structure so a
|
|
20
|
+
// tampered snapshot cannot widen authorization without breaking the hash
|
|
21
|
+
// chain. `getArrayString([])` returns '', so blocks with no delegates hash
|
|
22
|
+
// identically to before this field existed — existing proofs stay valid.
|
|
23
|
+
{ key: 'authorizedSigners', process: get_array_string_1.getArrayString },
|
|
19
24
|
{ key: 'events', process: get_array_string_1.getArrayString },
|
|
20
25
|
{ key: 'functions', process: get_array_string_1.getArrayString },
|
|
21
26
|
{ key: 'rules', process: get_array_string_1.getArrayString },
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IShareData, IShareDataCryptoProof } from '@degenerate/generic';
|
|
2
2
|
import { ShareData } from '../../share-data';
|
|
3
3
|
/**
|
|
4
4
|
* Configuration for the production transaction-proposal signer returned by
|
|
@@ -6,18 +6,13 @@ import { ShareData } from '../../share-data';
|
|
|
6
6
|
*/
|
|
7
7
|
export interface ITransactionProposalSignerConfig {
|
|
8
8
|
/**
|
|
9
|
-
* Hex-encoded
|
|
10
|
-
* (must correspond to its `creationPublicKey`). Captured in the
|
|
11
|
-
* closure and never leaves it. In production this should come from
|
|
12
|
-
* secure key manager (KMS / HSM / encrypted environment value), not a
|
|
9
|
+
* Hex-encoded 32-byte Ed25519 secret seed authorized to mutate the target
|
|
10
|
+
* share-data (must correspond to its `creationPublicKey`). Captured in the
|
|
11
|
+
* returned closure and never leaves it. In production this should come from
|
|
12
|
+
* a secure key manager (KMS / HSM / encrypted environment value), not a
|
|
13
13
|
* literal string in code.
|
|
14
14
|
*/
|
|
15
15
|
privateKey: string;
|
|
16
|
-
/**
|
|
17
|
-
* Elliptical curve to sign with. Defaults to `Curve25519`, matching the
|
|
18
|
-
* `ShareData` constructor default.
|
|
19
|
-
*/
|
|
20
|
-
curve?: EllipticalCurvesSigning;
|
|
21
16
|
}
|
|
22
17
|
/**
|
|
23
18
|
* A bound signer that mints a transaction proposal proof authorizing one
|
|
@@ -1 +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,
|
|
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,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;CACtB;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,yBAQF,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildTransactionProposalSigner = void 0;
|
|
4
|
-
const generic_1 = require("@degenerate/generic");
|
|
5
4
|
const create_transaction_proposal_proof_1 = require("./create-transaction-proposal-proof");
|
|
6
5
|
/**
|
|
7
6
|
* Returns a production-ready {@link TransactionProposalSigner} that signs each
|
|
@@ -30,7 +29,6 @@ const create_transaction_proposal_proof_1 = require("./create-transaction-propos
|
|
|
30
29
|
* replayed for a different amount or a different function.
|
|
31
30
|
*/
|
|
32
31
|
const buildTransactionProposalSigner = (config) => {
|
|
33
|
-
|
|
34
|
-
return (proposedState, functionId, shareData) => (0, create_transaction_proposal_proof_1.createTransactionProposalProof)(config.privateKey, shareData, proposedState, functionId, curve);
|
|
32
|
+
return (proposedState, functionId, shareData) => (0, create_transaction_proposal_proof_1.createTransactionProposalProof)(config.privateKey, shareData, proposedState, functionId);
|
|
35
33
|
};
|
|
36
34
|
exports.buildTransactionProposalSigner = buildTransactionProposalSigner;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IShareDataAdditionalValuesToInclude, IShareDataCryptoProof } from '@degenerate/generic';
|
|
2
2
|
import { ShareData } from '../../share-data';
|
|
3
3
|
/**
|
|
4
4
|
* This function creates a share data proposal proof.
|
|
5
|
-
* @param privateKey the
|
|
5
|
+
* @param privateKey the 32-byte Ed25519 secret seed (hex) to sign the proof with
|
|
6
6
|
* @param shareData the share data object
|
|
7
7
|
* @param additionalValuesToInclude the additional values to include in the share data string
|
|
8
|
-
* @param ellipticalCurve the elliptical curve to use for signing
|
|
9
8
|
* @returns
|
|
10
9
|
*/
|
|
11
|
-
export declare const createShareDataProposalProof: (privateKey: string, shareData: ShareData, additionalValuesToInclude: IShareDataAdditionalValuesToInclude
|
|
10
|
+
export declare const createShareDataProposalProof: (privateKey: string, shareData: ShareData, additionalValuesToInclude: IShareDataAdditionalValuesToInclude) => IShareDataCryptoProof;
|
|
12
11
|
//# sourceMappingURL=create-share-data-proposal-proof.d.ts.map
|
|
@@ -1 +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,
|
|
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,mCAAmC,EACnC,qBAAqB,EACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAI7C;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,GACrC,YAAY,MAAM,EAClB,WAAW,SAAS,EACpB,2BAA2B,mCAAmC,KAC/D,qBA0BF,CAAC"}
|
|
@@ -7,23 +7,22 @@ const get_previous_hash_from_share_data_1 = require("../helpers/get-previous-has
|
|
|
7
7
|
const create_share_data_string_to_sign_1 = require("../helpers/create-share-data-string-to-sign");
|
|
8
8
|
/**
|
|
9
9
|
* This function creates a share data proposal proof.
|
|
10
|
-
* @param privateKey the
|
|
10
|
+
* @param privateKey the 32-byte Ed25519 secret seed (hex) to sign the proof with
|
|
11
11
|
* @param shareData the share data object
|
|
12
12
|
* @param additionalValuesToInclude the additional values to include in the share data string
|
|
13
|
-
* @param ellipticalCurve the elliptical curve to use for signing
|
|
14
13
|
* @returns
|
|
15
14
|
*/
|
|
16
|
-
const createShareDataProposalProof = (privateKey, shareData, additionalValuesToInclude
|
|
17
|
-
const
|
|
15
|
+
const createShareDataProposalProof = (privateKey, shareData, additionalValuesToInclude) => {
|
|
16
|
+
const publicKey = (0, generic_1.getEd25519PublicKeyFromPrivateKey)(privateKey);
|
|
18
17
|
const shareDataString = (0, calculate_share_data_string_1.calculateShareDataString)(shareData, undefined, additionalValuesToInclude);
|
|
19
18
|
const shareDataPreviousHash = (0, get_previous_hash_from_share_data_1.getPreviousHashFromShareData)(shareData);
|
|
20
19
|
const shareDataHash = (0, generic_1.calculateHash)(shareDataString);
|
|
21
20
|
const currentTimestamp = Date.now();
|
|
22
21
|
// calculate the current signature for the share data proof
|
|
23
22
|
const shareDataSignatureString = (0, create_share_data_string_to_sign_1.createShareDataStringToSign)(shareDataHash, shareDataPreviousHash, currentTimestamp);
|
|
24
|
-
const shareDataSignature = (0, generic_1.
|
|
23
|
+
const shareDataSignature = (0, generic_1.createEd25519Signature)(privateKey, shareDataSignatureString);
|
|
25
24
|
const shareDataCryptoProof = {
|
|
26
|
-
publicKey
|
|
25
|
+
publicKey,
|
|
27
26
|
shareDataHash,
|
|
28
27
|
shareDataPreviousHash,
|
|
29
28
|
shareDataSignature,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IShareData, IShareDataCryptoProof } from '@degenerate/generic';
|
|
2
2
|
import { ShareData } from '../../share-data';
|
|
3
3
|
/**
|
|
4
4
|
* Mint a transaction proposal proof: a signed attestation that the holder of
|
|
@@ -17,11 +17,10 @@ import { ShareData } from '../../share-data';
|
|
|
17
17
|
* state it is handed at apply time, so it never needs to be stored in the
|
|
18
18
|
* proof — keeping the wire / persistence / history shape unchanged.
|
|
19
19
|
*
|
|
20
|
-
* @param privateKey
|
|
20
|
+
* @param privateKey 32-byte Ed25519 secret seed (hex) authorized for this share-data
|
|
21
21
|
* @param shareData the share-data the transaction will mutate
|
|
22
22
|
* @param proposedState the exact state the function proposes to apply
|
|
23
23
|
* @param functionId stable id of the function producing `proposedState`
|
|
24
|
-
* @param ellipticalCurve the signing curve (defaults to Curve25519)
|
|
25
24
|
*/
|
|
26
|
-
export declare const createTransactionProposalProof: (privateKey: string, shareData: ShareData, proposedState: IShareData, functionId: string
|
|
25
|
+
export declare const createTransactionProposalProof: (privateKey: string, shareData: ShareData, proposedState: IShareData, functionId: string) => IShareDataCryptoProof;
|
|
27
26
|
//# sourceMappingURL=create-transaction-proposal-proof.d.ts.map
|
|
@@ -1 +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,
|
|
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,UAAU,EACV,qBAAqB,EACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAK7C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,8BAA8B,GACvC,YAAY,MAAM,EAClB,WAAW,SAAS,EACpB,eAAe,UAAU,EACzB,YAAY,MAAM,KACnB,qBAkCF,CAAC"}
|
|
@@ -23,17 +23,16 @@ const hash_proposed_state_1 = require("../helpers/hash-proposed-state");
|
|
|
23
23
|
* state it is handed at apply time, so it never needs to be stored in the
|
|
24
24
|
* proof — keeping the wire / persistence / history shape unchanged.
|
|
25
25
|
*
|
|
26
|
-
* @param privateKey
|
|
26
|
+
* @param privateKey 32-byte Ed25519 secret seed (hex) authorized for this share-data
|
|
27
27
|
* @param shareData the share-data the transaction will mutate
|
|
28
28
|
* @param proposedState the exact state the function proposes to apply
|
|
29
29
|
* @param functionId stable id of the function producing `proposedState`
|
|
30
|
-
* @param ellipticalCurve the signing curve (defaults to Curve25519)
|
|
31
30
|
*/
|
|
32
|
-
const createTransactionProposalProof = (privateKey, shareData, proposedState, functionId
|
|
31
|
+
const createTransactionProposalProof = (privateKey, shareData, proposedState, functionId) => {
|
|
33
32
|
if (typeof functionId !== 'string' || functionId.length < 1) {
|
|
34
33
|
throw new Error('createTransactionProposalProof: functionId is required and must be a non-empty string');
|
|
35
34
|
}
|
|
36
|
-
const
|
|
35
|
+
const publicKey = (0, generic_1.getEd25519PublicKeyFromPrivateKey)(privateKey);
|
|
37
36
|
// Current-state hash uses functionId as the purpose, mirroring how the
|
|
38
37
|
// verifier recomputes it from `proof.purpose`.
|
|
39
38
|
const currentString = (0, calculate_share_data_string_1.calculateShareDataString)(shareData, undefined, { purpose: functionId });
|
|
@@ -42,11 +41,11 @@ const createTransactionProposalProof = (privateKey, shareData, proposedState, fu
|
|
|
42
41
|
const previousHash = (0, get_previous_hash_from_share_data_1.getPreviousHashFromShareData)(shareData);
|
|
43
42
|
const timestamp = Date.now();
|
|
44
43
|
const signedString = (0, create_transaction_proposal_string_to_sign_1.createTransactionProposalStringToSign)(currentHash, proposedStateHash, functionId, previousHash, timestamp);
|
|
45
|
-
const signature = (0, generic_1.
|
|
44
|
+
const signature = (0, generic_1.createEd25519Signature)(privateKey, signedString);
|
|
46
45
|
// Field order mirrors IShareDataCryptoProofSchema exactly — load-bearing,
|
|
47
46
|
// see the schema docs in share-data-crypto-models.ts.
|
|
48
47
|
const proof = {
|
|
49
|
-
publicKey
|
|
48
|
+
publicKey,
|
|
50
49
|
shareDataHash: currentHash,
|
|
51
50
|
shareDataPreviousHash: previousHash,
|
|
52
51
|
shareDataSignature: signature,
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IShareData, IShareDataCryptoProof } from '@degenerate/generic';
|
|
2
2
|
import { ShareData } from '../../share-data';
|
|
3
3
|
/**
|
|
4
|
-
* Generate a fresh
|
|
5
|
-
* in tests. Returns the hex-encoded private and public
|
|
6
|
-
* can use the public half as the ShareData's `creationPublicKey` and the
|
|
4
|
+
* Generate a fresh Ed25519 (EdDSA) keypair suitable for signing ShareData
|
|
5
|
+
* proofs in tests. Returns the hex-encoded private seed and public key so the
|
|
6
|
+
* caller can use the public half as the ShareData's `creationPublicKey` and the
|
|
7
7
|
* private half to mint real signed proofs.
|
|
8
8
|
*
|
|
9
9
|
* Test-only helper — not exported from the package barrel. Real signing
|
|
10
10
|
* keys must come from a key manager in production.
|
|
11
11
|
*/
|
|
12
|
-
export declare const generateTestSigningKey: (
|
|
12
|
+
export declare const generateTestSigningKey: () => {
|
|
13
13
|
privateKey: string;
|
|
14
14
|
publicKey: string;
|
|
15
15
|
};
|
|
@@ -24,7 +24,7 @@ export declare const generateTestSigningKey: (curve?: EllipticalCurvesSigning) =
|
|
|
24
24
|
* `buildEllipticalCurvesProofFor` from `@degenerate/shareblock` which
|
|
25
25
|
* handles the same plumbing through a documented public API.
|
|
26
26
|
*/
|
|
27
|
-
export declare const createTestProofFor: (privateKey: string
|
|
27
|
+
export declare const createTestProofFor: (privateKey: string) => (purpose: string, shareData: ShareData) => IShareDataCryptoProof;
|
|
28
28
|
/**
|
|
29
29
|
* Build a `(proposedState, functionId, shareData) => IShareDataCryptoProof`
|
|
30
30
|
* callback that mints a *transaction* proposal proof (binds the proposed
|
|
@@ -36,7 +36,7 @@ export declare const createTestProofFor: (privateKey: string, curve?: Elliptical
|
|
|
36
36
|
*
|
|
37
37
|
* Test-only helper. Production flows mint these from a key manager.
|
|
38
38
|
*/
|
|
39
|
-
export declare const createTestTransactionProofFor: (privateKey: string
|
|
39
|
+
export declare const createTestTransactionProofFor: (privateKey: string) => (proposedState: IShareData, functionId: string, shareData: ShareData) => IShareDataCryptoProof;
|
|
40
40
|
/**
|
|
41
41
|
* Convenience wrapper: generate a fresh signing keypair AND return a
|
|
42
42
|
* matching proof signer in one call. Returns both so the test can use the
|
|
@@ -44,7 +44,7 @@ export declare const createTestTransactionProofFor: (privateKey: string, curve?:
|
|
|
44
44
|
* structural proofs (addFunction/addRule); `transactionProofFor` mints
|
|
45
45
|
* runtime transaction proposal proofs.
|
|
46
46
|
*/
|
|
47
|
-
export declare const generateTestSigner: (
|
|
47
|
+
export declare const generateTestSigner: () => {
|
|
48
48
|
privateKey: string;
|
|
49
49
|
publicKey: string;
|
|
50
50
|
proofFor: ReturnType<typeof createTestProofFor>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-proof-signer.d.ts","sourceRoot":"","sources":["../../../../src/share-data/proofs/testing/test-proof-signer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"test-proof-signer.d.ts","sourceRoot":"","sources":["../../../../src/share-data/proofs/testing/test-proof-signer.ts"],"names":[],"mappings":"AACA,OAAO,EAEH,UAAU,EACV,qBAAqB,EACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAK7C;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,QAAO;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAMhF,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,GAAI,YAAY,MAAM,MACzC,SAAS,MAAM,EAAE,WAAW,SAAS,KAAG,qBAOnD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,6BAA6B,GAAI,YAAY,MAAM,MAExD,eAAe,UAAU,EACzB,YAAY,MAAM,EAClB,WAAW,SAAS,KACrB,qBAEN,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,QAAO;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC;IAChD,mBAAmB,EAAE,UAAU,CAAC,OAAO,6BAA6B,CAAC,CAAC;CASzE,CAAC"}
|
|
@@ -34,27 +34,25 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.generateTestSigner = exports.createTestTransactionProofFor = exports.createTestProofFor = exports.generateTestSigningKey = void 0;
|
|
37
|
-
|
|
38
|
-
const elliptic = __importStar(require("elliptic"));
|
|
37
|
+
const crypto = __importStar(require("crypto"));
|
|
39
38
|
const generic_1 = require("@degenerate/generic");
|
|
40
39
|
const create_share_data_initial_crypto_1 = require("../../creation/create-share-data-initial-crypto");
|
|
41
40
|
const create_share_data_proposal_proof_1 = require("../creation/create-share-data-proposal-proof");
|
|
42
41
|
const create_transaction_proposal_proof_1 = require("../creation/create-transaction-proposal-proof");
|
|
43
42
|
/**
|
|
44
|
-
* Generate a fresh
|
|
45
|
-
* in tests. Returns the hex-encoded private and public
|
|
46
|
-
* can use the public half as the ShareData's `creationPublicKey` and the
|
|
43
|
+
* Generate a fresh Ed25519 (EdDSA) keypair suitable for signing ShareData
|
|
44
|
+
* proofs in tests. Returns the hex-encoded private seed and public key so the
|
|
45
|
+
* caller can use the public half as the ShareData's `creationPublicKey` and the
|
|
47
46
|
* private half to mint real signed proofs.
|
|
48
47
|
*
|
|
49
48
|
* Test-only helper — not exported from the package barrel. Real signing
|
|
50
49
|
* keys must come from a key manager in production.
|
|
51
50
|
*/
|
|
52
|
-
const generateTestSigningKey = (
|
|
53
|
-
const
|
|
54
|
-
const keyPair = ec.genKeyPair();
|
|
51
|
+
const generateTestSigningKey = () => {
|
|
52
|
+
const privateKey = crypto.randomBytes(32).toString('hex');
|
|
55
53
|
return {
|
|
56
|
-
privateKey
|
|
57
|
-
publicKey:
|
|
54
|
+
privateKey,
|
|
55
|
+
publicKey: (0, generic_1.getEd25519PublicKeyFromPrivateKey)(privateKey),
|
|
58
56
|
};
|
|
59
57
|
};
|
|
60
58
|
exports.generateTestSigningKey = generateTestSigningKey;
|
|
@@ -69,13 +67,13 @@ exports.generateTestSigningKey = generateTestSigningKey;
|
|
|
69
67
|
* `buildEllipticalCurvesProofFor` from `@degenerate/shareblock` which
|
|
70
68
|
* handles the same plumbing through a documented public API.
|
|
71
69
|
*/
|
|
72
|
-
const createTestProofFor = (privateKey
|
|
70
|
+
const createTestProofFor = (privateKey) => {
|
|
73
71
|
return (purpose, shareData) => {
|
|
74
72
|
if (!shareData.creationHash && shareData.structuralProofs.length === 0) {
|
|
75
|
-
const initialCrypto = (0, create_share_data_initial_crypto_1.createShareDataInitialCrypto)(privateKey, shareData
|
|
73
|
+
const initialCrypto = (0, create_share_data_initial_crypto_1.createShareDataInitialCrypto)(privateKey, shareData);
|
|
76
74
|
shareData.initializeCrypto(initialCrypto);
|
|
77
75
|
}
|
|
78
|
-
return (0, create_share_data_proposal_proof_1.createShareDataProposalProof)(privateKey, shareData, { purpose }
|
|
76
|
+
return (0, create_share_data_proposal_proof_1.createShareDataProposalProof)(privateKey, shareData, { purpose });
|
|
79
77
|
};
|
|
80
78
|
};
|
|
81
79
|
exports.createTestProofFor = createTestProofFor;
|
|
@@ -90,8 +88,8 @@ exports.createTestProofFor = createTestProofFor;
|
|
|
90
88
|
*
|
|
91
89
|
* Test-only helper. Production flows mint these from a key manager.
|
|
92
90
|
*/
|
|
93
|
-
const createTestTransactionProofFor = (privateKey
|
|
94
|
-
return (proposedState, functionId, shareData) => (0, create_transaction_proposal_proof_1.createTransactionProposalProof)(privateKey, shareData, proposedState, functionId
|
|
91
|
+
const createTestTransactionProofFor = (privateKey) => {
|
|
92
|
+
return (proposedState, functionId, shareData) => (0, create_transaction_proposal_proof_1.createTransactionProposalProof)(privateKey, shareData, proposedState, functionId);
|
|
95
93
|
};
|
|
96
94
|
exports.createTestTransactionProofFor = createTestTransactionProofFor;
|
|
97
95
|
/**
|
|
@@ -101,13 +99,13 @@ exports.createTestTransactionProofFor = createTestTransactionProofFor;
|
|
|
101
99
|
* structural proofs (addFunction/addRule); `transactionProofFor` mints
|
|
102
100
|
* runtime transaction proposal proofs.
|
|
103
101
|
*/
|
|
104
|
-
const generateTestSigner = (
|
|
105
|
-
const { privateKey, publicKey } = (0, exports.generateTestSigningKey)(
|
|
102
|
+
const generateTestSigner = () => {
|
|
103
|
+
const { privateKey, publicKey } = (0, exports.generateTestSigningKey)();
|
|
106
104
|
return {
|
|
107
105
|
privateKey,
|
|
108
106
|
publicKey,
|
|
109
|
-
proofFor: (0, exports.createTestProofFor)(privateKey
|
|
110
|
-
transactionProofFor: (0, exports.createTestTransactionProofFor)(privateKey
|
|
107
|
+
proofFor: (0, exports.createTestProofFor)(privateKey),
|
|
108
|
+
transactionProofFor: (0, exports.createTestTransactionProofFor)(privateKey),
|
|
111
109
|
};
|
|
112
110
|
};
|
|
113
111
|
exports.generateTestSigner = generateTestSigner;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IShareDataCryptoProof } from '@degenerate/generic';
|
|
2
2
|
import { ShareData } from '../../share-data';
|
|
3
3
|
/**
|
|
4
4
|
* Verifies that an `IShareDataCryptoProof` is a faithful attestation of the
|
|
@@ -12,10 +12,8 @@ import { ShareData } from '../../share-data';
|
|
|
12
12
|
* requires the private key).
|
|
13
13
|
*
|
|
14
14
|
* Synchronous on purpose — `addFunction` / `addRule` are synchronous and we
|
|
15
|
-
* don't want to cascade-async every caller in the codebase.
|
|
16
|
-
* `
|
|
17
|
-
* project's existing `verifyCryptoSignatureByHash` wrapper is `async` only
|
|
18
|
-
* cosmetically.
|
|
15
|
+
* don't want to cascade-async every caller in the codebase. `@noble/ed25519`'s
|
|
16
|
+
* `verify` is itself synchronous (backed by a synchronous SHA-512 hook).
|
|
19
17
|
*
|
|
20
18
|
* Verification proceeds in this order:
|
|
21
19
|
* 1. Recompute the canonical share-data string + hash, folding in
|
|
@@ -36,5 +34,5 @@ import { ShareData } from '../../share-data';
|
|
|
36
34
|
* `(hash, previousHash, timestamp)` triple, not that the hash matches
|
|
37
35
|
* anything real.
|
|
38
36
|
*/
|
|
39
|
-
export declare const verifyShareDataProposalProof: (proof: IShareDataCryptoProof, shareData: ShareData
|
|
37
|
+
export declare const verifyShareDataProposalProof: (proof: IShareDataCryptoProof, shareData: ShareData) => true;
|
|
40
38
|
//# sourceMappingURL=verify-share-data-proposal-proof.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify-share-data-proposal-proof.d.ts","sourceRoot":"","sources":["../../../../src/share-data/proofs/verification/verify-share-data-proposal-proof.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"verify-share-data-proposal-proof.d.ts","sourceRoot":"","sources":["../../../../src/share-data/proofs/verification/verify-share-data-proposal-proof.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,qBAAqB,EAGxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAI7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,4BAA4B,GACrC,OAAO,qBAAqB,EAC5B,WAAW,SAAS,KACrB,IAwCF,CAAC"}
|
|
@@ -1,40 +1,6 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.verifyShareDataProposalProof = void 0;
|
|
37
|
-
const elliptic = __importStar(require("elliptic"));
|
|
38
4
|
const generic_1 = require("@degenerate/generic");
|
|
39
5
|
const calculate_share_data_string_1 = require("../../helpers/calculate-share-data-string");
|
|
40
6
|
const get_previous_hash_from_share_data_1 = require("../helpers/get-previous-hash-from-share-data");
|
|
@@ -51,10 +17,8 @@ const create_share_data_string_to_sign_1 = require("../helpers/create-share-data
|
|
|
51
17
|
* requires the private key).
|
|
52
18
|
*
|
|
53
19
|
* Synchronous on purpose — `addFunction` / `addRule` are synchronous and we
|
|
54
|
-
* don't want to cascade-async every caller in the codebase.
|
|
55
|
-
* `
|
|
56
|
-
* project's existing `verifyCryptoSignatureByHash` wrapper is `async` only
|
|
57
|
-
* cosmetically.
|
|
20
|
+
* don't want to cascade-async every caller in the codebase. `@noble/ed25519`'s
|
|
21
|
+
* `verify` is itself synchronous (backed by a synchronous SHA-512 hook).
|
|
58
22
|
*
|
|
59
23
|
* Verification proceeds in this order:
|
|
60
24
|
* 1. Recompute the canonical share-data string + hash, folding in
|
|
@@ -75,7 +39,7 @@ const create_share_data_string_to_sign_1 = require("../helpers/create-share-data
|
|
|
75
39
|
* `(hash, previousHash, timestamp)` triple, not that the hash matches
|
|
76
40
|
* anything real.
|
|
77
41
|
*/
|
|
78
|
-
const verifyShareDataProposalProof = (proof, shareData
|
|
42
|
+
const verifyShareDataProposalProof = (proof, shareData) => {
|
|
79
43
|
// Step 1: hash of current state matches what the proof claims. The
|
|
80
44
|
// purpose comes from the proof itself, so a tampered purpose produces
|
|
81
45
|
// a different hash and gets caught here.
|
|
@@ -101,24 +65,11 @@ const verifyShareDataProposalProof = (proof, shareData, ellipticalCurve = generi
|
|
|
101
65
|
// Step 3: signature verifies against the proof's publicKey for the
|
|
102
66
|
// (now-validated) hash + previousHash + timestamp triple.
|
|
103
67
|
const signedString = (0, create_share_data_string_to_sign_1.createShareDataStringToSign)(proof.shareDataHash, proof.shareDataPreviousHash, proof.timestamp);
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// so the verifier sees the same fixed-size 256-bit digest the signer
|
|
110
|
-
// operated on. Without this, elliptic's ECDSA on ed25519 silently
|
|
111
|
-
// truncates inputs longer than ~253 bits and the signature stops
|
|
112
|
-
// binding the trailing bytes (timestamp, tail of previousHash).
|
|
113
|
-
const digest = (0, generic_1.calculateHash)(signedString);
|
|
114
|
-
signatureValid = key.verify(digest, proof.shareDataSignature);
|
|
115
|
-
}
|
|
116
|
-
catch {
|
|
117
|
-
// elliptic throws on malformed signature/key strings rather than
|
|
118
|
-
// returning false — normalize to a single rejection mode.
|
|
119
|
-
throw new generic_1.ShareDataStructuralProofFailedError(shareData.id);
|
|
120
|
-
}
|
|
121
|
-
if (!signatureValid) {
|
|
68
|
+
// EdDSA signs the message bytes directly (Ed25519 hashes internally with
|
|
69
|
+
// SHA-512), so no SHA-256 pre-hash here — the signer didn't pre-hash either.
|
|
70
|
+
// `verifyEd25519Signature` already normalizes malformed key/signature hex
|
|
71
|
+
// to a `false` return rather than throwing.
|
|
72
|
+
if (!(0, generic_1.verifyEd25519Signature)(proof.publicKey, signedString, proof.shareDataSignature)) {
|
|
122
73
|
throw new generic_1.ShareDataStructuralProofFailedError(shareData.id);
|
|
123
74
|
}
|
|
124
75
|
return true;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IShareData, IShareDataCryptoProof } from '@degenerate/generic';
|
|
2
2
|
import { ShareData } from '../../share-data';
|
|
3
3
|
/**
|
|
4
4
|
* Verify a transaction proposal proof against the live `shareData` and the
|
|
@@ -30,8 +30,8 @@ import { ShareData } from '../../share-data';
|
|
|
30
30
|
* hash, a structural proof's signature can never satisfy this check — the two
|
|
31
31
|
* proof kinds are non-interchangeable.
|
|
32
32
|
*
|
|
33
|
-
* Synchronous to match the rest of the proof pipeline;
|
|
34
|
-
* is itself synchronous.
|
|
33
|
+
* Synchronous to match the rest of the proof pipeline; `@noble/ed25519`'s
|
|
34
|
+
* `verify` is itself synchronous.
|
|
35
35
|
*/
|
|
36
|
-
export declare const verifyTransactionProposalProof: (proof: IShareDataCryptoProof, shareData: ShareData, proposedState: IShareData
|
|
36
|
+
export declare const verifyTransactionProposalProof: (proof: IShareDataCryptoProof, shareData: ShareData, proposedState: IShareData) => true;
|
|
37
37
|
//# sourceMappingURL=verify-transaction-proposal-proof.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify-transaction-proposal-proof.d.ts","sourceRoot":"","sources":["../../../../src/share-data/proofs/verification/verify-transaction-proposal-proof.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"verify-transaction-proposal-proof.d.ts","sourceRoot":"","sources":["../../../../src/share-data/proofs/verification/verify-transaction-proposal-proof.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,UAAU,EACV,qBAAqB,EAGxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAK7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,8BAA8B,GACvC,OAAO,qBAAqB,EAC5B,WAAW,SAAS,EACpB,eAAe,UAAU,KAC1B,IA6CF,CAAC"}
|
|
@@ -1,40 +1,6 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.verifyTransactionProposalProof = void 0;
|
|
37
|
-
const elliptic = __importStar(require("elliptic"));
|
|
38
4
|
const generic_1 = require("@degenerate/generic");
|
|
39
5
|
const calculate_share_data_string_1 = require("../../helpers/calculate-share-data-string");
|
|
40
6
|
const get_previous_hash_from_share_data_1 = require("../helpers/get-previous-hash-from-share-data");
|
|
@@ -70,10 +36,10 @@ const hash_proposed_state_1 = require("../helpers/hash-proposed-state");
|
|
|
70
36
|
* hash, a structural proof's signature can never satisfy this check — the two
|
|
71
37
|
* proof kinds are non-interchangeable.
|
|
72
38
|
*
|
|
73
|
-
* Synchronous to match the rest of the proof pipeline;
|
|
74
|
-
* is itself synchronous.
|
|
39
|
+
* Synchronous to match the rest of the proof pipeline; `@noble/ed25519`'s
|
|
40
|
+
* `verify` is itself synchronous.
|
|
75
41
|
*/
|
|
76
|
-
const verifyTransactionProposalProof = (proof, shareData, proposedState
|
|
42
|
+
const verifyTransactionProposalProof = (proof, shareData, proposedState) => {
|
|
77
43
|
// Step 1: current-state hash matches what the proof claims. The purpose
|
|
78
44
|
// (functionId) comes from the proof itself, so a tampered purpose
|
|
79
45
|
// produces a different hash and is caught here.
|
|
@@ -101,23 +67,11 @@ const verifyTransactionProposalProof = (proof, shareData, proposedState, ellipti
|
|
|
101
67
|
// Step 4: signature verifies over the full transaction payload (which
|
|
102
68
|
// includes the proposed-state hash and the `tx:` discriminator).
|
|
103
69
|
const signedString = (0, create_transaction_proposal_string_to_sign_1.createTransactionProposalStringToSign)(proof.shareDataHash, proposedStateHash, proof.purpose, proof.shareDataPreviousHash, proof.timestamp);
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// so the verifier operates on the same fixed-size digest the signer
|
|
110
|
-
// did. Without this, elliptic's ECDSA on ed25519 silently truncates
|
|
111
|
-
// long inputs and stops binding the trailing bytes.
|
|
112
|
-
const digest = (0, generic_1.calculateHash)(signedString);
|
|
113
|
-
signatureValid = key.verify(digest, proof.shareDataSignature);
|
|
114
|
-
}
|
|
115
|
-
catch {
|
|
116
|
-
// elliptic throws on malformed signature/key strings rather than
|
|
117
|
-
// returning false — normalize to a single rejection mode.
|
|
118
|
-
throw new generic_1.ShareDataTransactionProofFailedError(shareData.id);
|
|
119
|
-
}
|
|
120
|
-
if (!signatureValid) {
|
|
70
|
+
// EdDSA signs the message bytes directly (Ed25519 hashes internally with
|
|
71
|
+
// SHA-512), so no SHA-256 pre-hash here — the signer didn't pre-hash either.
|
|
72
|
+
// `verifyEd25519Signature` already normalizes malformed key/signature hex
|
|
73
|
+
// to a `false` return rather than throwing.
|
|
74
|
+
if (!(0, generic_1.verifyEd25519Signature)(proof.publicKey, signedString, proof.shareDataSignature)) {
|
|
121
75
|
throw new generic_1.ShareDataTransactionProofFailedError(shareData.id);
|
|
122
76
|
}
|
|
123
77
|
return true;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IShareData, IShareDataEvent, IShareFunction, IShareRuleApplied, IShareRuleEvalutionResult, IShareDataTransactionHistory, IShareDataCryptoProof, EllipticalCurvesSigning, IShareDataInitialCryptoData } from '@degenerate/generic';
|
|
1
|
+
import { IShareData, IShareDataEvent, IShareFunction, IShareRuleApplied, IShareRuleEvalutionResult, IShareDataTransactionHistory, IShareDataCryptoProof, EllipticalCurvesSigning, IShareDataInitialCryptoData, IAuthorizedSigner } from '@degenerate/generic';
|
|
2
2
|
/**
|
|
3
3
|
* This contains the interface for the share data object
|
|
4
4
|
*/
|
|
@@ -18,6 +18,7 @@ export declare class ShareData {
|
|
|
18
18
|
private _signingCurve;
|
|
19
19
|
private _lastUpdated;
|
|
20
20
|
private _structuralProofs;
|
|
21
|
+
private _authorizedSigners;
|
|
21
22
|
/**
|
|
22
23
|
* This is the constructor for the share data object
|
|
23
24
|
* @param id the id of the share data
|
|
@@ -90,6 +91,14 @@ export declare class ShareData {
|
|
|
90
91
|
* This gets the structure proofs for the share data
|
|
91
92
|
*/
|
|
92
93
|
get structuralProofs(): IShareDataCryptoProof[];
|
|
94
|
+
/**
|
|
95
|
+
* This gets the delegated authorized-signer grants for the share data.
|
|
96
|
+
* Each grant is a `{ publicKey, functionIds }` pair: a key the owner has
|
|
97
|
+
* delegated the right to propose transactions for, scoped to those function
|
|
98
|
+
* ids. The block owner (`creationPublicKey`) is always authorized and is
|
|
99
|
+
* NOT listed here.
|
|
100
|
+
*/
|
|
101
|
+
get authorizedSigners(): IAuthorizedSigner[];
|
|
93
102
|
/**
|
|
94
103
|
* This gets the transaction history for the share block
|
|
95
104
|
*/
|
|
@@ -113,6 +122,49 @@ export declare class ShareData {
|
|
|
113
122
|
* @param rule the rule to add to the share block
|
|
114
123
|
*/
|
|
115
124
|
addRule(rule: IShareRuleApplied, cryptoProof: IShareDataCryptoProof): void;
|
|
125
|
+
/**
|
|
126
|
+
* Delegates `signerPublicKey` the right to propose runtime transactions for
|
|
127
|
+
* the given `functionIds` (and ONLY those — least privilege). Creation-time
|
|
128
|
+
* only: rejected once the block is locked. The registration is part of the
|
|
129
|
+
* signed structure, so a delegate cannot be injected into a tampered
|
|
130
|
+
* snapshot without invalidating the chain.
|
|
131
|
+
*
|
|
132
|
+
* Three gates, in order:
|
|
133
|
+
* 1. Owner-identity: `registrationProof.publicKey === creationPublicKey`.
|
|
134
|
+
* ONLY the block owner may delegate — this is the check `addFunction` /
|
|
135
|
+
* `addRule` deliberately omit (the HTTP layer supplies it there). It
|
|
136
|
+
* must live here because the security of the widened transaction gate
|
|
137
|
+
* (see {@link isAuthorizedSigner}) rests on "the allow-list was
|
|
138
|
+
* authorized by the owner." It also blocks transitive delegation: a
|
|
139
|
+
* delegate's key is never the creation key, so a delegate can never
|
|
140
|
+
* register further delegates.
|
|
141
|
+
* 2. Grant binding: the proof's `purpose` must equal
|
|
142
|
+
* `buildDelegatePurpose(signerPublicKey, functionIds)`. The proof signs
|
|
143
|
+
* over the PRE-append state (the grant is not yet folded into
|
|
144
|
+
* `_authorizedSigners`), so the purpose is the only thing that attests
|
|
145
|
+
* to the exact `(key, functionIds)` grant — without this a tampered
|
|
146
|
+
* snapshot could widen a delegate's scope without breaking the
|
|
147
|
+
* signature.
|
|
148
|
+
* 3. Structural verification against the current (pre-append) state,
|
|
149
|
+
* reusing the same machinery `addFunction` / `addRule` use; folds the
|
|
150
|
+
* proof into the hash chain and verifies the owner's signature.
|
|
151
|
+
*
|
|
152
|
+
* Throws {@link ShareDataIsLockedError} if locked,
|
|
153
|
+
* {@link ShareDataDelegationNotAuthorizedError} for a non-owner registrant /
|
|
154
|
+
* empty grant / mismatched purpose, and
|
|
155
|
+
* {@link ShareDataStructuralProofFailedError} if the proof does not verify.
|
|
156
|
+
*/
|
|
157
|
+
addAuthorizedSigner(signerPublicKey: string, functionIds: string[], registrationProof: IShareDataCryptoProof): void;
|
|
158
|
+
/**
|
|
159
|
+
* Whether `publicKey` is authorized to propose a transaction for
|
|
160
|
+
* `functionId` on this block. The block owner (`creationPublicKey`) is
|
|
161
|
+
* always authorized for every function; a delegated key is authorized only
|
|
162
|
+
* for the function ids its registration granted. This is the single
|
|
163
|
+
* predicate behind the proposer-identity gate, called from both the live
|
|
164
|
+
* mutation path ({@link addTransaction}) and the persistence replay path so
|
|
165
|
+
* the two cannot drift.
|
|
166
|
+
*/
|
|
167
|
+
isAuthorizedSigner(publicKey: string, functionId: string): boolean;
|
|
116
168
|
/**
|
|
117
169
|
* Append a pre-validated transaction to the history. Pass `transactionTime`
|
|
118
170
|
* when the caller needs the recorded timestamp to be deterministic — for
|
|
@@ -159,12 +211,12 @@ export declare class ShareData {
|
|
|
159
211
|
* This binds the proof to *this* function so a proof minted for one
|
|
160
212
|
* function can't be replayed to drive another even if the proposed
|
|
161
213
|
* state would satisfy both functions' rules.
|
|
162
|
-
* 3. The proof's signer must be authorized for this block
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
214
|
+
* 3. The proof's signer must be authorized for this block AND this
|
|
215
|
+
* function — the creation key for any function, or a delegated key for
|
|
216
|
+
* the function ids its registration granted (`isAuthorizedSigner`).
|
|
217
|
+
* Signature validity alone only proves *someone* signed the transition;
|
|
218
|
+
* this binds the *authorized* someone. Without it any valid keypair
|
|
219
|
+
* could sign a legal transition.
|
|
168
220
|
* 4. The proof must verify against the current state AND `proposedData`
|
|
169
221
|
* (closes the amount-replay hole — see
|
|
170
222
|
* `verifyTransactionProposalProof`).
|
|
@@ -206,7 +258,7 @@ export declare class ShareData {
|
|
|
206
258
|
* success; throws `ShareDataStructuralProofFailedError` on any mismatch
|
|
207
259
|
* (hash, previousHash, signature, or purpose).
|
|
208
260
|
*/
|
|
209
|
-
verifyStructuralProof(proof: IShareDataCryptoProof
|
|
261
|
+
verifyStructuralProof(proof: IShareDataCryptoProof): true;
|
|
210
262
|
/**
|
|
211
263
|
* Verifies that `proof` authorizes applying a transaction that moves this
|
|
212
264
|
* share-data to exactly `proposedData`. Unlike {@link verifyStructuralProof}
|
|
@@ -215,7 +267,7 @@ export declare class ShareData {
|
|
|
215
267
|
* verify against any other. Returns `true`; throws
|
|
216
268
|
* `ShareDataTransactionProofFailedError` on any mismatch.
|
|
217
269
|
*/
|
|
218
|
-
verifyTransactionProof(proof: IShareDataCryptoProof, proposedData: IShareData
|
|
270
|
+
verifyTransactionProof(proof: IShareDataCryptoProof, proposedData: IShareData): true;
|
|
219
271
|
/**
|
|
220
272
|
* This adds a structure proof to the share data
|
|
221
273
|
* @param proof the structure proof to add
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"share-data.d.ts","sourceRoot":"","sources":["../../src/share-data/share-data.ts"],"names":[],"mappings":"AACA,OAAO,EACH,UAAU,EACV,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,yBAAyB,EACzB,4BAA4B,EAG5B,qBAAqB,EAErB,uBAAuB,EACvB,2BAA2B,
|
|
1
|
+
{"version":3,"file":"share-data.d.ts","sourceRoot":"","sources":["../../src/share-data/share-data.ts"],"names":[],"mappings":"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"}
|
|
@@ -30,6 +30,7 @@ class ShareData {
|
|
|
30
30
|
this._cryptoProofs = [];
|
|
31
31
|
this._signingCurve = signingCurve;
|
|
32
32
|
this._structuralProofs = [];
|
|
33
|
+
this._authorizedSigners = [];
|
|
33
34
|
}
|
|
34
35
|
/**
|
|
35
36
|
* This initializes the cryptographic properties of the share data
|
|
@@ -139,6 +140,16 @@ class ShareData {
|
|
|
139
140
|
get structuralProofs() {
|
|
140
141
|
return this._structuralProofs;
|
|
141
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* This gets the delegated authorized-signer grants for the share data.
|
|
145
|
+
* Each grant is a `{ publicKey, functionIds }` pair: a key the owner has
|
|
146
|
+
* delegated the right to propose transactions for, scoped to those function
|
|
147
|
+
* ids. The block owner (`creationPublicKey`) is always authorized and is
|
|
148
|
+
* NOT listed here.
|
|
149
|
+
*/
|
|
150
|
+
get authorizedSigners() {
|
|
151
|
+
return this._authorizedSigners;
|
|
152
|
+
}
|
|
142
153
|
/**
|
|
143
154
|
* This gets the transaction history for the share block
|
|
144
155
|
*/
|
|
@@ -189,6 +200,78 @@ class ShareData {
|
|
|
189
200
|
this._structuralProofs.push(cryptoProof);
|
|
190
201
|
this._rules.push(rule);
|
|
191
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Delegates `signerPublicKey` the right to propose runtime transactions for
|
|
205
|
+
* the given `functionIds` (and ONLY those — least privilege). Creation-time
|
|
206
|
+
* only: rejected once the block is locked. The registration is part of the
|
|
207
|
+
* signed structure, so a delegate cannot be injected into a tampered
|
|
208
|
+
* snapshot without invalidating the chain.
|
|
209
|
+
*
|
|
210
|
+
* Three gates, in order:
|
|
211
|
+
* 1. Owner-identity: `registrationProof.publicKey === creationPublicKey`.
|
|
212
|
+
* ONLY the block owner may delegate — this is the check `addFunction` /
|
|
213
|
+
* `addRule` deliberately omit (the HTTP layer supplies it there). It
|
|
214
|
+
* must live here because the security of the widened transaction gate
|
|
215
|
+
* (see {@link isAuthorizedSigner}) rests on "the allow-list was
|
|
216
|
+
* authorized by the owner." It also blocks transitive delegation: a
|
|
217
|
+
* delegate's key is never the creation key, so a delegate can never
|
|
218
|
+
* register further delegates.
|
|
219
|
+
* 2. Grant binding: the proof's `purpose` must equal
|
|
220
|
+
* `buildDelegatePurpose(signerPublicKey, functionIds)`. The proof signs
|
|
221
|
+
* over the PRE-append state (the grant is not yet folded into
|
|
222
|
+
* `_authorizedSigners`), so the purpose is the only thing that attests
|
|
223
|
+
* to the exact `(key, functionIds)` grant — without this a tampered
|
|
224
|
+
* snapshot could widen a delegate's scope without breaking the
|
|
225
|
+
* signature.
|
|
226
|
+
* 3. Structural verification against the current (pre-append) state,
|
|
227
|
+
* reusing the same machinery `addFunction` / `addRule` use; folds the
|
|
228
|
+
* proof into the hash chain and verifies the owner's signature.
|
|
229
|
+
*
|
|
230
|
+
* Throws {@link ShareDataIsLockedError} if locked,
|
|
231
|
+
* {@link ShareDataDelegationNotAuthorizedError} for a non-owner registrant /
|
|
232
|
+
* empty grant / mismatched purpose, and
|
|
233
|
+
* {@link ShareDataStructuralProofFailedError} if the proof does not verify.
|
|
234
|
+
*/
|
|
235
|
+
addAuthorizedSigner(signerPublicKey, functionIds, registrationProof) {
|
|
236
|
+
if (this._isLocked) {
|
|
237
|
+
throw new generic_1.ShareDataIsLockedError(this._id, generic_1.ShareDataTypes.AUTHORIZATION);
|
|
238
|
+
}
|
|
239
|
+
// Gate 1: owner-identity. Only the creation key may delegate.
|
|
240
|
+
if (registrationProof.publicKey !== this._creationPublicKey) {
|
|
241
|
+
throw new generic_1.ShareDataDelegationNotAuthorizedError(this._id, registrationProof.publicKey);
|
|
242
|
+
}
|
|
243
|
+
// Normalize so the purpose, the stored grant, and the canonical hash all
|
|
244
|
+
// agree byte-for-byte on live-create and on replay.
|
|
245
|
+
const normalizedFunctionIds = Array.from(new Set(functionIds.map((id) => id.trim()).filter((id) => id.length > 0))).sort();
|
|
246
|
+
if (normalizedFunctionIds.length === 0) {
|
|
247
|
+
throw new generic_1.ShareDataDelegationNotAuthorizedError(this._id, registrationProof.publicKey);
|
|
248
|
+
}
|
|
249
|
+
// Gate 2: the proof must bind this exact (key, functionIds) grant.
|
|
250
|
+
const expectedPurpose = (0, generic_1.buildDelegatePurpose)(signerPublicKey, normalizedFunctionIds);
|
|
251
|
+
if (registrationProof.purpose !== expectedPurpose) {
|
|
252
|
+
throw new generic_1.ShareDataDelegationNotAuthorizedError(this._id, registrationProof.publicKey);
|
|
253
|
+
}
|
|
254
|
+
// Gate 3: structural verification (pre-append, mirroring addFunction).
|
|
255
|
+
this.verifyStructuralProof(registrationProof);
|
|
256
|
+
this._structuralProofs.push(registrationProof);
|
|
257
|
+
this._authorizedSigners.push({ publicKey: signerPublicKey, functionIds: normalizedFunctionIds });
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Whether `publicKey` is authorized to propose a transaction for
|
|
261
|
+
* `functionId` on this block. The block owner (`creationPublicKey`) is
|
|
262
|
+
* always authorized for every function; a delegated key is authorized only
|
|
263
|
+
* for the function ids its registration granted. This is the single
|
|
264
|
+
* predicate behind the proposer-identity gate, called from both the live
|
|
265
|
+
* mutation path ({@link addTransaction}) and the persistence replay path so
|
|
266
|
+
* the two cannot drift.
|
|
267
|
+
*/
|
|
268
|
+
isAuthorizedSigner(publicKey, functionId) {
|
|
269
|
+
if (publicKey === this._creationPublicKey) {
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
const grant = this._authorizedSigners.find((s) => s.publicKey === publicKey);
|
|
273
|
+
return grant !== undefined && grant.functionIds.includes(functionId);
|
|
274
|
+
}
|
|
192
275
|
/**
|
|
193
276
|
* Append a pre-validated transaction to the history. Pass `transactionTime`
|
|
194
277
|
* when the caller needs the recorded timestamp to be deterministic — for
|
|
@@ -254,12 +337,12 @@ class ShareData {
|
|
|
254
337
|
* This binds the proof to *this* function so a proof minted for one
|
|
255
338
|
* function can't be replayed to drive another even if the proposed
|
|
256
339
|
* state would satisfy both functions' rules.
|
|
257
|
-
* 3. The proof's signer must be authorized for this block
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
340
|
+
* 3. The proof's signer must be authorized for this block AND this
|
|
341
|
+
* function — the creation key for any function, or a delegated key for
|
|
342
|
+
* the function ids its registration granted (`isAuthorizedSigner`).
|
|
343
|
+
* Signature validity alone only proves *someone* signed the transition;
|
|
344
|
+
* this binds the *authorized* someone. Without it any valid keypair
|
|
345
|
+
* could sign a legal transition.
|
|
263
346
|
* 4. The proof must verify against the current state AND `proposedData`
|
|
264
347
|
* (closes the amount-replay hole — see
|
|
265
348
|
* `verifyTransactionProposalProof`).
|
|
@@ -289,10 +372,14 @@ class ShareData {
|
|
|
289
372
|
if (proof.purpose !== functionId) {
|
|
290
373
|
throw new generic_1.ShareDataTransactionProofFailedError(this._id);
|
|
291
374
|
}
|
|
292
|
-
// Gate 3: bind the proposer identity.
|
|
293
|
-
// authorize
|
|
294
|
-
//
|
|
295
|
-
|
|
375
|
+
// Gate 3: bind the proposer identity. The block's creation key may
|
|
376
|
+
// authorize any function; a delegated key may authorize only the
|
|
377
|
+
// function ids it was granted (see addAuthorizedSigner / isAuthorizedSigner).
|
|
378
|
+
// `functionId` equals `proof.purpose` here (enforced by Gate 2), so the
|
|
379
|
+
// scope check is against the function the proof is bound to. Checked
|
|
380
|
+
// before the (more expensive) signature verification so an unauthorized
|
|
381
|
+
// signer fails fast.
|
|
382
|
+
if (!this.isAuthorizedSigner(proof.publicKey, functionId)) {
|
|
296
383
|
throw new generic_1.ShareDataTransactionNotAuthorizedError(this._id, proof.publicKey);
|
|
297
384
|
}
|
|
298
385
|
// Gate 4: proof binds current state + proposed state + chain position.
|
|
@@ -361,8 +448,8 @@ class ShareData {
|
|
|
361
448
|
* success; throws `ShareDataStructuralProofFailedError` on any mismatch
|
|
362
449
|
* (hash, previousHash, signature, or purpose).
|
|
363
450
|
*/
|
|
364
|
-
verifyStructuralProof(proof
|
|
365
|
-
return (0, verify_share_data_proposal_proof_1.verifyShareDataProposalProof)(proof, this
|
|
451
|
+
verifyStructuralProof(proof) {
|
|
452
|
+
return (0, verify_share_data_proposal_proof_1.verifyShareDataProposalProof)(proof, this);
|
|
366
453
|
}
|
|
367
454
|
/**
|
|
368
455
|
* Verifies that `proof` authorizes applying a transaction that moves this
|
|
@@ -372,8 +459,8 @@ class ShareData {
|
|
|
372
459
|
* verify against any other. Returns `true`; throws
|
|
373
460
|
* `ShareDataTransactionProofFailedError` on any mismatch.
|
|
374
461
|
*/
|
|
375
|
-
verifyTransactionProof(proof, proposedData
|
|
376
|
-
return (0, verify_transaction_proposal_proof_1.verifyTransactionProposalProof)(proof, this, proposedData
|
|
462
|
+
verifyTransactionProof(proof, proposedData) {
|
|
463
|
+
return (0, verify_transaction_proposal_proof_1.verifyTransactionProposalProof)(proof, this, proposedData);
|
|
377
464
|
}
|
|
378
465
|
//#endregion Crypto Proofs
|
|
379
466
|
//#region Structure Proofs
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@degenerate/sharedata",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "This contains the ShareData Adaptive Framework Ecosystem (SAFE) network core code",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"url": "https://github.com/syncrude/safe/issues"
|
|
50
50
|
},
|
|
51
51
|
"homepage": "https://github.com/syncrude/safe#readme",
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "c8c1a2f456cdb01a74f85779275b246361e33b81",
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@degenerate/generic": "^0.
|
|
55
|
-
"@degenerate/rules": "^0.
|
|
54
|
+
"@degenerate/generic": "^0.6.0",
|
|
55
|
+
"@degenerate/rules": "^0.6.0",
|
|
56
56
|
"zod": "^4.4.3"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|