Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
feat: sidevmQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
kingsleydon committed Sep 30, 2022
1 parent 9c4ae39 commit 769dcb5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@phala/sdk",
"version": "0.3.3",
"version": "0.3.4-beta.0",
"description": "Phala JS SDK",
"homepage": "https:/Phala-Network/js-sdk/tree/main/packages/sdk#readme",
"repository": {
Expand Down
25 changes: 23 additions & 2 deletions packages/sdk/src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export type Query = (
certificateData: CertificateData
) => Promise<string>

export type SidevmQuery = (
bytes: Bytes,
certificateData: CertificateData
) => Promise<string>

type EncryptedData = {
iv: string
pubkey: string
Expand All @@ -53,7 +58,7 @@ type CreateFn = (options: {
api: ApiPromise
baseURL: string
contractId: string
}) => Promise<ApiPromise>
}) => Promise<{api: ApiPromise; sidevmQuery: SidevmQuery}>

export const createPruntimeApi = (baseURL: string) => {
// Create a http client prepared for protobuf
Expand Down Expand Up @@ -162,6 +167,22 @@ export const create: CreateFn = async ({api, baseURL, contractId}) => {
})
}

const sidevmQuery: SidevmQuery = async (bytes, certificateData) =>
query(
api
.createType('InkQuery', {
head: {
nonce: hexAddPrefix(randomHex(32)),
id: contractId,
},
data: {
SidevmMessage: bytes,
},
})
.toHex(),
certificateData
)

const command: Command = ({contractId, payload}) => {
const encodedPayload = api
.createType('CommandPayload', {
Expand Down Expand Up @@ -257,5 +278,5 @@ export const create: CreateFn = async ({api, baseURL, contractId}) => {
enumerable: true,
})

return api
return {api, sidevmQuery}
}
1 change: 1 addition & 0 deletions packages/sdk/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const types: RegistryTypes = {
InkQueryData: {
_enum: {
InkMessage: 'Vec<u8>',
SidevmMessage: 'Vec<u8>',
},
},
InkQuery: {
Expand Down

0 comments on commit 769dcb5

Please sign in to comment.