diff --git a/Cargo.lock b/Cargo.lock index ae93e54c..95f17e41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3552,7 +3552,7 @@ dependencies = [ [[package]] name = "stacks-codec" version = "2.10.0" -source = "git+https://github.com/hirosystems/clarinet.git?rev=fcebfb5a986ded32d5a450c34f8e5e5f2da97de4#fcebfb5a986ded32d5a450c34f8e5e5f2da97de4" +source = "git+https://github.com/hirosystems/clarinet.git?rev=3ec638a64171b7557613531f118f302992c99b89#3ec638a64171b7557613531f118f302992c99b89" dependencies = [ "clarity", "serde", diff --git a/Cargo.toml b/Cargo.toml index 97b5fc91..f1e1171f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,4 @@ default-members = ["components/chainhook-cli", "components/chainhook-sdk"] resolver = "2" [patch.crates-io] -stacks-codec = { git = "https://github.com/hirosystems/clarinet.git", rev = "fcebfb5a986ded32d5a450c34f8e5e5f2da97de4" } +stacks-codec = { git = "https://github.com/hirosystems/clarinet.git", rev = "3ec638a64171b7557613531f118f302992c99b89" } diff --git a/components/chainhook-cli/src/storage/signers.rs b/components/chainhook-cli/src/storage/signers.rs index c01c6abd..a1f6a77b 100644 --- a/components/chainhook-cli/src/storage/signers.rs +++ b/components/chainhook-cli/src/storage/signers.rs @@ -146,6 +146,8 @@ pub fn initialize_signers_db(base_dir: &PathBuf, ctx: &Context) -> Result, - peer_info: &PeerInfoData, - metadata: &SignerMessageMetadata, + mock_signature: &MockSignatureData, message_id: Option, mock_block_id: Option, ) -> Result<(), String> { - let mock_proposal_id = store_mock_proposal_peer_info(&db_tx, &peer_info, None)?; + let mock_proposal_id = + store_mock_proposal_peer_info(&db_tx, &mock_signature.mock_proposal.peer_info, None)?; let mut signature_stmt = db_tx .prepare( "INSERT INTO mock_signatures - (message_id, mock_proposal_id, mock_block_id, server_version) - VALUES (?,?,?,?)", + (message_id, mock_proposal_id, mock_block_id, server_version, signature, pubkey) + VALUES (?,?,?,?,?,?)", ) .map_err(|e| format!("unable to prepare statement: {e}"))?; signature_stmt @@ -213,7 +215,9 @@ fn store_mock_signature( &message_id, &mock_proposal_id, &mock_block_id, - &metadata.server_version, + &mock_signature.metadata.server_version, + &mock_signature.signature, + &mock_signature.pubkey, ]) .map_err(|e| format!("unable to write mock signature: {e}"))?; Ok(()) @@ -435,13 +439,7 @@ pub fn store_signer_db_messages( "Storing stacks MockSignature by signer {}", chunk.pubkey ); - store_mock_signature( - &db_tx, - &data.mock_proposal.peer_info, - &data.metadata, - Some(message_id), - None, - )?; + store_mock_signature(&db_tx, &data, Some(message_id), None)?; } StacksSignerMessage::MockProposal(data) => { try_info!( @@ -477,8 +475,7 @@ pub fn store_signer_db_messages( for signature in data.mock_signatures.iter() { store_mock_signature( &db_tx, - &signature.mock_proposal.peer_info, - &signature.metadata, + &signature, None, Some(mock_block_id), )?; @@ -654,7 +651,8 @@ pub fn get_signer_db_messages_received_at_block( "mock_signature" => db_tx .query_row( "SELECT p.burn_block_height, p.stacks_tip_consensus_hash, p.stacks_tip, p.stacks_tip_height, - p.pox_consensus, p.server_version AS peer_version, p.network_id, s.server_version + p.pox_consensus, p.server_version AS peer_version, p.network_id, s.server_version, s.signature, + s.pubkey FROM mock_signatures AS s INNER JOIN mock_proposals AS p ON p.id = s.mock_proposal_id WHERE s.message_id = ?", @@ -675,7 +673,9 @@ pub fn get_signer_db_messages_received_at_block( }, metadata: SignerMessageMetadata { server_version: signature_row.get(8).unwrap() - } + }, + signature: signature_row.get(9).unwrap(), + pubkey: signature_row.get(10).unwrap() })) }, ) @@ -715,7 +715,7 @@ pub fn get_signer_db_messages_received_at_block( .prepare( "SELECT p.burn_block_height, p.stacks_tip_consensus_hash, p.stacks_tip, p.stacks_tip_height, p.pox_consensus, p.server_version AS peer_version, - p.network_id, p.index_block_hash, s.server_version + p.network_id, p.index_block_hash, s.server_version, s.signature, s.pubkey FROM mock_signatures AS s INNER JOIN mock_proposals AS p ON p.id = s.mock_proposal_id WHERE s.mock_block_id = ?")?; @@ -737,7 +737,9 @@ pub fn get_signer_db_messages_received_at_block( }, metadata: SignerMessageMetadata { server_version: signature_row.get(8).unwrap() - } + }, + signature: signature_row.get(9).unwrap(), + pubkey: signature_row.get(10).unwrap() }); } Ok(StacksSignerMessage::MockBlock(MockBlockData { diff --git a/components/chainhook-sdk/src/indexer/stacks/mod.rs b/components/chainhook-sdk/src/indexer/stacks/mod.rs index 3a4a12a8..6532d48f 100644 --- a/components/chainhook-sdk/src/indexer/stacks/mod.rs +++ b/components/chainhook-sdk/src/indexer/stacks/mod.rs @@ -802,13 +802,16 @@ pub fn standardize_stacks_stackerdb_chunks( .mock_signatures .iter() .map(|signature| standardize_stacks_signer_mock_signature(signature)) - .try_fold(Vec::new(), |mut acc, item| -> Result, String> { - item.and_then(|val| { - acc.push(val); - Ok(()) - })?; - Ok(acc) - })?, + .try_fold( + Vec::new(), + |mut acc, item| -> Result, String> { + item.and_then(|val| { + acc.push(val); + Ok(()) + })?; + Ok(acc) + }, + )?, }), }; parsed_chunks.push(StacksStackerDbChunk { @@ -829,6 +832,14 @@ pub fn standardize_stacks_stackerdb_chunks( pub fn standardize_stacks_signer_mock_signature( signature: &stacks_codec::codec::MockSignature, ) -> Result { + let pubkey = get_signer_pubkey_from_message_hash( + &signature + .mock_proposal + .signer_signature_hash() + .as_bytes() + .to_vec(), + &signature.signature, + )?; Ok(MockSignatureData { mock_proposal: MockProposalData { peer_info: standardize_stacks_signer_peer_info(&signature.mock_proposal.peer_info)?, @@ -836,6 +847,8 @@ pub fn standardize_stacks_signer_mock_signature( metadata: SignerMessageMetadata { server_version: signature.metadata.server_version.clone(), }, + signature: format!("0x{}", signature.signature.to_hex()), + pubkey: format!("0x{}", hex::encode(pubkey)), }) } diff --git a/components/chainhook-types-rs/src/signers.rs b/components/chainhook-types-rs/src/signers.rs index 3cb78d7f..a7264703 100644 --- a/components/chainhook-types-rs/src/signers.rs +++ b/components/chainhook-types-rs/src/signers.rs @@ -111,7 +111,9 @@ pub struct MockProposalData { #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub struct MockSignatureData { pub mock_proposal: MockProposalData, - pub metadata: SignerMessageMetadata + pub metadata: SignerMessageMetadata, + pub signature: String, + pub pubkey: String, } #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] diff --git a/components/client/typescript/package-lock.json b/components/client/typescript/package-lock.json index af8a39f3..c753b9a6 100644 --- a/components/client/typescript/package-lock.json +++ b/components/client/typescript/package-lock.json @@ -1,12 +1,12 @@ { "name": "@hirosystems/chainhook-client", - "version": "2.2.0", + "version": "2.3.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@hirosystems/chainhook-client", - "version": "2.2.0", + "version": "2.3.0", "license": "Apache 2.0", "dependencies": { "@fastify/type-provider-typebox": "^3.2.0", diff --git a/components/client/typescript/package.json b/components/client/typescript/package.json index f558fb8d..78117ec3 100644 --- a/components/client/typescript/package.json +++ b/components/client/typescript/package.json @@ -1,6 +1,6 @@ { "name": "@hirosystems/chainhook-client", - "version": "2.2.0", + "version": "2.3.0", "description": "Chainhook TypeScript client", "main": "./dist/index.js", "typings": "./dist/index.d.ts", diff --git a/components/client/typescript/src/schemas/stacks/signers.ts b/components/client/typescript/src/schemas/stacks/signers.ts index 57503acc..07f358a2 100644 --- a/components/client/typescript/src/schemas/stacks/signers.ts +++ b/components/client/typescript/src/schemas/stacks/signers.ts @@ -128,6 +128,8 @@ export type StacksSignerMessageMockProposalData = Static< export const StacksSignerMessageMockSignatureDataSchema = Type.Object({ mock_proposal: StacksSignerMessageMockProposalDataSchema, metadata: StacksSignerMessageMetadataSchema, + signature: Type.String(), + pubkey: Type.String(), }); export type StacksSignerMessageMockSignatureData = Static< typeof StacksSignerMessageMockSignatureDataSchema