-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update ts client to include signer messages
- Loading branch information
Showing
5 changed files
with
129 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
components/client/typescript/src/schemas/stacks/signers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { Static, Type } from '@fastify/type-provider-typebox'; | ||
import { BlockIdentifierSchema } from '../common'; | ||
import { StacksTransactionSchema } from './payload'; | ||
|
||
export const StacksNakamotoBlockHeaderSchema = Type.Object({ | ||
version: Type.Integer(), | ||
chain_length: Type.Integer(), | ||
burn_spent: Type.Integer(), | ||
consensus_hash: Type.String(), | ||
parent_block_id: Type.String(), | ||
tx_merkle_root: Type.String(), | ||
state_index_root: Type.String(), | ||
timestamp: Type.Integer(), | ||
miner_signature: Type.String(), | ||
signer_signature: Type.Array(Type.String()), | ||
pox_treatment: Type.String(), | ||
}); | ||
export type StacksNakamotoBlockHeader = Static<typeof StacksNakamotoBlockHeaderSchema>; | ||
|
||
export const StacksNakamotoBlockSchema = Type.Object({ | ||
header: StacksNakamotoBlockHeaderSchema, | ||
transactions: Type.Array(StacksTransactionSchema), | ||
}); | ||
export type StacksNakamotoBlock = Static<typeof StacksNakamotoBlockSchema>; | ||
|
||
export const StacksSignerMessageBlockProposalSchema = Type.Object({ | ||
type: Type.Literal('BlockProposal'), | ||
data: Type.Object({ | ||
block: StacksNakamotoBlockSchema, | ||
burn_height: Type.Integer(), | ||
reward_cycle: Type.Integer(), | ||
}), | ||
}); | ||
export type StacksSignerMessageBlockProposal = Static< | ||
typeof StacksSignerMessageBlockProposalSchema | ||
>; | ||
|
||
export const StacksSignerMessageBlockResponseAcceptedSchema = Type.Object({ | ||
type: Type.Literal('Accepted'), | ||
data: Type.Object({ | ||
signer_signature_hash: Type.String(), | ||
sig: Type.String(), | ||
}), | ||
}); | ||
export type StacksSignerMessageBlockResponseAccepted = Static< | ||
typeof StacksSignerMessageBlockResponseAcceptedSchema | ||
>; | ||
|
||
export const StacksSignerMessageBlockResponseRejectedSchema = Type.Object({ | ||
type: Type.Literal('Rejected'), | ||
data: Type.Object({ | ||
reason: Type.String(), | ||
reason_code: Type.Union([ | ||
Type.Literal('VALIDATION_FAILED'), | ||
Type.Literal('CONNECTIVITY_ISSUES'), | ||
Type.Literal('REJECTED_IN_PRIOR_ROUND'), | ||
Type.Literal('NO_SORTITION_VIEW'), | ||
Type.Literal('SORTITION_VIEW_MISMATCH'), | ||
Type.Literal('TESTING_DIRECTIVE'), | ||
]), | ||
signer_signature_hash: Type.String(), | ||
chain_id: Type.Integer(), | ||
signature: Type.String(), | ||
}), | ||
}); | ||
export type StacksSignerMessageBlockResponseRejected = Static< | ||
typeof StacksSignerMessageBlockResponseRejectedSchema | ||
>; | ||
|
||
export const StacksSignerMessageBlockResponseSchema = Type.Object({ | ||
type: Type.Literal('BlockResponse'), | ||
data: Type.Union([ | ||
StacksSignerMessageBlockResponseAcceptedSchema, | ||
StacksSignerMessageBlockResponseRejectedSchema, | ||
]), | ||
}); | ||
export type StacksSignerMessageBlockResponse = Static< | ||
typeof StacksSignerMessageBlockResponseSchema | ||
>; | ||
|
||
export const StacksSignerMessageBlockPushedSchema = Type.Object({ | ||
type: Type.Literal('BlockPushed'), | ||
data: Type.Object({ | ||
block: StacksNakamotoBlockSchema, | ||
}), | ||
}); | ||
export type StacksSignerMessageBlockPushed = Static<typeof StacksSignerMessageBlockPushedSchema>; | ||
|
||
export const StacksSignerMessageSchema = Type.Union([ | ||
StacksSignerMessageBlockProposalSchema, | ||
StacksSignerMessageBlockResponseSchema, | ||
StacksSignerMessageBlockPushedSchema, | ||
]); | ||
export type StacksSignerMessage = Static<typeof StacksSignerMessageSchema>; | ||
|
||
export const StacksSignerMessageEventSchema = Type.Object({ | ||
contract: Type.String(), | ||
sig: Type.String(), | ||
pubkey: Type.String(), | ||
message: StacksSignerMessageSchema, | ||
received_at: Type.Integer(), | ||
received_at_block: BlockIdentifierSchema, | ||
}); | ||
export type StacksSignerMessageEvent = Static<typeof StacksSignerMessageEventSchema>; |