diff --git a/e2e/browser/browser.test.js b/e2e/browser/browser.test.js index 6963ae82..0c6ca0cc 100644 --- a/e2e/browser/browser.test.js +++ b/e2e/browser/browser.test.js @@ -57,12 +57,6 @@ describe("E2E browser", () => { await gammeDriver.stop(); }); - it("should create Orbs.Client instance", async () => { - await clickOnElement("#create-orbs-client"); - const orbsClientResult = await getElementText("#orbs-client-result"); - expect(orbsClientResult).toEqual("Created"); - }); - it("should create the sender account", async () => { await clickOnElement("#create-sender-account"); const senderAccountId = await getElementText("#sender-account-id"); @@ -70,6 +64,12 @@ describe("E2E browser", () => { expect(accountIdLength).toEqual(32); }); + it("should create Orbs.Client instance", async () => { + await clickOnElement("#create-orbs-client"); + const orbsClientResult = await getElementText("#orbs-client-result"); + expect(orbsClientResult).toEqual("Created"); + }); + it("should create the receiver account", async () => { await clickOnElement("#create-receiver-account"); const receiverAccountId = await getElementText("#receiver-account-id"); diff --git a/e2e/browser/index.html b/e2e/browser/index.html index 5b4f3ccb..875fac09 100644 --- a/e2e/browser/index.html +++ b/e2e/browser/index.html @@ -30,7 +30,7 @@ try { const endpoint = document.querySelector("#endpoint").value; const virtualChainId = document.querySelector("#virtual-chain-id").value; - window.orbsClient = new Orbs.Client(endpoint, virtualChainId, "TEST_NET"); + window.orbsClient = new Orbs.Client(endpoint, virtualChainId, "TEST_NET", new Orbs.LocalSigner(window.senderAccount)); result = "Created"; } catch (e) { result = "Failed"; @@ -48,46 +48,42 @@ document.querySelector("#receiver-account-id").innerText = window.receiverAccount.publicKey; } - function CreateTx() { - const [tx, txId] = window.orbsClient.createTransaction(window.senderAccount.publicKey, window.senderAccount.privateKey, "BenchmarkToken", "transfer", [Orbs.argUint64(10), Orbs.argAddress(window.receiverAccount.address)]); + async function CreateTx() { + const [tx, txId] = await window.orbsClient.createTransaction("BenchmarkToken", "transfer", [Orbs.argUint64(10), Orbs.argAddress(window.receiverAccount.address)]); window.tx = tx; window.txId = txId; document.querySelector("#tx-id").innerText = txId; } - function SendTx() { - window.orbsClient.sendTransaction(window.tx).then(transferResponse => { - document.querySelector("#transfer-response-request-status").innerText = transferResponse.requestStatus; - document.querySelector("#transfer-response-execution-result").innerText = transferResponse.executionResult; - document.querySelector("#transfer-response-transaction-status").innerText = transferResponse.transactionStatus; - }); + async function SendTx() { + const transferResponse = await window.orbsClient.sendTransaction(window.tx); + document.querySelector("#transfer-response-request-status").innerText = transferResponse.requestStatus; + document.querySelector("#transfer-response-execution-result").innerText = transferResponse.executionResult; + document.querySelector("#transfer-response-transaction-status").innerText = transferResponse.transactionStatus; } - function GetTxStatus() { - window.orbsClient.getTransactionStatus(window.txId).then(statusResponse => { - document.querySelector("#status-response-request-status").innerText = statusResponse.requestStatus; - document.querySelector("#status-response-execution-result").innerText = statusResponse.executionResult; - document.querySelector("#status-response-transaction-status").innerText = statusResponse.transactionStatus; - }); + async function GetTxStatus() { + const statusResponse = await window.orbsClient.getTransactionStatus(window.txId); + document.querySelector("#status-response-request-status").innerText = statusResponse.requestStatus; + document.querySelector("#status-response-execution-result").innerText = statusResponse.executionResult; + document.querySelector("#status-response-transaction-status").innerText = statusResponse.transactionStatus; } - function GetTxReceiptProof() { - window.orbsClient.getTransactionReceiptProof(window.txId).then(txProofResponse => { - document.querySelector("#proof-response-request-status").innerText = txProofResponse.requestStatus; - document.querySelector("#proof-response-execution-result").innerText = txProofResponse.executionResult; - document.querySelector("#proof-response-transaction-status").innerText = txProofResponse.transactionStatus; - document.querySelector("#proof-response-packedproof-bytelength").innerText = txProofResponse.packedProof.byteLength; - document.querySelector("#proof-response-packedreceipt-bytelength").innerText = txProofResponse.packedReceipt.byteLength; - }); + async function GetTxReceiptProof() { + const txProofResponse = await window.orbsClient.getTransactionReceiptProof(window.txId); + document.querySelector("#proof-response-request-status").innerText = txProofResponse.requestStatus; + document.querySelector("#proof-response-execution-result").innerText = txProofResponse.executionResult; + document.querySelector("#proof-response-transaction-status").innerText = txProofResponse.transactionStatus; + document.querySelector("#proof-response-packedproof-bytelength").innerText = txProofResponse.packedProof.byteLength; + document.querySelector("#proof-response-packedreceipt-bytelength").innerText = txProofResponse.packedReceipt.byteLength; } - function SendQuery() { - const query = window.orbsClient.createQuery(window.receiverAccount.publicKey, "BenchmarkToken", "getBalance", [Orbs.argAddress(window.receiverAccount.address)]); - window.orbsClient.sendQuery(query).then(balanceResponse => { - document.querySelector("#balance-response-request-status").innerText = balanceResponse.requestStatus; - document.querySelector("#balance-response-execution-result").innerText = balanceResponse.executionResult; - document.querySelector("#balance-response-value").innerText = balanceResponse.outputArguments[0].value; - }); + async function SendQuery() { + const query = await window.orbsClient.createQuery("BenchmarkToken", "getBalance", [Orbs.argAddress(window.receiverAccount.address)]); + const balanceResponse = await window.orbsClient.sendQuery(query); + document.querySelector("#balance-response-request-status").innerText = balanceResponse.requestStatus; + document.querySelector("#balance-response-execution-result").innerText = balanceResponse.executionResult; + document.querySelector("#balance-response-value").innerText = balanceResponse.outputArguments[0].value; } diff --git a/e2e/nodejs/e2e.test.js b/e2e/nodejs/e2e.test.js index 8ba26dff..ef71a672 100644 --- a/e2e/nodejs/e2e.test.js +++ b/e2e/nodejs/e2e.test.js @@ -32,13 +32,13 @@ describe("E2E nodejs", () => { // create client const endpoint = gammeDriver.getEndpoint(); - const client = new Orbs.Client(endpoint, VIRTUAL_CHAIN_ID, "TEST_NET"); + const senderClient = new Orbs.Client(endpoint, VIRTUAL_CHAIN_ID, "TEST_NET", new Orbs.LocalSigner(sender)); // create transfer transaction - const [tx, txId] = client.createTransaction(sender.publicKey, sender.privateKey, "BenchmarkToken", "transfer", [Orbs.argUint64(10), Orbs.argAddress(receiver.address)]); + const [tx, txId] = await senderClient.createTransaction("BenchmarkToken", "transfer", [Orbs.argUint64(10), Orbs.argAddress(receiver.address)]); // send the transaction - const transferResponse = await client.sendTransaction(tx); + const transferResponse = await senderClient.sendTransaction(tx); console.log("Transfer response:"); console.log(transferResponse); expect(transferResponse.requestStatus).toEqual("COMPLETED"); @@ -46,7 +46,7 @@ describe("E2E nodejs", () => { expect(transferResponse.transactionStatus).toEqual("COMMITTED"); // check the transaction status - const statusResponse = await client.getTransactionStatus(txId); + const statusResponse = await senderClient.getTransactionStatus(txId); console.log("Status response:"); console.log(statusResponse); expect(statusResponse.requestStatus).toEqual("COMPLETED"); @@ -54,7 +54,7 @@ describe("E2E nodejs", () => { expect(statusResponse.transactionStatus).toEqual("COMMITTED"); // check the transaction receipt proof - const txProofResponse = await client.getTransactionReceiptProof(txId); + const txProofResponse = await senderClient.getTransactionReceiptProof(txId); console.log("Receipt proof response:"); console.log(txProofResponse); expect(txProofResponse.requestStatus).toEqual("COMPLETED"); @@ -64,10 +64,10 @@ describe("E2E nodejs", () => { expect(txProofResponse.packedReceipt.byteLength).toBeGreaterThan(10); // create balance query - const query = client.createQuery(receiver.publicKey, "BenchmarkToken", "getBalance", [Orbs.argAddress(receiver.address)]); + const query = await senderClient.createQuery("BenchmarkToken", "getBalance", [Orbs.argAddress(receiver.address)]); // send the query - const balanceResponse = await client.sendQuery(query); + const balanceResponse = await senderClient.sendQuery(query); console.log("Query response:"); console.log(balanceResponse); expect(balanceResponse.requestStatus).toEqual("COMPLETED"); @@ -75,7 +75,7 @@ describe("E2E nodejs", () => { expect(balanceResponse.outputArguments[0]).toEqual(Orbs.argUint64(10)); // get the block which contains the transfer transaction - const blockResponse = await client.getBlock(transferResponse.blockHeight); + const blockResponse = await senderClient.getBlock(transferResponse.blockHeight); expect(blockResponse.blockHeight).toEqual(transferResponse.blockHeight); expect(blockResponse.transactionsBlockHeader.blockHeight).toEqual(transferResponse.blockHeight); expect(blockResponse.transactionsBlockHeader.numTransactions).toEqual(1); @@ -91,7 +91,7 @@ describe("E2E nodejs", () => { test("TextualError", async () => { // create client const endpoint = gammeDriver.getEndpoint(); - const client = new Orbs.Client(endpoint, VIRTUAL_CHAIN_ID, "TEST_NET"); + const client = new Orbs.Client(endpoint, VIRTUAL_CHAIN_ID, "TEST_NET", new Orbs.LocalSigner(Orbs.createAccount())); // send a corrupt transaction let error; @@ -112,7 +112,7 @@ describe("E2E nodejs", () => { // create client const endpoint = gammeDriver.getEndpoint(); - const client = new Orbs.Client(endpoint, VIRTUAL_CHAIN_ID, "TEST_NET"); + const client = new Orbs.Client(endpoint, VIRTUAL_CHAIN_ID, "TEST_NET", new Orbs.LocalSigner(sender)); const sources = [ readFileSync(`${__dirname}/../contract/increment_base.go`), @@ -120,7 +120,7 @@ describe("E2E nodejs", () => { ]; // create transfer transaction - const [deploymentTx, deploymentTxId] = client.createDeployTransaction(sender.publicKey, sender.privateKey, "Inc", Orbs.PROCESSOR_TYPE_NATIVE, ...sources); + const [deploymentTx, deploymentTxId] = await client.createDeployTransaction("Inc", Orbs.PROCESSOR_TYPE_NATIVE, ...sources); // send the transaction const deploymentResponse = await client.sendTransaction(deploymentTx); @@ -131,7 +131,7 @@ describe("E2E nodejs", () => { expect(deploymentResponse.transactionStatus).toEqual("COMMITTED"); // create transfer transaction - const [tx, txId] = client.createTransaction(sender.publicKey, sender.privateKey, "BenchmarkToken", "transfer", [Orbs.argUint64(10), Orbs.argAddress(receiver.address)]); + const [tx, txId] = await client.createTransaction("BenchmarkToken", "transfer", [Orbs.argUint64(10), Orbs.argAddress(receiver.address)]); // send the transaction const transferResponse = await client.sendTransaction(tx); @@ -142,7 +142,7 @@ describe("E2E nodejs", () => { expect(transferResponse.transactionStatus).toEqual("COMMITTED"); // create balance query - const query = client.createQuery(receiver.publicKey, "BenchmarkToken", "getBalance", [Orbs.argAddress(receiver.address)]); + const query = await client.createQuery("BenchmarkToken", "getBalance", [Orbs.argAddress(receiver.address)]); // send the query const balanceResponse = await client.sendQuery(query); diff --git a/package-lock.json b/package-lock.json index 924e40f5..614b8f8c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "orbs-client-sdk", - "version": "1.3.1", + "version": "2.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -6453,28 +6453,28 @@ "dependencies": { "abbrev": { "version": "1.1.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", "dev": true, "optional": true }, "ansi-regex": { "version": "2.1.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", "dev": true, "optional": true }, "aproba": { "version": "1.2.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", "dev": true, "optional": true }, "are-we-there-yet": { "version": "1.1.5", - "resolved": false, + "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz", "integrity": "sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w==", "dev": true, "optional": true, @@ -6485,14 +6485,14 @@ }, "balanced-match": { "version": "1.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "dev": true, "optional": true }, "brace-expansion": { "version": "1.1.11", - "resolved": false, + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, "optional": true, @@ -6503,35 +6503,35 @@ }, "chownr": { "version": "1.1.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.1.tgz", "integrity": "sha512-j38EvO5+LHX84jlo6h4UzmOwi0UgW61WRyPtJz4qaadK5eY3BTS5TY/S1Stc3Uk2lIM6TPevAlULiEJwie860g==", "dev": true, "optional": true }, "code-point-at": { "version": "1.1.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", "dev": true, "optional": true }, "concat-map": { "version": "0.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true, "optional": true }, "console-control-strings": { "version": "1.1.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", "dev": true, "optional": true }, "core-util-is": { "version": "1.0.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", "dev": true, "optional": true @@ -6548,28 +6548,28 @@ }, "deep-extend": { "version": "0.6.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", "dev": true, "optional": true }, "delegates": { "version": "1.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=", "dev": true, "optional": true }, "detect-libc": { "version": "1.0.3", - "resolved": false, + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=", "dev": true, "optional": true }, "fs-minipass": { "version": "1.2.5", - "resolved": false, + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.5.tgz", "integrity": "sha512-JhBl0skXjUPCFH7x6x61gQxrKyXsxB5gcgePLZCwfyCGGsTISMoIeObbrvVeP6Xmyaudw4TT43qV2Gz+iyd2oQ==", "dev": true, "optional": true, @@ -6579,14 +6579,14 @@ }, "fs.realpath": { "version": "1.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true, "optional": true }, "gauge": { "version": "2.7.4", - "resolved": false, + "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", "integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=", "dev": true, "optional": true, @@ -6603,7 +6603,7 @@ }, "glob": { "version": "7.1.3", - "resolved": false, + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", "dev": true, "optional": true, @@ -6618,14 +6618,14 @@ }, "has-unicode": { "version": "2.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=", "dev": true, "optional": true }, "iconv-lite": { "version": "0.4.24", - "resolved": false, + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", "dev": true, "optional": true, @@ -6635,7 +6635,7 @@ }, "ignore-walk": { "version": "3.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/ignore-walk/-/ignore-walk-3.0.1.tgz", "integrity": "sha512-DTVlMx3IYPe0/JJcYP7Gxg7ttZZu3IInhuEhbchuqneY9wWe5Ojy2mXLBaQFUQmo0AW2r3qG7m1mg86js+gnlQ==", "dev": true, "optional": true, @@ -6645,7 +6645,7 @@ }, "inflight": { "version": "1.0.6", - "resolved": false, + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "dev": true, "optional": true, @@ -6656,21 +6656,21 @@ }, "inherits": { "version": "2.0.3", - "resolved": false, + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", "dev": true, "optional": true }, "ini": { "version": "1.3.5", - "resolved": false, + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", "dev": true, "optional": true }, "is-fullwidth-code-point": { "version": "1.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", "dev": true, "optional": true, @@ -6680,14 +6680,14 @@ }, "isarray": { "version": "1.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", "dev": true, "optional": true }, "minimatch": { "version": "3.0.4", - "resolved": false, + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "dev": true, "optional": true, @@ -6697,14 +6697,14 @@ }, "minimist": { "version": "0.0.8", - "resolved": false, + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", "dev": true, "optional": true }, "minipass": { "version": "2.3.5", - "resolved": false, + "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.3.5.tgz", "integrity": "sha512-Gi1W4k059gyRbyVUZQ4mEqLm0YIUiGYfvxhF6SIlk3ui1WVxMTGfGdQ2SInh3PDrRTVvPKgULkpJtT4RH10+VA==", "dev": true, "optional": true, @@ -6715,7 +6715,7 @@ }, "minizlib": { "version": "1.2.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-1.2.1.tgz", "integrity": "sha512-7+4oTUOWKg7AuL3vloEWekXY2/D20cevzsrNT2kGWm+39J9hGTCBv8VI5Pm5lXZ/o3/mdR4f8rflAPhnQb8mPA==", "dev": true, "optional": true, @@ -6725,7 +6725,7 @@ }, "mkdirp": { "version": "0.5.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "dev": true, "optional": true, @@ -6773,7 +6773,7 @@ }, "nopt": { "version": "4.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.1.tgz", "integrity": "sha1-0NRoWv1UFRk8jHUFYC0NF81kR00=", "dev": true, "optional": true, @@ -6802,7 +6802,7 @@ }, "npmlog": { "version": "4.1.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", "dev": true, "optional": true, @@ -6815,21 +6815,21 @@ }, "number-is-nan": { "version": "1.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", "dev": true, "optional": true }, "object-assign": { "version": "4.1.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", "dev": true, "optional": true }, "once": { "version": "1.4.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "dev": true, "optional": true, @@ -6839,21 +6839,21 @@ }, "os-homedir": { "version": "1.0.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", "dev": true, "optional": true }, "os-tmpdir": { "version": "1.0.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", "dev": true, "optional": true }, "osenv": { "version": "0.1.5", - "resolved": false, + "resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz", "integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==", "dev": true, "optional": true, @@ -6864,21 +6864,21 @@ }, "path-is-absolute": { "version": "1.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true, "optional": true }, "process-nextick-args": { "version": "2.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==", "dev": true, "optional": true }, "rc": { "version": "1.2.8", - "resolved": false, + "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", "dev": true, "optional": true, @@ -6891,7 +6891,7 @@ "dependencies": { "minimist": { "version": "1.2.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true, "optional": true @@ -6900,7 +6900,7 @@ }, "readable-stream": { "version": "2.3.6", - "resolved": false, + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "dev": true, "optional": true, @@ -6916,7 +6916,7 @@ }, "rimraf": { "version": "2.6.3", - "resolved": false, + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", "dev": true, "optional": true, @@ -6926,21 +6926,21 @@ }, "safe-buffer": { "version": "5.1.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", "dev": true, "optional": true }, "safer-buffer": { "version": "2.1.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true, "optional": true }, "sax": { "version": "1.2.4", - "resolved": false, + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", "dev": true, "optional": true @@ -6954,21 +6954,21 @@ }, "set-blocking": { "version": "2.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", "dev": true, "optional": true }, "signal-exit": { "version": "3.0.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", "dev": true, "optional": true }, "string-width": { "version": "1.0.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", "dev": true, "optional": true, @@ -6980,7 +6980,7 @@ }, "string_decoder": { "version": "1.1.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", "dev": true, "optional": true, @@ -6990,7 +6990,7 @@ }, "strip-ansi": { "version": "3.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "dev": true, "optional": true, @@ -7000,14 +7000,14 @@ }, "strip-json-comments": { "version": "2.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", "dev": true, "optional": true }, "tar": { "version": "4.4.8", - "resolved": false, + "resolved": "https://registry.npmjs.org/tar/-/tar-4.4.8.tgz", "integrity": "sha512-LzHF64s5chPQQS0IYBn9IN5h3i98c12bo4NCO7e0sGM2llXQ3p2FGC5sdENN4cTW48O915Sh+x+EXx7XW96xYQ==", "dev": true, "optional": true, @@ -7023,14 +7023,14 @@ }, "util-deprecate": { "version": "1.0.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", "dev": true, "optional": true }, "wide-align": { "version": "1.1.3", - "resolved": false, + "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", "integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==", "dev": true, "optional": true, @@ -7040,14 +7040,14 @@ }, "wrappy": { "version": "1.0.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true, "optional": true }, "yallist": { "version": "3.0.3", - "resolved": false, + "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.3.tgz", "integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==", "dev": true, "optional": true diff --git a/package.json b/package.json index dd226c1c..86249914 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "orbs-client-sdk", - "version": "1.3.2", + "version": "2.0.0", "description": "orbs-client-sdk", "main": "dist/orbs-client-sdk.js", "browser": "dist/orbs-client-sdk-web.js", diff --git a/src/codec/OpRunQuery.ts b/src/codec/OpRunQuery.ts index b6ae77f5..4ef3ffec 100644 --- a/src/codec/OpRunQuery.ts +++ b/src/codec/OpRunQuery.ts @@ -8,21 +8,19 @@ import * as Client from "../protocol/Client"; import * as Protocol from "../protocol/Protocol"; -import * as Keys from "../crypto/Keys"; -import * as Signature from "../crypto/Signature"; import { InternalMessage } from "membuffers"; import { NetworkType, networkTypeEncode } from "./NetworkType"; import { RequestStatus, requestStatusDecode } from "./RequestStatus"; import { ExecutionResult, executionResultDecode } from "./ExecutionResult"; import { Argument, packedArgumentsDecode, packedArgumentsEncode } from "./Arguments"; import { Event, packedEventsDecode } from "./Events"; +import { Signer } from "../crypto/Signer"; export interface RunQueryRequest { protocolVersion: number; virtualChainId: number; timestamp: Date; networkType: NetworkType; - publicKey: Uint8Array; contractName: string; methodName: string; inputArguments: Argument[]; @@ -37,15 +35,11 @@ export interface RunQueryResponse { blockTimestamp: Date; } -export function encodeRunQueryRequest(req: RunQueryRequest): Uint8Array { +export async function encodeRunQueryRequest(req: RunQueryRequest, signer: Signer): Promise { // validate if (req.protocolVersion != 1) { throw new Error(`expected ProtocolVersion 1, ${req.protocolVersion} given`); } - if (req.publicKey.byteLength != Keys.ED25519_PUBLIC_KEY_SIZE_BYTES) { - throw new Error(`expected PublicKey length ${Keys.ED25519_PUBLIC_KEY_SIZE_BYTES}, ${req.publicKey.byteLength} given`); - } - // encode method arguments const inputArgumentArray = packedArgumentsEncode(req.inputArguments); @@ -63,7 +57,7 @@ export function encodeRunQueryRequest(req: RunQueryRequest): Uint8Array { scheme: 0, eddsa: new Protocol.EdDSA01SignerBuilder({ networkType: networkType, - signerPublicKey: req.publicKey, + signerPublicKey: await signer.getPublicKey(), }), }), contractName: req.contractName, diff --git a/src/codec/OpSendTransaction.ts b/src/codec/OpSendTransaction.ts index 7baf4c66..bb3f5c4e 100644 --- a/src/codec/OpSendTransaction.ts +++ b/src/codec/OpSendTransaction.ts @@ -10,7 +10,6 @@ import { NetworkType, networkTypeEncode } from "./NetworkType"; import * as Client from "../protocol/Client"; import * as Protocol from "../protocol/Protocol"; import * as Keys from "../crypto/Keys"; -import * as Signature from "../crypto/Signature"; import * as Digest from "../crypto/Digest"; import { InternalMessage } from "membuffers"; import { Argument, packedArgumentsDecode, packedArgumentsEncode } from "./Arguments"; @@ -18,13 +17,13 @@ import { Event, packedEventsDecode } from "./Events"; import { RequestStatus, requestStatusDecode } from "./RequestStatus"; import { ExecutionResult, executionResultDecode } from "./ExecutionResult"; import { TransactionStatus, transactionStatusDecode } from "./TransactionStatus"; +import { Signer, ED25519_SIGNATURE_SIZE_BYTES } from "../crypto/Signer"; export interface SendTransactionRequest { protocolVersion: number; virtualChainId: number; timestamp: Date; networkType: NetworkType; - publicKey: Uint8Array; contractName: string; methodName: string; inputArguments: Argument[]; @@ -41,17 +40,11 @@ export interface SendTransactionResponse { blockTimestamp: Date; } -export function encodeSendTransactionRequest(req: SendTransactionRequest, privateKey: Uint8Array): [Uint8Array, Uint8Array] { +export async function encodeSendTransactionRequest(req: SendTransactionRequest, signer: Signer): Promise<[Uint8Array, Uint8Array]> { // validate if (req.protocolVersion != 1) { throw new Error(`expected ProtocolVersion 1, ${req.protocolVersion} given`); } - if (req.publicKey.byteLength != Keys.ED25519_PUBLIC_KEY_SIZE_BYTES) { - throw new Error(`expected PublicKey length ${Keys.ED25519_PUBLIC_KEY_SIZE_BYTES}, ${req.publicKey.byteLength} given`); - } - if (privateKey.byteLength != Keys.ED25519_PRIVATE_KEY_SIZE_BYTES) { - throw new Error(`expected PublicKey length ${Keys.ED25519_PRIVATE_KEY_SIZE_BYTES}, ${privateKey.byteLength} given`); - } // encode method arguments const inputArgumentArray = packedArgumentsEncode(req.inputArguments); @@ -73,14 +66,14 @@ export function encodeSendTransactionRequest(req: SendTransactionRequest, privat scheme: 0, eddsa: new Protocol.EdDSA01SignerBuilder({ networkType: networkType, - signerPublicKey: req.publicKey, + signerPublicKey: await signer.getPublicKey(), }), }), contractName: req.contractName, methodName: req.methodName, inputArgumentArray: inputArgumentArray, }), - signature: new Uint8Array(Signature.ED25519_SIGNATURE_SIZE_BYTES), + signature: new Uint8Array(ED25519_SIGNATURE_SIZE_BYTES), }), }); @@ -93,7 +86,7 @@ export function encodeSendTransactionRequest(req: SendTransactionRequest, privat // sign const txHash = Digest.calcTxHash(transactionBuf); - const sig = Signature.signEd25519(privateKey, txHash); + const sig = await signer.signEd25519(txHash); signedTransactionMsg.setBytes(1, sig); // return diff --git a/src/codec/contract.test.ts b/src/codec/contract.test.ts index 709222ee..8a687bb3 100644 --- a/src/codec/contract.test.ts +++ b/src/codec/contract.test.ts @@ -14,6 +14,7 @@ import { decodeGetTransactionReceiptProofResponse, encodeGetTransactionReceiptPr import { decodeGetTransactionStatusResponse, encodeGetTransactionStatusRequest } from "./OpGetTransactionStatus"; import { decodeRunQueryResponse, encodeRunQueryRequest } from "./OpRunQuery"; import { decodeSendTransactionResponse, encodeSendTransactionRequest } from "./OpSendTransaction"; +import { LocalSigner } from "../crypto/Signer"; describe("Codec contract", () => { let contractInput: any; @@ -30,22 +31,20 @@ describe("Codec contract", () => { for (let index = 0; index < contractInput.length; index++) { const inputScenario = contractInput[index]; const outputScenario = contractOutput[index]; - test(`Test Id: ${inputScenario.Test}`, () => { + test(`Test Id: ${inputScenario.Test}`, async () => { // SendTransactionRequest if (inputScenario.SendTransactionRequest) { - const [encoded, txId] = encodeSendTransactionRequest( + const signer = new LocalSigner({publicKey: jsonUnmarshalBase64Bytes(inputScenario.SendTransactionRequest.PublicKey), privateKey: jsonUnmarshalBase64Bytes(inputScenario.PrivateKey)}); + const [encoded, txId] = await encodeSendTransactionRequest( { protocolVersion: jsonUnmarshalNumber(inputScenario.SendTransactionRequest.ProtocolVersion), virtualChainId: jsonUnmarshalNumber(inputScenario.SendTransactionRequest.VirtualChainId), timestamp: new Date(inputScenario.SendTransactionRequest.Timestamp), networkType: inputScenario.SendTransactionRequest.NetworkType, - publicKey: jsonUnmarshalBase64Bytes(inputScenario.SendTransactionRequest.PublicKey), contractName: inputScenario.SendTransactionRequest.ContractName, methodName: inputScenario.SendTransactionRequest.MethodName, inputArguments: jsonUnmarshalArguments(inputScenario.SendTransactionRequest.InputArguments, inputScenario.SendTransactionRequest.InputArgumentsTypes), - }, - jsonUnmarshalBase64Bytes(inputScenario.PrivateKey), - ); + }, signer); const expected = jsonUnmarshalBase64Bytes(outputScenario.SendTransactionRequest); expect(encoded).toBeEqualToUint8Array(expected); const expectedTxId = jsonUnmarshalBase64Bytes(outputScenario.TxId); @@ -55,16 +54,19 @@ describe("Codec contract", () => { // RunQueryRequest if (inputScenario.RunQueryRequest) { - const encoded = encodeRunQueryRequest({ + // we don't have it in the source files but the signer can't be instantiated withouth the key + const stubPrivateKey = "k+kZmGoiR3/aAWeJzKMMuEGhNWUJOHFPhfAACmUHa9TfwGxb4kpnre6As1q08Ue7GjXFX/he2mn0Dvgnvd7Bcw=="; + const signer = new LocalSigner({publicKey: jsonUnmarshalBase64Bytes(inputScenario.RunQueryRequest.PublicKey), privateKey: jsonUnmarshalBase64Bytes(stubPrivateKey)}); + + const encoded = await encodeRunQueryRequest({ protocolVersion: jsonUnmarshalNumber(inputScenario.RunQueryRequest.ProtocolVersion), virtualChainId: jsonUnmarshalNumber(inputScenario.RunQueryRequest.VirtualChainId), timestamp: new Date(inputScenario.RunQueryRequest.Timestamp), networkType: inputScenario.RunQueryRequest.NetworkType, - publicKey: jsonUnmarshalBase64Bytes(inputScenario.RunQueryRequest.PublicKey), contractName: inputScenario.RunQueryRequest.ContractName, methodName: inputScenario.RunQueryRequest.MethodName, inputArguments: jsonUnmarshalArguments(inputScenario.RunQueryRequest.InputArguments, inputScenario.RunQueryRequest.InputArgumentsTypes), - }); + }, signer); const expected = jsonUnmarshalBase64Bytes(outputScenario.RunQueryRequest); expect(encoded).toBeEqualToUint8Array(expected); return; @@ -72,7 +74,7 @@ describe("Codec contract", () => { // GetTransactionStatusRequest if (inputScenario.GetTransactionStatusRequest) { - const encoded = encodeGetTransactionStatusRequest({ + const encoded = await encodeGetTransactionStatusRequest({ protocolVersion: jsonUnmarshalNumber(inputScenario.GetTransactionStatusRequest.ProtocolVersion), virtualChainId: jsonUnmarshalNumber(inputScenario.GetTransactionStatusRequest.VirtualChainId), txId: jsonUnmarshalBase64Bytes(inputScenario.GetTransactionStatusRequest.TxId), @@ -84,7 +86,7 @@ describe("Codec contract", () => { // GetTransactionReceiptProofRequest if (inputScenario.GetTransactionReceiptProofRequest) { - const encoded = encodeGetTransactionReceiptProofRequest({ + const encoded = await encodeGetTransactionReceiptProofRequest({ protocolVersion: jsonUnmarshalNumber(inputScenario.GetTransactionReceiptProofRequest.ProtocolVersion), virtualChainId: jsonUnmarshalNumber(inputScenario.GetTransactionReceiptProofRequest.VirtualChainId), txId: jsonUnmarshalBase64Bytes(inputScenario.GetTransactionReceiptProofRequest.TxId), @@ -96,7 +98,7 @@ describe("Codec contract", () => { // GetBlockRequest if (inputScenario.GetBlockRequest) { - const encoded = encodeGetBlockRequest({ + const encoded = await encodeGetBlockRequest({ protocolVersion: jsonUnmarshalNumber(inputScenario.GetBlockRequest.ProtocolVersion), virtualChainId: jsonUnmarshalNumber(inputScenario.GetBlockRequest.VirtualChainId), blockHeight: BigInt(inputScenario.GetBlockRequest.BlockHeight), diff --git a/src/crypto/Signature.test.ts b/src/crypto/Signer.test.ts similarity index 76% rename from src/crypto/Signature.test.ts rename to src/crypto/Signer.test.ts index 707067e5..c7395f47 100644 --- a/src/crypto/Signature.test.ts +++ b/src/crypto/Signer.test.ts @@ -6,7 +6,7 @@ * The above notice should be included in all copies or substantial portions of the software. */ -import * as Signature from "./Signature"; +import { signEd25519, verifyEd25519 } from "./Signer"; import { getTextEncoder } from "membuffers"; const someDataToSign = getTextEncoder().encode("this is what we want to sign"); @@ -14,9 +14,9 @@ const PublicKey1 = Buffer.from("92d469d7c004cc0b24a192d9457836bf38effa27536627ef const PrivateKey1 = Buffer.from("3b24b5f9e6b1371c3b5de2e402a96930eeafe52111bb4a1b003e5ecad3fab53892d469d7c004cc0b24a192d9457836bf38effa27536627ef60718b00b0f33152", "hex"); test("SignEd25519", () => { - const sig = Signature.signEd25519(PrivateKey1, someDataToSign); - expect(Signature.verifyEd25519(PublicKey1, someDataToSign, sig)).toBe(true); + const sig = signEd25519(PrivateKey1, someDataToSign); + expect(verifyEd25519(PublicKey1, someDataToSign, sig)).toBe(true); sig[0] += 1; // corrupt the signature - expect(Signature.verifyEd25519(PublicKey1, someDataToSign, sig)).toBe(false); + expect(verifyEd25519(PublicKey1, someDataToSign, sig)).toBe(false); }); diff --git a/src/crypto/Signature.ts b/src/crypto/Signer.ts similarity index 66% rename from src/crypto/Signature.ts rename to src/crypto/Signer.ts index 6240fd45..91a91814 100644 --- a/src/crypto/Signature.ts +++ b/src/crypto/Signer.ts @@ -11,6 +11,36 @@ import elliptic from "elliptic"; export const ED25519_SIGNATURE_SIZE_BYTES = 64; +export interface Signer { + getPublicKey(): Promise; + signEd25519(data: Uint8Array): Promise; +} + +export class LocalSigner implements Signer { + constructor( + private fields: { + publicKey: Uint8Array; + privateKey: Uint8Array; + } + ) { + if (this.fields.publicKey.byteLength != Keys.ED25519_PUBLIC_KEY_SIZE_BYTES) { + throw new Error(`expected PublicKey length ${Keys.ED25519_PUBLIC_KEY_SIZE_BYTES}, ${this.fields.publicKey.byteLength} given`); + } + + if (this.fields.privateKey.byteLength != Keys.ED25519_PRIVATE_KEY_SIZE_BYTES) { + throw new Error(`expected PublicKey length ${Keys.ED25519_PRIVATE_KEY_SIZE_BYTES}, ${this.fields.privateKey.byteLength} given`); + } + } + + async signEd25519(data: Uint8Array): Promise { + return signEd25519(this.fields.privateKey, data); + } + + async getPublicKey(): Promise { + return this.fields.publicKey; + } +} + export function signEd25519(privateKey: Uint8Array, data: Uint8Array): Uint8Array { if (privateKey.byteLength != Keys.ED25519_PRIVATE_KEY_SIZE_BYTES) { throw new Error(`cannot sign with ed25519, private key invalid with length ${privateKey.byteLength}`); diff --git a/src/index.ts b/src/index.ts index 8eddb9ec..6322db44 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,4 +13,5 @@ export { Client, PROCESSOR_TYPE_NATIVE, PROCESSOR_TYPE_JAVASCRIPT } from "./orbs export { calcClientAddressOfEd25519PublicKey, contractNameToAddressAsBytes } from "./crypto/Digest"; export { encodeHex, decodeHex } from "./crypto/Encoding"; export { argUint32, argUint64, argString, argBytes, argAddress } from "./codec/Arguments"; -export { NetworkType } from "./codec/NetworkType"; \ No newline at end of file +export { NetworkType } from "./codec/NetworkType"; +export { LocalSigner } from "./crypto/Signer"; \ No newline at end of file diff --git a/src/orbs/Client.ts b/src/orbs/Client.ts index 6c04a68b..dbe419c7 100644 --- a/src/orbs/Client.ts +++ b/src/orbs/Client.ts @@ -15,6 +15,7 @@ import { decodeGetTransactionStatusResponse, encodeGetTransactionStatusRequest, import { decodeGetTransactionReceiptProofResponse, encodeGetTransactionReceiptProofRequest, GetTransactionReceiptProofResponse } from "../codec/OpGetTransactionReceiptProof"; import { decodeGetBlockResponse, encodeGetBlockRequest, GetBlockResponse } from "../codec/OpGetBlock"; import axios, { AxiosResponse } from "axios"; +import { Signer } from "../crypto/Signer"; import { getTextDecoder } from "membuffers"; const PROTOCOL_VERSION = 1; @@ -29,46 +30,44 @@ export const PROCESSOR_TYPE_NATIVE = 1; export const PROCESSOR_TYPE_JAVASCRIPT = 2; export class Client { - constructor(private endpoint: string, private virtualChainId: number, private networkType: NetworkType) {} + constructor(private endpoint: string, private virtualChainId: number, private networkType: NetworkType, private signer: Signer) {} - createTransaction(publicKey: Uint8Array, privateKey: Uint8Array, contractName: string, methodName: string, inputArguments: Argument[]): [Uint8Array, string] { - const [req, rawTxId] = encodeSendTransactionRequest( + async createTransaction(contractName: string, methodName: string, inputArguments: Argument[]): Promise<[Uint8Array, string]> { + const [req, rawTxId] = await encodeSendTransactionRequest( { protocolVersion: PROTOCOL_VERSION, virtualChainId: this.virtualChainId, timestamp: new Date(), networkType: this.networkType, - publicKey: publicKey, contractName: contractName, methodName: methodName, inputArguments: inputArguments, }, - privateKey, + this.signer, ); return [req, Encoding.encodeHex(rawTxId)]; } - createDeployTransaction(publicKey: Uint8Array, privateKey: Uint8Array, contractName: string, processorType: number, ...sources: Uint8Array[]): [Uint8Array, string] { + async createDeployTransaction(contractName: string, processorType: number, ...sources: Uint8Array[]): Promise<[Uint8Array, string]> { const inputArguments: Argument[] = [ argString(contractName), argUint32(processorType), ...sources.map(argBytes) ]; - return this.createTransaction(publicKey, privateKey, "_Deployments", "deployService", inputArguments); + return this.createTransaction("_Deployments", "deployService", inputArguments); } - createQuery(publicKey: Uint8Array, contractName: string, methodName: string, inputArguments: Argument[]): Uint8Array { + async createQuery(contractName: string, methodName: string, inputArguments: Argument[]): Promise { return encodeRunQueryRequest({ protocolVersion: PROTOCOL_VERSION, virtualChainId: this.virtualChainId, timestamp: new Date(), networkType: this.networkType, - publicKey: publicKey, contractName: contractName, methodName: methodName, inputArguments: inputArguments, - }); + }, this.signer); } protected createGetTransactionStatusPayload(txId: string): Uint8Array {