-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rpc): add deployContract feat(rpc): add profile, backwards compat stx_signTransaction
- Loading branch information
1 parent
e68e810
commit 46af901
Showing
13 changed files
with
341 additions
and
55 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
2 changes: 1 addition & 1 deletion
2
packages/rpc/src/methods/send-transfer.ts → .../rpc/src/methods/bitcoin/send-transfer.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
4 changes: 2 additions & 2 deletions
4
packages/rpc/src/methods/sign-message.ts → ...s/rpc/src/methods/bitcoin/sign-message.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
2 changes: 1 addition & 1 deletion
2
packages/rpc/src/methods/sign-psbt.ts → ...ages/rpc/src/methods/bitcoin/sign-psbt.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
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,97 @@ | ||
import { z } from 'zod'; | ||
|
||
export const stacksTransactionDetailsSchema = z.object({ | ||
txid: z.string(), | ||
transaction: z.string(), | ||
}); | ||
|
||
// Clarity values | ||
export const cvIntSchema = z.object({ | ||
type: z.literal('int'), | ||
value: z.string(), // `bigint` compatible | ||
}); | ||
|
||
export const cvUintSchema = z.object({ | ||
type: z.literal('uint'), | ||
value: z.string(), // `bigint` compatible | ||
}); | ||
|
||
export const cvBufferSchema = z.object({ | ||
type: z.literal('buffer'), | ||
value: z.string(), // hex-encoded string | ||
}); | ||
|
||
export const cvTrueSchema = z.object({ | ||
type: z.literal('true'), | ||
}); | ||
|
||
export const cvFalseSchema = z.object({ | ||
type: z.literal('false'), | ||
}); | ||
|
||
export const cvAddressSchema = z.object({ | ||
type: z.literal('address'), | ||
value: z.string(), // Stacks c32-encoded | ||
}); | ||
|
||
export const cvContractSchema = z.object({ | ||
type: z.literal('contract'), | ||
value: z.string(), // Stacks c32-encoded, with contract name suffix | ||
}); | ||
|
||
export const cvOkSchema = z.object({ | ||
type: z.literal('ok'), | ||
value: z.unknown(), // Clarity value | ||
}); | ||
|
||
export const cvErrSchema = z.object({ | ||
type: z.literal('err'), | ||
value: z.unknown(), // Clarity value | ||
}); | ||
|
||
export const cvNoneSchema = z.object({ | ||
type: z.literal('none'), | ||
}); | ||
|
||
export const cvSomeSchema = z.object({ | ||
type: z.literal('some'), | ||
value: z.unknown(), // Clarity value | ||
}); | ||
|
||
export const cvListSchema = z.object({ | ||
type: z.literal('list'), | ||
value: z.array(z.unknown()), // Array of Clarity values | ||
}); | ||
|
||
export const cvTupleSchema = z.object({ | ||
type: z.literal('tuple'), | ||
value: z.record(z.unknown()), // Record of Clarity values | ||
}); | ||
|
||
export const cvAsciiSchema = z.object({ | ||
type: z.literal('ascii'), | ||
value: z.string(), // ASCII-compatible string | ||
}); | ||
|
||
export const cvUtf8Schema = z.object({ | ||
type: z.literal('utf8'), | ||
value: z.string(), | ||
}); | ||
|
||
export const clarityValueSchema = z.union([ | ||
cvIntSchema, | ||
cvUintSchema, | ||
cvBufferSchema, | ||
cvTrueSchema, | ||
cvFalseSchema, | ||
cvAddressSchema, | ||
cvContractSchema, | ||
cvOkSchema, | ||
cvErrSchema, | ||
cvNoneSchema, | ||
cvSomeSchema, | ||
cvListSchema, | ||
cvTupleSchema, | ||
cvAsciiSchema, | ||
cvUtf8Schema, | ||
]); |
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,32 @@ | ||
import { z } from 'zod'; | ||
|
||
import { DefineRpcMethod, RpcRequest, RpcResponse } from '../../rpc/schemas'; | ||
import { stacksTransactionDetailsSchema } from './_stacks-helpers'; | ||
|
||
export const stxCallContractMethodName = 'stx_callContract'; | ||
|
||
type StxCallContractRequestMethodName = typeof stxCallContractMethodName; | ||
|
||
// Request | ||
export const stxCallContractRequestParamsSchema = z.object({ | ||
contract: z.string(), | ||
asset: z.string(), | ||
amount: z.coerce.number(), | ||
}); | ||
|
||
export type StxCallContractRequestParams = z.infer<typeof stxCallContractRequestParamsSchema>; | ||
|
||
export type StxCallContractRequest = RpcRequest< | ||
StxCallContractRequestMethodName, | ||
StxCallContractRequestParams | ||
>; | ||
|
||
// Result | ||
export const stxCallContractResponseBodySchema = stacksTransactionDetailsSchema; | ||
|
||
export type StxCallContractResponse = RpcResponse<typeof stxCallContractResponseBodySchema>; | ||
|
||
export type DefineStxCallContractMethod = DefineRpcMethod< | ||
StxCallContractRequest, | ||
StxCallContractResponse | ||
>; |
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,32 @@ | ||
import { z } from 'zod'; | ||
|
||
import { DefineRpcMethod, RpcRequest, RpcResponse } from '../../rpc/schemas'; | ||
import { stacksTransactionDetailsSchema } from './_stacks-helpers'; | ||
|
||
export const stxDeployContractMethodName = 'stx_deployContract'; | ||
|
||
type StxDeployContractRequestMethodName = typeof stxDeployContractMethodName; | ||
|
||
// Request | ||
export const stxDeployContractRequestParamsSchema = z.object({ | ||
name: z.string(), | ||
clarityCode: z.string(), | ||
clarityVersion: z.coerce.number().optional(), | ||
}); | ||
|
||
export type StxDeployContractRequestParams = z.infer<typeof stxDeployContractRequestParamsSchema>; | ||
|
||
export type StxDeployContractRequest = RpcRequest< | ||
StxDeployContractRequestMethodName, | ||
StxDeployContractRequestParams | ||
>; | ||
|
||
// Result | ||
export const stxDeployContractResponseBodySchema = stacksTransactionDetailsSchema; | ||
|
||
export type StxDeployContractResponse = RpcResponse<typeof stxDeployContractResponseBodySchema>; | ||
|
||
export type DefineStxDeployContractMethod = DefineRpcMethod< | ||
StxDeployContractRequest, | ||
StxDeployContractResponse | ||
>; |
2 changes: 1 addition & 1 deletion
2
packages/rpc/src/methods/stx-sign-message.ts → ...pc/src/methods/stacks/stx-sign-message.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
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,46 @@ | ||
import { z } from 'zod'; | ||
|
||
import { DefineRpcMethod, RpcRequest, RpcResponse } from '../../rpc/schemas'; | ||
|
||
export const stxSignTransactionMethodName = 'stx_signTransaction'; | ||
|
||
// Leather's RPC params prior to SIP-30 | ||
// Developers should be warned away from this structure | ||
export const stxSignTransactionRequestLeatherRpcParamsSchema = z.object({ | ||
txHex: z.string(), | ||
stxAddress: z.string().optional(), | ||
attachment: z.string().optional(), | ||
accountIndex: z.string().optional(), | ||
}); | ||
|
||
// SIP-30 params | ||
export const stxSignTransactionRequestSip30ParamsSchema = z.object({ transaction: z.string() }); | ||
|
||
export const stxSignTransactionRequestParamsSchema = z.union([ | ||
stxSignTransactionRequestLeatherRpcParamsSchema, | ||
stxSignTransactionRequestSip30ParamsSchema, | ||
]); | ||
|
||
export type StxSignTransactionRequestParams = z.infer< | ||
typeof stxSignTransactionRequestSip30ParamsSchema | ||
>; | ||
|
||
// For backwards compatibility, we return the same data under both properties | ||
export const stxSignTransactionResponseSchema = z.object({ | ||
transaction: z.string(), | ||
txHex: z.string(), | ||
}); | ||
|
||
export type StxSignTransactionResponseBody = z.infer<typeof stxSignTransactionResponseSchema>; | ||
|
||
export type StxSignTransactionRequest = RpcRequest< | ||
typeof stxSignTransactionMethodName, | ||
StxSignTransactionRequestParams | ||
>; | ||
|
||
export type StxSignTransactionResponse = RpcResponse<StxSignTransactionResponseBody>; | ||
|
||
export type DefineStxSignTransactionMethod = DefineRpcMethod< | ||
StxSignTransactionRequest, | ||
StxSignTransactionResponse | ||
>; |
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,32 @@ | ||
import { z } from 'zod'; | ||
|
||
import { DefineRpcMethod, RpcRequest, RpcResponse } from '../../rpc/schemas'; | ||
import { stacksTransactionDetailsSchema } from './_stacks-helpers'; | ||
|
||
export const stxTransferSip10FtMethodName = 'stx_transferSip10Ft'; | ||
|
||
type StxTransferSip10FtRequestMethodName = typeof stxTransferSip10FtMethodName; | ||
|
||
// Request | ||
export const stxTransferSip10FtRequestParamsSchema = z.object({ | ||
recipient: z.string(), | ||
asset: z.string(), | ||
amount: z.coerce.number(), | ||
}); | ||
|
||
export type StxTransferSip10FtRequestParams = z.infer<typeof stxTransferSip10FtRequestParamsSchema>; | ||
|
||
export type StxTransferSip10FtRequest = RpcRequest< | ||
StxTransferSip10FtRequestMethodName, | ||
StxTransferSip10FtRequestParams | ||
>; | ||
|
||
// Result | ||
export const stxTransferSip10FtResponseBodySchema = stacksTransactionDetailsSchema; | ||
|
||
export type StxTransferSip10FtResponse = RpcResponse<typeof stxTransferSip10FtResponseBodySchema>; | ||
|
||
export type DefineStxTransferSip10FtMethod = DefineRpcMethod< | ||
StxTransferSip10FtRequest, | ||
StxTransferSip10FtResponse | ||
>; |
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,32 @@ | ||
import { z } from 'zod'; | ||
|
||
import { DefineRpcMethod, RpcRequest, RpcResponse } from '../../rpc/schemas'; | ||
import { stacksTransactionDetailsSchema } from './_stacks-helpers'; | ||
|
||
export const stxTransferStxMethodName = 'stx_transferStx'; | ||
|
||
type StxTransferStxRequestMethodName = typeof stxTransferStxMethodName; | ||
|
||
// Request | ||
export const stxTransferStxRequestParamsSchema = z.object({ | ||
recipient: z.string(), | ||
amount: z.number(), | ||
memo: z.string().optional(), | ||
}); | ||
|
||
export type StxTransferStxRequestParams = z.infer<typeof stxTransferStxRequestParamsSchema>; | ||
|
||
export type StxTransferStxRequest = RpcRequest< | ||
StxTransferStxRequestMethodName, | ||
StxTransferStxRequestParams | ||
>; | ||
|
||
// Result | ||
export const stxTransferStxResponseBodySchema = stacksTransactionDetailsSchema; | ||
|
||
export type StxTransferStxResponse = RpcResponse<typeof stxTransferStxResponseBodySchema>; | ||
|
||
export type DefineStxTransferStxMethod = DefineRpcMethod< | ||
StxTransferStxRequest, | ||
StxTransferStxResponse | ||
>; |
Oops, something went wrong.