├── .nvmrc ├── README.md ├── .gitignore ├── .npmignore ├── test ├── StateUpdater.class ├── TestFunction.class ├── ValidateLedger.class ├── TestFunction_cassandra_schema.json ├── TestFunction.java ├── StateUpdater.java ├── signature_validator.test.js ├── client_service_with_indexeddb.test.js ├── integration_auditor.test.js └── integration.test.js ├── .circleci ├── docker-compose-open-cassandra-port.yml ├── README_CI.md ├── function_schema.cql └── config.yml ├── .eslintrc.json ├── example ├── sample.key.pem ├── sample.crt.pem └── index.html ├── webpack.config.js ├── dist └── scalardl-web-client-sdk.bundle.js.LICENSE.txt ├── karma.auditor.conf.js ├── karma.conf.js ├── lib └── keyutil.js ├── package.json ├── signature_validator.js ├── scalardl-web-client-sdk.js ├── signer.js ├── indexdb.js ├── docs └── README.md ├── LICENSE └── scalar_grpc_web_pb.js /.nvmrc: -------------------------------------------------------------------------------- 1 | v14.16.0 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | docs/README.md -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | example/ 2 | Makefile 3 | .eslintrc.json 4 | test/ 5 | .circleci/ 6 | -------------------------------------------------------------------------------- /test/StateUpdater.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scalar-labs/scalardl-web-client-sdk/HEAD/test/StateUpdater.class -------------------------------------------------------------------------------- /test/TestFunction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scalar-labs/scalardl-web-client-sdk/HEAD/test/TestFunction.class -------------------------------------------------------------------------------- /test/ValidateLedger.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scalar-labs/scalardl-web-client-sdk/HEAD/test/ValidateLedger.class -------------------------------------------------------------------------------- /.circleci/docker-compose-open-cassandra-port.yml: -------------------------------------------------------------------------------- 1 | version: "3.5" 2 | services: 3 | cassandra: 4 | ports: 5 | - "9042:9042" 6 | 7 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "parserOptions": { 3 | "ecmaVersion": 2017 4 | }, 5 | "env": { 6 | "es6": true 7 | }, 8 | "extends": ["google"] 9 | } 10 | -------------------------------------------------------------------------------- /.circleci/README_CI.md: -------------------------------------------------------------------------------- 1 | ## Setting up CircleCI for Scalar DL Web Client SDK 2 | 3 | ### The guideline can be found [here](https://github.com/scalarindetail/scalardl-node-client-sdk/tree/feature/update_readme_circleci/.circleci) 4 | -------------------------------------------------------------------------------- /test/TestFunction_cassandra_schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "foo.bar": { 3 | "transaction": true, 4 | "partition-key": [ 5 | "column_a" 6 | ], 7 | "columns": { 8 | "column_a": "TEXT" 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /example/sample.key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PRIVATE KEY----- 2 | MHcCAQEEIIbElY/Vs5nEoVGsHZ8G9icxZcsRlT2DcHIfxFNkZrnHoAoGCCqGSM49 3 | AwEHoUQDQgAE/TzGEcYJNcwe5d+BlPuxuwiIhMhKpMpTMZM94L+bRhDPFn4nMigc 4 | Cijley7qhOfwplVrTtnNLTNMD82ttwnR7g== 5 | -----END EC PRIVATE KEY----- 6 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = { 4 | entry: './scalardl-web-client-sdk.js', 5 | output: { 6 | filename: 'scalardl-web-client-sdk.bundle.js', 7 | path: path.resolve(__dirname, 'dist'), 8 | library: 'Scalar', 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /dist/scalardl-web-client-sdk.bundle.js.LICENSE.txt: -------------------------------------------------------------------------------- 1 | /*! (c) Stefan Thomas | https://github.com/bitcoinjs/bitcoinjs-lib 2 | */ 3 | 4 | /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ 5 | */ 6 | 7 | /*! Mike Samuel (c) 2009 | code.google.com/p/json-sans-eval 8 | */ 9 | 10 | /** @license URI.js v4.2.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */ 11 | -------------------------------------------------------------------------------- /.circleci/function_schema.cql: -------------------------------------------------------------------------------- 1 | CREATE KEYSPACE IF NOT EXISTS foo WITH REPLICATION ={'class': 'SimpleStrategy', 'replication_factor': 1}; 2 | 3 | CREATE TABLE foo.bar ( 4 | column_a TEXT, 5 | column_b TEXT, 6 | 7 | before_column_b TEXT, 8 | 9 | tx_id text, 10 | tx_prepared_at bigint, 11 | tx_committed_at bigint, 12 | tx_state int, 13 | tx_version int, 14 | 15 | before_tx_id text, 16 | before_tx_prepared_at bigint, 17 | before_tx_committed_at bigint, 18 | before_tx_state int, 19 | before_tx_version int, 20 | 21 | PRIMARY KEY (column_a), 22 | ); 23 | -------------------------------------------------------------------------------- /karma.auditor.conf.js: -------------------------------------------------------------------------------- 1 | module.exports = function(config) { 2 | config.set({ 3 | frameworks: ['mocha', 'chai'], 4 | files: ['test/integration_auditor.test.js'], 5 | reporters: ['progress'], 6 | preprocessors: { 7 | 'test/*.test.js': ['webpack'], 8 | }, 9 | webpack: {}, 10 | htmlReporter: { 11 | outputFile: 'test/test-reports/integration-test-auditor.html', 12 | }, 13 | listenAddress: '127.0.0.1', 14 | hostname: 'localhost', 15 | colors: true, 16 | logLevel: config.LOG_WARN, 17 | singleRun: true, 18 | browsers: ['ChromeHeadless'], 19 | }); 20 | }; 21 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | module.exports = function(config) { 2 | config.set({ 3 | frameworks: ['mocha', 'chai'], 4 | files: [ 5 | 'test/integration.test.js', 6 | 'test/signature_validator.test.js', 7 | 'test/client_service_with_indexeddb.test.js', 8 | ], 9 | reporters: ['progress'], 10 | preprocessors: { 11 | 'test/*.test.js': ['webpack'], 12 | }, 13 | webpack: {}, 14 | htmlReporter: { 15 | outputFile: 'test/test-reports/integration-test.html', 16 | }, 17 | listenAddress: '127.0.0.1', 18 | hostname: 'localhost', 19 | colors: true, 20 | logLevel: config.LOG_WARN, 21 | singleRun: true, 22 | browsers: ['ChromeHeadless'], 23 | }); 24 | }; 25 | -------------------------------------------------------------------------------- /test/TestFunction.java: -------------------------------------------------------------------------------- 1 | package com.org1.function; 2 | 3 | import com.scalar.db.api.Put; 4 | import com.scalar.db.io.Key; 5 | import com.scalar.db.io.TextValue; 6 | import com.scalar.db.io.Value; 7 | import com.scalar.dl.ledger.database.Database; 8 | import com.scalar.dl.ledger.function.Function; 9 | import java.util.Optional; 10 | import javax.json.JsonObject; 11 | 12 | public class TestFunction extends Function { 13 | @Override 14 | public void invoke( 15 | Database database, 16 | Optional functionArgument, 17 | JsonObject contractArgument, 18 | Optional contractProperties) { 19 | String mockedId = contractArgument.getString("asset_id"); 20 | Put put = 21 | (new Put(new Key(new Value[] {new TextValue("column_a", mockedId)}))) 22 | .forNamespace("foo") 23 | .forTable("bar"); 24 | database.put(put); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib/keyutil.js: -------------------------------------------------------------------------------- 1 | const jsrsasign = require('jsrsasign'); 2 | 3 | /** 4 | * @param {Object} jwk 5 | * @return {CryptoKey} 6 | */ 7 | async function toCryptoKeyFromJwk(jwk) { 8 | return window.crypto.subtle.importKey( 9 | 'jwk', 10 | jwk, 11 | { 12 | name: 'ECDSA', 13 | namedCurve: 'P-256', 14 | }, 15 | false, // extractable is false (which means unextractable) 16 | ['sign'], 17 | ); 18 | } 19 | 20 | /** 21 | * @param {String} pkcs1 22 | * @return {Object} 23 | */ 24 | function toJwkFromPkcs1(pkcs1) { 25 | pkcs1 = pkcs1 26 | .replace('-----BEGIN EC PRIVATE KEY-----', '') 27 | .replace('-----END EC PRIVATE KEY-----', '') 28 | .replace(/\r\n/g, ''); 29 | const key = jsrsasign.KEYUTIL.getKey( 30 | jsrsasign.b64utohex(pkcs1), 31 | null, 32 | 'pkcs5prv', 33 | ); 34 | 35 | return jsrsasign.KEYUTIL.getJWKFromKey(key); 36 | } 37 | 38 | module.exports = { 39 | toCryptoKeyFromJwk, 40 | toJwkFromPkcs1, 41 | }; 42 | -------------------------------------------------------------------------------- /example/sample.crt.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICjTCCAjKgAwIBAgIUOt6KMwZpclftxxQzdJsptjxNjdMwCgYIKoZIzj0EAwIw 3 | bzELMAkGA1UEBhMCSlAxDjAMBgNVBAgTBVRva3lvMQ4wDAYDVQQHEwVUb2t5bzEf 4 | MB0GA1UEChMWU2FtcGxlIEludGVybWVkaWF0ZSBDQTEfMB0GA1UEAxMWU2FtcGxl 5 | IEludGVybWVkaWF0ZSBDQTAeFw0xODA5MTAwODA2MDBaFw0yMTA5MDkwODA2MDBa 6 | MEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJ 7 | bnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNC 8 | AAT9PMYRxgk1zB7l34GU+7G7CIiEyEqkylMxkz3gv5tGEM8WficyKBwKKOV7LuqE 9 | 5/CmVWtO2c0tM0wPza23CdHuo4HVMIHSMA4GA1UdDwEB/wQEAwIFoDATBgNVHSUE 10 | DDAKBggrBgEFBQcDAjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBS1Neb+7m9wyM2h 11 | oRs75x86gbzS5TAfBgNVHSMEGDAWgBR+Y+v8yByDNp39G7trYrTfZ0UjJzAxBggr 12 | BgEFBQcBAQQlMCMwIQYIKwYBBQUHMAGGFWh0dHA6Ly9sb2NhbGhvc3Q6ODg4OTAq 13 | BgNVHR8EIzAhMB+gHaAbhhlodHRwOi8vbG9jYWxob3N0Ojg4ODgvY3JsMAoGCCqG 14 | SM49BAMCA0kAMEYCIQDxqVzuhLWxnX6fajucPcjCcvtWTl/4fAAN/n8Py1qmfwIh 15 | AKtP641f4dGZTV0R6uMYDrZjunwbG+kmt9+vSuE8rjO0 16 | -----END CERTIFICATE----- 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@scalar-labs/scalardl-javascript-sdk-base": "^3.4.1", 4 | "dexie": "^3.0.3", 5 | "google-protobuf": "^3.19.1", 6 | "grpc-web": "^1.3.0", 7 | "jsrsasign": "^10.4.1" 8 | }, 9 | "name": "@scalar-labs/scalardl-web-client-sdk", 10 | "version": "3.4.0", 11 | "description": "The web client SDK for Scalar DL", 12 | "main": "scalardl-web-client-sdk.js", 13 | "author": "Scalar, Inc.", 14 | "license": "AGPL-3.0-or-later", 15 | "engine": { 16 | "node": ">=16.0.0" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git@github.com:scalar-labs/scalardl-web-client-sdk.git" 21 | }, 22 | "devDependencies": { 23 | "arraybuffer-loader": "^1.0.8", 24 | "chai": "^4.3.0", 25 | "chai-as-promised": "^7.1.1", 26 | "eslint": "^8.1.0", 27 | "eslint-config-google": "^0.14.0", 28 | "karma": "^6.3.6", 29 | "karma-chai": "^0.1.0", 30 | "karma-chrome-launcher": "^3.1.0", 31 | "karma-htmlfile-reporter": "^0.3.8", 32 | "karma-mocha": "^2.0.1", 33 | "karma-webpack": "^5.0.0", 34 | "mocha": "^9.1.3", 35 | "webpack": "^5.61.0", 36 | "webpack-cli": "^4.9.1" 37 | }, 38 | "scripts": { 39 | "test": "karma start", 40 | "test-auditor": "karma start karma.auditor.conf.js", 41 | "bundle": "webpack" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /signature_validator.js: -------------------------------------------------------------------------------- 1 | const jsrsasign = require('jsrsasign'); 2 | 3 | /** @description A validator of ECDSA-SHA256 signature */ 4 | class SignatureValidator { 5 | /** 6 | * @param {String} certificate PEM 7 | */ 8 | constructor(certificate) { 9 | this.publicKey = jsrsasign.KEYUTIL.getPEM( 10 | jsrsasign.KEYUTIL.getKey(certificate), 11 | 'PKCS8PUB', 12 | ); 13 | } 14 | 15 | /** 16 | * @param {Uint8Array} toBeValidated 17 | * @param {Uint8Array} signature 18 | * @return {Boolean} 19 | */ 20 | async validate(toBeValidated, signature) { 21 | if (!this.key) { 22 | const pkcs8 = this.publicKey 23 | .replace('-----BEGIN PUBLIC KEY-----', '') 24 | .replace('-----END PUBLIC KEY-----', '') 25 | .replace(/(\r\n|\n|\r)/gm, ''); 26 | 27 | this.key = await window.crypto.subtle.importKey( 28 | 'spki', 29 | jsrsasign.hextoArrayBuffer(jsrsasign.b64utohex(pkcs8)), 30 | { 31 | name: 'ECDSA', 32 | namedCurve: 'P-256', 33 | }, 34 | false, 35 | ['verify'], 36 | ); 37 | } 38 | 39 | return window.crypto.subtle.verify( 40 | {name: 'ECDSA', hash: 'SHA-256'}, 41 | this.key, 42 | signature, 43 | toBeValidated, 44 | ); 45 | } 46 | } 47 | 48 | module.exports = { 49 | SignatureValidator, 50 | }; 51 | -------------------------------------------------------------------------------- /test/StateUpdater.java: -------------------------------------------------------------------------------- 1 | package com.org1.contract; 2 | 3 | import com.scalar.dl.ledger.asset.Asset; 4 | import com.scalar.dl.ledger.contract.Contract; 5 | import com.scalar.dl.ledger.exception.ContractContextException; 6 | import com.scalar.dl.ledger.database.Ledger; 7 | import java.util.Optional; 8 | import javax.json.Json; 9 | import javax.json.JsonNumber; 10 | import javax.json.JsonObject; 11 | 12 | public class StateUpdater extends Contract { 13 | 14 | @Override 15 | public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { 16 | if (argument.containsKey("asset_id") && argument.containsKey("state")) { 17 | if (!properties.isPresent()) { 18 | throw new ContractContextException("please set a properties"); 19 | } else { 20 | String assetId = argument.getString("asset_id"); 21 | String propertiesValue = ((JsonObject) properties.get()).getString("properties"); 22 | JsonNumber state = argument.getJsonNumber("state"); 23 | Optional asset = ledger.get(assetId); 24 | JsonObject jsonObject = 25 | Json.createObjectBuilder() 26 | .add("asset_id", assetId) 27 | .add("state", state) 28 | .add("properties", propertiesValue) 29 | .build(); 30 | if (!asset.isPresent() || ((Asset) asset.get()).data().getJsonNumber("state") != state) { 31 | ledger.put(assetId, Json.createObjectBuilder().add("state", state).build()); 32 | } 33 | 34 | return jsonObject; 35 | } 36 | } else { 37 | throw new ContractContextException("please set asset_id and state in the argument"); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /test/signature_validator.test.js: -------------------------------------------------------------------------------- 1 | const certificate = ` 2 | -----BEGIN CERTIFICATE----- 3 | MIICjTCCAjKgAwIBAgIUOt6KMwZpclftxxQzdJsptjxNjdMwCgYIKoZIzj0EAwIw 4 | bzELMAkGA1UEBhMCSlAxDjAMBgNVBAgTBVRva3lvMQ4wDAYDVQQHEwVUb2t5bzEf 5 | MB0GA1UEChMWU2FtcGxlIEludGVybWVkaWF0ZSBDQTEfMB0GA1UEAxMWU2FtcGxl 6 | IEludGVybWVkaWF0ZSBDQTAeFw0xODA5MTAwODA2MDBaFw0yMTA5MDkwODA2MDBa 7 | MEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJ 8 | bnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNC 9 | AAT9PMYRxgk1zB7l34GU+7G7CIiEyEqkylMxkz3gv5tGEM8WficyKBwKKOV7LuqE 10 | 5/CmVWtO2c0tM0wPza23CdHuo4HVMIHSMA4GA1UdDwEB/wQEAwIFoDATBgNVHSUE 11 | DDAKBggrBgEFBQcDAjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBS1Neb+7m9wyM2h 12 | oRs75x86gbzS5TAfBgNVHSMEGDAWgBR+Y+v8yByDNp39G7trYrTfZ0UjJzAxBggr 13 | BgEFBQcBAQQlMCMwIQYIKwYBBQUHMAGGFWh0dHA6Ly9sb2NhbGhvc3Q6ODg4OTAq 14 | BgNVHR8EIzAhMB+gHaAbhhlodHRwOi8vbG9jYWxob3N0Ojg4ODgvY3JsMAoGCCqG 15 | SM49BAMCA0kAMEYCIQDxqVzuhLWxnX6fajucPcjCcvtWTl/4fAAN/n8Py1qmfwIh 16 | AKtP641f4dGZTV0R6uMYDrZjunwbG+kmt9+vSuE8rjO0 17 | -----END CERTIFICATE----- 18 | `; 19 | 20 | const privateKey = 21 | 'MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0waw' + 22 | 'IBAQQghsSVj9WzmcShUawdnwb2JzFlyxGVPYNwch/EU' + 23 | '2RmucehRANCAAT9PMYRxgk1zB7l34GU+7G7CIiEyEqky' + 24 | 'lMxkz3gv5tGEM8WficyKBwKKOV7LuqE5/CmVWtO2c0tM0wPza23CdHu'; 25 | 26 | const {SignatureValidator} = require('../signature_validator.js'); 27 | const jsrsasign = require('jsrsasign'); 28 | 29 | const validator = new SignatureValidator(certificate); 30 | 31 | let testingKey; 32 | before(async () => { 33 | testingKey = await window.crypto.subtle.importKey( 34 | 'pkcs8', 35 | jsrsasign.hextoArrayBuffer(jsrsasign.b64utohex(privateKey)), 36 | { 37 | name: 'ECDSA', 38 | namedCurve: 'P-256', 39 | }, 40 | false, 41 | ['sign'], 42 | ); 43 | }); 44 | 45 | describe('SignatureValidator', async () => { 46 | it('should be able to verify the content', async () => { 47 | const testingContent = new Uint8Array([0, 1, 2, 4]); 48 | const signature = await window.crypto.subtle.sign( 49 | {name: 'ECDSA', hash: 'SHA-256'}, 50 | testingKey, 51 | testingContent, 52 | ); 53 | 54 | const validated = await validator.validate(testingContent, signature); 55 | 56 | assert.equal(true, validated); 57 | }); 58 | 59 | it('should be able to verify the negative content', async () => { 60 | const correctContent = new Uint8Array([0, 1, 2, 4]); 61 | const signature = await window.crypto.subtle.sign( 62 | {name: 'ECDSA', hash: 'SHA-256'}, 63 | testingKey, 64 | correctContent, 65 | ); 66 | const wrongContent = new Uint8Array([0]); 67 | 68 | const validated = await validator.validate(wrongContent, signature); 69 | 70 | assert.equal(false, validated); 71 | }); 72 | }); 73 | -------------------------------------------------------------------------------- /scalardl-web-client-sdk.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-invalid-this */ 2 | const { 3 | ClientServiceBase, 4 | StatusCode, 5 | ClientProperties, 6 | } = require('@scalar-labs/scalardl-javascript-sdk-base'); 7 | 8 | const protobuf = require('./scalar_pb'); 9 | const { 10 | LedgerClient, 11 | LedgerPrivilegedClient, 12 | AuditorClient, 13 | AuditorPrivilegedClient, 14 | } = require('./scalar_grpc_web_pb'); 15 | 16 | const {SignerFactory} = require('./signer'); 17 | const { 18 | ClientServiceWithIndexedDb, 19 | IndexedDbKeyNotFoundError, 20 | IndexedDbOperationError, 21 | } = require('./indexdb'); 22 | 23 | /** 24 | * This class inherits ClientServiceBase. 25 | * It needs to be constructed with LedgerClient 26 | * and protobuf messages that are generated by gRPC tools 27 | * @class 28 | */ 29 | class ClientService extends ClientServiceBase { 30 | /** 31 | * Inject LedgerClient and protobuf messages 32 | * @constructor 33 | * @param {Object} properties JSON Object used for setting client properties 34 | */ 35 | constructor(properties) { 36 | const clientProperties = new ClientProperties(properties); 37 | 38 | const host = clientProperties.getServerHost(); 39 | const auditorHost = clientProperties.getAuditorHost(); 40 | const tlsEnabled = clientProperties.getTlsEnabled(); 41 | const ledgerClientServiceURL = `${ 42 | tlsEnabled ? 'https' : 'http' 43 | }://${host}:${clientProperties.getServerPort()}`; 44 | const ledgerPriviledgedClientServiceURL = `${ 45 | tlsEnabled ? 'https' : 'http' 46 | }://${host}:${clientProperties.getServerPrivilegedPort()}`; 47 | const auditorClientServiceURL = `${ 48 | tlsEnabled ? 'https' : 'http' 49 | }://${auditorHost}:${clientProperties.getAuditorPort()}`; 50 | const auditorPriviledgedClientServiceURL = `${ 51 | tlsEnabled ? 'https' : 'http' 52 | }://${auditorHost}:${clientProperties.getAuditorPrivilegedPort()}`; 53 | 54 | const services = { 55 | ledgerClient: new LedgerClient(ledgerClientServiceURL), 56 | ledgerPrivileged: new LedgerPrivilegedClient( 57 | ledgerPriviledgedClientServiceURL, 58 | ), 59 | auditorClient: new AuditorClient(auditorClientServiceURL), 60 | auditorPrivileged: new AuditorPrivilegedClient( 61 | auditorPriviledgedClientServiceURL, 62 | ), 63 | signerFactory: new SignerFactory(), 64 | }; 65 | 66 | const metadata = {}; 67 | if (clientProperties.getAuthorizationCredential()) { 68 | metadata.Authorization = clientProperties.getAuthorizationCredential(); 69 | } 70 | super(services, protobuf, properties, metadata); 71 | } 72 | } 73 | 74 | module.exports = { 75 | ClientService, 76 | ClientServiceWithIndexedDb, 77 | IndexedDbKeyNotFoundError, 78 | IndexedDbOperationError, 79 | StatusCode, 80 | }; 81 | -------------------------------------------------------------------------------- /signer.js: -------------------------------------------------------------------------------- 1 | const {toCryptoKeyFromJwk, toJwkFromPkcs1} = require('./lib/keyutil'); 2 | 3 | /** @description The signer based on Web Crypto API */ 4 | class WebCryptoSigner { 5 | /** 6 | * @param {String|Object} key key can be a CryptoKey or PKCS#1 PEM 7 | */ 8 | constructor(key) { 9 | if (typeof key == 'string') { 10 | this.pkcs1 = key; 11 | } else if (typeof key === 'object') { 12 | this.key = key; 13 | } else { 14 | throw new Error( 15 | 'key type should be either String (PEM) or Object (CryptoKey)', 16 | ); 17 | } 18 | } 19 | 20 | /** 21 | * @param {Uint8Array} content 22 | * @return {Uint8Array} 23 | */ 24 | async sign(content) { 25 | let key; 26 | if (this.key) { 27 | key = this.key; 28 | } else { 29 | if (!this.jwk) { 30 | this.jwk = await toJwkFromPkcs1(this.pkcs1); 31 | } 32 | try { 33 | key = await toCryptoKeyFromJwk(this.jwk); 34 | } catch (_) { 35 | throw new Error('Failed load the PEM file'); 36 | } 37 | } 38 | 39 | const algorithm = { 40 | // EcdsaParams 41 | name: 'ECDSA', 42 | hash: 'SHA-256', 43 | }; 44 | const data = content; 45 | 46 | try { 47 | const signature = await window.crypto.subtle.sign(algorithm, key, data); 48 | return this._P1363ToDer(new Uint8Array(signature)); 49 | } catch (_) { 50 | throw new Error(`Failed to sign the request`); 51 | } 52 | } 53 | 54 | /** 55 | * @param {Uint8Array} sig - P1363 signature 56 | * @return {Uint8Array} DER signature 57 | * 58 | * This function is taken from the SDK of token.io (https://github.com/tokenio/sdk-js) 59 | * 60 | * Copyright (c) 2020, Token, Inc. (https://token.io) 61 | * Permission to use, copy, modify, and distribute this software for any 62 | * purpose with or without fee is hereby granted, provided that the above 63 | * copyright notice and this permission notice appear in all copies. 64 | * 65 | * Converts an ECDSA signature from P1363 to DER format 66 | * 67 | * IEEE P1363: bytes array of [ 68 | * r, 69 | * s 70 | * ] 71 | * 72 | * ASN.1 DER: bytes array of [ 73 | * 0x30 (DER sequence tag), 74 | * (length of the bytes after this byte), 75 | * 0x02 (DER integer tag), 76 | * (length of the bytes of r), 77 | * (padding, if necessary) 78 | * r, 79 | * 0x02 (DER integer tag), 80 | * (length of the bytes of s), 81 | * (padding, if necessary) 82 | * s 83 | * ] 84 | */ 85 | _P1363ToDer(sig) { 86 | const signature = Array.from(sig, (x) => 87 | ('00' + x.toString(16)).slice(-2), 88 | ).join(''); 89 | let r = signature.substr(0, signature.length / 2); 90 | let s = signature.substr(signature.length / 2); 91 | r = r.replace(/^(00)+/, ''); 92 | s = s.replace(/^(00)+/, ''); 93 | if ((parseInt(r, 16) & '0x80') > 0) r = `00${r}`; 94 | if ((parseInt(s, 16) & '0x80') > 0) s = `00${s}`; 95 | const rString = `02${(r.length / 2).toString(16).padStart(2, '0')}${r}`; 96 | const sString = `02${(s.length / 2).toString(16).padStart(2, '0')}${s}`; 97 | const derSig = `30${((rString.length + sString.length) / 2) 98 | .toString(16) 99 | .padStart(2, '0')}${rString}${sString}`; 100 | return new Uint8Array( 101 | derSig.match(/[\da-f]{2}/gi).map((h) => parseInt(h, 16)), 102 | ); 103 | } 104 | } 105 | 106 | /** @description A factory to create EllipticSigner by given PEM */ 107 | class SignerFactory { 108 | /** 109 | * @param {String|Object} key 110 | * @return {WebCryptoSigner} 111 | */ 112 | create(key) { 113 | return new WebCryptoSigner(key); 114 | } 115 | } 116 | 117 | module.exports = { 118 | SignerFactory, 119 | }; 120 | -------------------------------------------------------------------------------- /indexdb.js: -------------------------------------------------------------------------------- 1 | const {toCryptoKeyFromJwk, toJwkFromPkcs1} = require('./lib/keyutil'); 2 | const Dexie = require('dexie').default; 3 | const KEYSTORE_DATABASE_NAME = 'scalar'; 4 | const { 5 | ClientProperties, 6 | ClientPropertiesField, 7 | } = require('@scalar-labs/scalardl-javascript-sdk-base'); 8 | 9 | /** 10 | * @description 11 | * This class delegates two functions related indexedDB to for ClientService 12 | */ 13 | class ClientServiceWithIndexedDb { 14 | /** 15 | * @param {ClientService} clientService 16 | * @return {ClientService} 17 | */ 18 | constructor(clientService) { 19 | /** 20 | * @description 21 | * Use indexedDB and check if it is necessary to load keys for the users 22 | * @throws {Error} 23 | */ 24 | const getIndexedDb = async function() { 25 | const db = new Dexie(KEYSTORE_DATABASE_NAME); 26 | db.version(1).stores({keystore: 'id'}); 27 | const clientProperties = new ClientProperties( 28 | this.properties, 29 | [ 30 | ClientPropertiesField.CERT_HOLDER_ID, 31 | ClientPropertiesField.CERT_VERSION, 32 | ], // cert_holder_id cert_version are required 33 | ); 34 | const cryptoKey = clientProperties.getPrivateKeyCryptoKey(); 35 | const pem = clientProperties.getPrivateKeyPem(); 36 | const keyId = 37 | `${clientProperties.getCertHolderId()}_` + 38 | `${clientProperties.getCertVersion()}`; 39 | 40 | let key; 41 | try { 42 | if (cryptoKey || pem) { 43 | key = cryptoKey || (await toCryptoKeyFromJwk(toJwkFromPkcs1(pem))); 44 | await db.keystore.put({id: keyId, key: key}); 45 | } else { 46 | const item = await db.keystore.get(keyId); 47 | key = item && item.key; 48 | } 49 | } catch (e) { 50 | if (e instanceof Dexie.DexieError) { 51 | throw new IndexedDbOperationError(e.message); 52 | } else { 53 | throw e; 54 | } 55 | } 56 | 57 | if (!(key instanceof CryptoKey)) { 58 | throw new IndexedDbKeyNotFoundError(); 59 | } 60 | 61 | this.properties['scalar.dl.client.private_key_cryptokey'] = key; 62 | delete this.properties['scalar.dl.client.private_key_pem']; 63 | }.bind(clientService); 64 | 65 | /** 66 | * @description 67 | * Remove the private key stored in indexedDB for `cert_holder_id` 68 | */ 69 | const deleteIndexedDb = async function() { 70 | const db = new Dexie(KEYSTORE_DATABASE_NAME); 71 | db.version(1).stores({keystore: 'id'}); 72 | const clientProperties = new ClientProperties( 73 | this.properties, 74 | [ 75 | ClientPropertiesField.CERT_HOLDER_ID, 76 | ClientPropertiesField.CERT_VERSION, 77 | ], // cert_holder_id and cert_version are required 78 | ); 79 | const keyId = 80 | `${clientProperties.getCertHolderId()}_` + 81 | `${clientProperties.getCertVersion()}`; 82 | 83 | try { 84 | await db.keystore.delete(keyId); 85 | } catch (e) { 86 | throw new IndexedDbOperationError(e.message); 87 | } 88 | }.bind(clientService); 89 | 90 | clientService.deleteIndexedDb = deleteIndexedDb; 91 | clientService.getIndexedDb = getIndexedDb; 92 | 93 | return (async () => { 94 | await getIndexedDb(); 95 | return clientService; 96 | })(); 97 | } 98 | } 99 | 100 | /** @description Indicates the private key is not found in indexedDB */ 101 | class IndexedDbKeyNotFoundError extends Error {} 102 | 103 | /** @description Indicates fail indexedDB operation */ 104 | class IndexedDbOperationError extends Error {} 105 | 106 | module.exports = { 107 | ClientServiceWithIndexedDb, 108 | IndexedDbKeyNotFoundError, 109 | IndexedDbOperationError, 110 | }; 111 | -------------------------------------------------------------------------------- /test/client_service_with_indexeddb.test.js: -------------------------------------------------------------------------------- 1 | const { 2 | ClientService, 3 | ClientServiceWithIndexedDb, 4 | IndexedDbKeyNotFoundError, 5 | } = require('../scalardl-web-client-sdk'); 6 | 7 | const chai = require('chai'); 8 | chai.use(require('chai-as-promised')); 9 | 10 | const Dexie = require('dexie').default; 11 | 12 | let generatedKeyPair; 13 | let db; 14 | 15 | describe('ClientServiceWithIndexedDb', function() { 16 | beforeEach(async function() { 17 | db = new Dexie('scalar'); 18 | db.version(1).stores({keystore: 'id'}); 19 | generatedKeyPair = await window.crypto.subtle.generateKey( 20 | {name: 'ECDSA', namedCurve: 'P-256'}, 21 | false, // cannot extractable 22 | ['sign', 'verify'], 23 | ); 24 | }); 25 | 26 | describe('#getIndexedDb()', function() { 27 | it('should work if key is stored', async function() { 28 | const privateKey = generatedKeyPair.privateKey; 29 | const certHolderId = `${new Date().getTime()}`; 30 | const certVersion = 1; 31 | const keyId = `${certHolderId}_${certVersion}`; 32 | db.keystore.put({id: keyId, key: privateKey}); 33 | 34 | const properties = { 35 | 'scalar.dl.client.server.host': '127.0.0.1', 36 | 'scalar.dl.client.server.port': 50051, 37 | 'scalar.dl.client.server.privileged_port': 50052, 38 | 'scalar.dl.client.cert_holder_id': certHolderId, 39 | 'scalar.dl.client.cert_version': certVersion, 40 | }; 41 | 42 | const clientService = await new ClientServiceWithIndexedDb( 43 | new ClientService(properties), 44 | ); 45 | const signature = await window.crypto.subtle.sign( 46 | {name: 'ECDSA', hash: 'SHA-256'}, 47 | clientService.properties['scalar.dl.client.private_key_cryptokey'], 48 | new ArrayBuffer([1, 2, 3]), 49 | ); 50 | const verified = await window.crypto.subtle.verify( 51 | {name: 'ECDSA', hash: 'SHA-256'}, 52 | generatedKeyPair.publicKey, 53 | signature, 54 | new ArrayBuffer([0, 1, 2, 3]), 55 | ); 56 | 57 | chai.assert.equal(true, verified); 58 | }); 59 | 60 | it('should work to store pem', async function() { 61 | const certHolderId = `${new Date().getTime()}`; 62 | const certVersion = 1; 63 | const properties = { 64 | 'scalar.dl.client.server.host': '127.0.0.1', 65 | 'scalar.dl.client.server.port': 50051, 66 | 'scalar.dl.client.server.privileged_port': 50052, 67 | 'scalar.dl.client.cert_holder_id': certHolderId, 68 | 'scalar.dl.client.cert_version': certVersion, 69 | 'scalar.dl.client.private_key_pem': 70 | '-----BEGIN EC PRIVATE KEY-----\n' + 71 | 'MHcCAQEEICcJGMEw3dyXUGFu/5a36HqY0ynZi9gLUfKgYWMYgr/IoAoGCCqGSM49\n' + 72 | 'AwEHoUQDQgAEBGuhqumyh7BVNqcNKAQQipDGooUpURve2dO66pQCgjtSfu7lJV20\n' + 73 | 'XYWdrgo0Y3eXEhvK0lsURO9N0nrPiQWT4A==\n' + 74 | '-----END EC PRIVATE KEY-----\n', 75 | 'scalar.dl.client.cert_pem': 76 | '-----BEGIN CERTIFICATE-----\n' + 77 | 'MIICizCCAjKgAwIBAgIUMEUDTdWsQpftFkqs6bCd6U++4nEwCgYIKoZIzj0EAwIw\n' + 78 | 'bzELMAkGA1UEBhMCSlAxDjAMBgNVBAgTBVRva3lvMQ4wDAYDVQQHEwVUb2t5bzEf\n' + 79 | 'MB0GA1UEChMWU2FtcGxlIEludGVybWVkaWF0ZSBDQTEfMB0GA1UEAxMWU2FtcGxl\n' + 80 | 'IEludGVybWVkaWF0ZSBDQTAeFw0xODA5MTAwODA3MDBaFw0yMTA5MDkwODA3MDBa\n' + 81 | 'MEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJ\n' + 82 | 'bnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNC\n' + 83 | 'AAQEa6Gq6bKHsFU2pw0oBBCKkMaihSlRG97Z07rqlAKCO1J+7uUlXbRdhZ2uCjRj\n' + 84 | 'd5cSG8rSWxRE703Ses+JBZPgo4HVMIHSMA4GA1UdDwEB/wQEAwIFoDATBgNVHSUE\n' + 85 | 'DDAKBggrBgEFBQcDAjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBRDd2MS9Ndo68PJ\n' + 86 | 'y9K/RNY6syZW0zAfBgNVHSMEGDAWgBR+Y+v8yByDNp39G7trYrTfZ0UjJzAxBggr\n' + 87 | 'BgEFBQcBAQQlMCMwIQYIKwYBBQUHMAGGFWh0dHA6Ly9sb2NhbGhvc3Q6ODg4OTAq\n' + 88 | 'BgNVHR8EIzAhMB+gHaAbhhlodHRwOi8vbG9jYWxob3N0Ojg4ODgvY3JsMAoGCCqG\n' + 89 | 'SM49BAMCA0cAMEQCIC/Bo4oNU6yHFLJeme5ApxoNdyu3rWyiqWPxJmJAr9L0AiBl\n' + 90 | 'Gc/v+yh4dHIDhCrimajTQAYOG9n0kajULI70Gg7TNw==\n' + 91 | '-----END CERTIFICATE-----\n', 92 | }; 93 | const keyId = `${certHolderId}_${certVersion}`; 94 | 95 | const before = await db.keystore.get(keyId); 96 | const clientService = await new ClientServiceWithIndexedDb( 97 | new ClientService(properties), 98 | ); 99 | const after = await db.keystore.get(keyId); 100 | 101 | chai.assert.equal(undefined, before); 102 | chai.assert.notEqual(undefined, after); 103 | await chai.expect(clientService.registerCertificate()).to.not.be.rejected; 104 | await chai.expect(clientService.validateLedger('foo', 0, 1)).to.not.be 105 | .rejected; 106 | await chai.expect(clientService.validateLedger('foo')).to.not.be.rejected; 107 | }); 108 | 109 | it('should work to store CryptoKey', async function() { 110 | const certHolderId = `${new Date().getTime()}`; 111 | const certVersion = 1; 112 | const key = generatedKeyPair.privateKey; 113 | const properties = { 114 | 'scalar.dl.client.server.host': '127.0.0.1', 115 | 'scalar.dl.client.server.port': 50051, 116 | 'scalar.dl.client.server.privileged_port': 50052, 117 | 'scalar.dl.client.cert_holder_id': certHolderId, 118 | 'scalar.dl.client.cert_version': certVersion, 119 | 'scalar.dl.client.private_key_cryptokey': key, 120 | }; 121 | const keyId = `${certHolderId}_${certVersion}`; 122 | 123 | const before = await db.keystore.get(keyId); 124 | await new ClientServiceWithIndexedDb(new ClientService(properties)); 125 | const after = await db.keystore.get(keyId); 126 | 127 | chai.assert.equal(undefined, before); 128 | chai.assert.notEqual(undefined, after); 129 | }); 130 | 131 | it('should be able to throw IndexedDbKeyNotFoundError', async function() { 132 | const certHolderId = `${new Date().getTime()}`; 133 | const certVersion = 1; 134 | const properties = { 135 | 'scalar.dl.client.server.host': '127.0.0.1', 136 | 'scalar.dl.client.server.port': 50051, 137 | 'scalar.dl.client.server.privileged_port': 50052, 138 | 'scalar.dl.client.cert_holder_id': certHolderId, 139 | 'scalar.dl.client.cert_version': certVersion, 140 | }; 141 | 142 | await chai 143 | .expect(new ClientServiceWithIndexedDb(new ClientService(properties))) 144 | .to.be.rejectedWith(IndexedDbKeyNotFoundError); 145 | }); 146 | }); 147 | 148 | describe('#deleteIndexedDb', function() { 149 | it('shoud work fine', async function() { 150 | const privateKey = generatedKeyPair.privateKey; 151 | const certHolderId = `${new Date().getTime()}`; 152 | const certVersion = 1; 153 | const keyId = `${certHolderId}_${certVersion}`; 154 | db.keystore.put({id: keyId, key: privateKey}); 155 | const properties = { 156 | 'scalar.dl.client.server.host': '127.0.0.1', 157 | 'scalar.dl.client.server.port': 50051, 158 | 'scalar.dl.client.server.privileged_port': 50052, 159 | 'scalar.dl.client.cert_holder_id': certHolderId, 160 | 'scalar.dl.client.cert_version': certVersion, 161 | }; 162 | 163 | const clientService = await new ClientServiceWithIndexedDb( 164 | new ClientService(properties), 165 | ); 166 | const before = await db.keystore.get(keyId); 167 | await clientService.deleteIndexedDb(); 168 | const after = await db.keystore.get(keyId); 169 | 170 | chai.assert.notEqual(undefined, before); 171 | chai.assert.equal(undefined, after); 172 | }); 173 | }); 174 | }); 175 | -------------------------------------------------------------------------------- /test/integration_auditor.test.js: -------------------------------------------------------------------------------- 1 | describe('ClientService', () => { 2 | const {ClientService} = require('../scalardl-web-client-sdk.js'); 3 | const validateLedgerContractId = `validate-ledger${Date.now()}`; 4 | const properties = { 5 | 'scalar.dl.client.server.host': '127.0.0.1', 6 | 'scalar.dl.client.server.port': 50051, 7 | 'scalar.dl.client.server.privileged_port': 50052, 8 | 9 | 'scalar.dl.client.auditor.enabled': true, 10 | 'scalar.dl.client.auditor.host': '127.0.0.1', 11 | 'scalar.dl.client.auditor.port': 40051, 12 | 'scalar.dl.client.auditor.privileged_port': 40052, 13 | 'scalar.dl.client.auditor.linearizable_validation.enabled': true, 14 | 'scalar.dl.client.auditor.linearizable_validation.contract_id': 15 | validateLedgerContractId, 16 | 17 | // Make the test idempotent. 18 | 'scalar.dl.client.cert_holder_id': `foo@${Date.now()}`, 19 | 20 | 'scalar.dl.client.private_key_pem': 21 | '-----BEGIN EC PRIVATE KEY-----\n' + 22 | 'MHcCAQEEICcJGMEw3dyXUGFu/5a36HqY0ynZi9gLUfKgYWMYgr/IoAoGCCqGSM49\n' + 23 | 'AwEHoUQDQgAEBGuhqumyh7BVNqcNKAQQipDGooUpURve2dO66pQCgjtSfu7lJV20\n' + 24 | 'XYWdrgo0Y3eXEhvK0lsURO9N0nrPiQWT4A==\n-----END EC PRIVATE KEY-----\n', 25 | 26 | 'scalar.dl.client.cert_pem': 27 | '-----BEGIN CERTIFICATE-----\n' + 28 | 'MIICizCCAjKgAwIBAgIUMEUDTdWsQpftFkqs6bCd6U++4nEwCgYIKoZIzj0EAwIw\n' + 29 | 'bzELMAkGA1UEBhMCSlAxDjAMBgNVBAgTBVRva3lvMQ4wDAYDVQQHEwVUb2t5bzEf\n' + 30 | 'MB0GA1UEChMWU2FtcGxlIEludGVybWVkaWF0ZSBDQTEfMB0GA1UEAxMWU2FtcGxl\n' + 31 | 'IEludGVybWVkaWF0ZSBDQTAeFw0xODA5MTAwODA3MDBaFw0yMTA5MDkwODA3MDBa\n' + 32 | 'MEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJ\n' + 33 | 'bnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNC\n' + 34 | 'AAQEa6Gq6bKHsFU2pw0oBBCKkMaihSlRG97Z07rqlAKCO1J+7uUlXbRdhZ2uCjRj\n' + 35 | 'd5cSG8rSWxRE703Ses+JBZPgo4HVMIHSMA4GA1UdDwEB/wQEAwIFoDATBgNVHSUE\n' + 36 | 'DDAKBggrBgEFBQcDAjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBRDd2MS9Ndo68PJ\n' + 37 | 'y9K/RNY6syZW0zAfBgNVHSMEGDAWgBR+Y+v8yByDNp39G7trYrTfZ0UjJzAxBggr\n' + 38 | 'BgEFBQcBAQQlMCMwIQYIKwYBBQUHMAGGFWh0dHA6Ly9sb2NhbGhvc3Q6ODg4OTAq\n' + 39 | 'BgNVHR8EIzAhMB+gHaAbhhlodHRwOi8vbG9jYWxob3N0Ojg4ODgvY3JsMAoGCCqG\n' + 40 | 'SM49BAMCA0cAMEQCIC/Bo4oNU6yHFLJeme5ApxoNdyu3rWyiqWPxJmJAr9L0AiBl\n' + 41 | 'Gc/v+yh4dHIDhCrimajTQAYOG9n0kajULI70Gg7TNw==\n' + 42 | '-----END CERTIFICATE-----\n', 43 | 44 | 'scalar.dl.client.cert_version': 1, 45 | 'scalar.dl.client.tls.enabled': false, 46 | 47 | 'scalar.dl.client.tls.ca_root_cert_pem': 48 | '-----BEGIN CERTIFICATE-----\n' + 49 | 'MIIE/jCCAuagAwIBAgIJAJO8tpVEEORLMA0GCSqGSIb3DQEBCwUAMBQxEjAQBgNV\n' + 50 | 'BAMMCWxvY2FsaG9zdDAeFw0xOTAzMTMxMDUyMTFaFw0yMDAzMTIxMDUyMTFaMBQx\n' + 51 | 'EjAQBgNVBAMMCWxvY2FsaG9zdDCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoC\n' + 52 | 'ggIBAKFeFSrXRh5jA+OodMPw0XFO4sd4G9wYERlxgCjDmd9eC+loLpjGwRwwO7os\n' + 53 | '/+rhW+Cg/NGhNn64xCmS/JtZf91SBD1QfQ4wk4094sAUIHsztaWtZTATl6aIy0BN\n' + 54 | '21A0ueFgVQGehwO1FdRKtS7X+45YV2vMMK/UQ69VSCwY82olBRgWp45TXLUmWVgC\n' + 55 | 'UAJkE/V2Ch8WLyKpCggtaxYmn8YfzA1X20QDK1b2IW4YPDcPapQLtU6wqIjrXX1E\n' + 56 | 'w992GgfERm//I14QEyu+qIPafsniDGYxiR6HK8nqeR70QcGHt+Qql24xyjwWHEA/\n' + 57 | '43pn3jjrNVRhiVAD8tkVyRmfWjIngksRHPwEh3jG34gshOi9xAaID+mx2AWhThsk\n' + 58 | 'XbuqSxHckPlvgWHugZmFOwKZAgU5/gpnWR7oHPOSYffhGwmc/+SK/SQ4UDeTFI2c\n' + 59 | '40Xw22P8CWbIq4gKi66kSvuFbLSeKQIRMJd50hf7kw3SqnkqEaeRXy5jBovut7CU\n' + 60 | 'nwcgGPceYmWhKxhkg5urzk+CQZENf+9+pVvArOQemn9bMuaBPwtwXE42+fktQpQ2\n' + 61 | 'PG3k7ryVL5R0jhuVNXf9ioU2z1ONQ2IdsuFtCKnozfVBAhy9bPfm120rTV/UBOCD\n' + 62 | 'zcmfRnv081lG9BN/KtZBo7hfFH/ZD2542yVRvibRIIdPWIkTAgMBAAGjUzBRMB0G\n' + 63 | 'A1UdDgQWBBQ61fQAtAgd7sM/NDtIX4D8GSA/8DAfBgNVHSMEGDAWgBQ61fQAtAgd\n' + 64 | '7sM/NDtIX4D8GSA/8DAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IC\n' + 65 | 'AQCaYh1bxlj9Impoq3rmFHl5/9Fb2o2H2Ne8VjTHb8eSoHuLwXdWzKnw6UhiCaN4\n' + 66 | 'EZgrsqq1L2Tc8Y+eqT4gz3uDLc5Cj29HHC/suZezIo3lgyZ/A6stYQXE5Gy8e+to\n' + 67 | 'Qhmf4u8RMZ8zt6i355un6mTJxJq7JxoVqpECf5tg6pMdOUzbcKLTmN6i50jH/PSO\n' + 68 | 'NQsJhiSJg3caNdWviob+UwEuUineMF/X08dB3gphZ7kmfDeRjmONALMXS1uvPwk2\n' + 69 | '3s8S45LmxETx+tcJSvckKRC9JaQf6dgHfKAWHpkIqvLKyqy9Dmvg2RSJi3kI9oaj\n' + 70 | 'dm64zc6CAsqVaPvoMfWIN7JZq9jvzc8msGiilfhiYoc+M3jvnmM81FuGbAw7Utq4\n' + 71 | 'uuHtpCcpbxRMChD4WdlrPeBONyBKp+RRWTGfBY1GW5aGWVp/cbcpIc2RSgnZcrxb\n' + 72 | '6ef2iTMtUjRd76JlkobTyvgo0GKdLgnr8c711I2YNp+TabKIKZOEvw2X+oGbfxBN\n' + 73 | '1WvRB5YJo2rzwZj0fSvN9IwT9TGxSZIo5zcaQuwLEmDZBJShgXN5Ya71Vag1AP2i\n' + 74 | 'mOwUJRvfTVPWg+wtF2JQwaPpK0+Kb7oCq9tl3PUW40FRgqWV1Tgp6Co/U1W/1BU6\n' + 75 | '02Vmic/M/HmRMwWuX1PyVOVr8Mjyj+OMF1JsmdR5eL5Mtg==\n' + 76 | '-----END CERTIFICATE-----\n', 77 | }; 78 | 79 | describe('Integration test on ClientService', async () => { 80 | const mockedContractId = `StateUpdater${Date.now()}`; 81 | const mockedContractName = 'com.org1.contract.StateUpdater'; 82 | const mockedAssetId = `mockedAssetId${Date.now()}`; 83 | const mockedState = 1; 84 | const mockedContractArgument = { 85 | asset_id: mockedAssetId, 86 | state: mockedState, 87 | }; 88 | const contractProperty = { 89 | properties: 'bar', 90 | }; 91 | const mockedByteContract = new Uint8Array( 92 | require('arraybuffer-loader!./StateUpdater.class'), 93 | ); 94 | const clientService = new ClientService(properties); 95 | describe('registerCertificate', () => { 96 | it('should be successful', async () => { 97 | try { 98 | const response = await clientService.registerCertificate(); 99 | assert.deepEqual(response, undefined); 100 | } catch (clientError) { 101 | console.log(clientError); 102 | assert.fail(); 103 | } 104 | }); 105 | }); 106 | describe('registerContract', () => { 107 | it('should be successful', async () => { 108 | try { 109 | const response = await clientService.registerContract( 110 | mockedContractId, 111 | mockedContractName, 112 | mockedByteContract, 113 | contractProperty, 114 | ); 115 | assert.deepEqual(response, undefined); 116 | } catch (clientError) { 117 | assert.fail(); 118 | } 119 | }); 120 | }); 121 | describe('executeContract', () => { 122 | it( 123 | 'should work as expected ' + 'when executing a registered contract', 124 | async () => { 125 | try { 126 | const response = await clientService.executeContract( 127 | mockedContractId, 128 | mockedContractArgument, 129 | {}, 130 | ); 131 | const contractResult = response.getResult(); 132 | assert.equal(contractResult.asset_id, mockedAssetId); 133 | assert.equal(contractResult.state, mockedState); 134 | assert.equal( 135 | contractResult.properties, 136 | contractProperty.properties, 137 | ); 138 | } catch (clientError) { 139 | assert.fail(); 140 | } 141 | }, 142 | ); 143 | }); 144 | describe('validateLedger linearizably', () => { 145 | it( 146 | 'should return successfully ' + 'and the proofs are the same', 147 | async () => { 148 | await clientService.registerContract( 149 | validateLedgerContractId, 150 | 'com.scalar.dl.client.contract.ValidateLedger', 151 | new Uint8Array( 152 | require('arraybuffer-loader!./ValidateLedger.class'), 153 | ), 154 | {}, 155 | ); 156 | 157 | const response = await clientService.validateLedger(mockedAssetId); 158 | assert.equal(response.getProof(), response.getAuditorProof()); 159 | }, 160 | ); 161 | }); 162 | }); 163 | }); 164 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | # Java Gradle CircleCI 2.0 configuration file 2 | # 3 | # Check https://circleci.com/docs/2.0/language-java/ for more details 4 | # 5 | version: 2.1 6 | jobs: 7 | e2e-without-auditor: 8 | machine: 9 | image: ubuntu-2004:current 10 | 11 | working_directory: ~/scalardl-web-client-sdk 12 | 13 | steps: 14 | - checkout 15 | # Restore dependencies 16 | - restore_cache: 17 | keys: 18 | - dependency-cache-{{ checksum "package-lock.json" }} 19 | 20 | - run: 21 | name: Docker login 22 | command: | 23 | echo ${GHCR_PAT} | docker login https://ghcr.io -u ${GHCR_USERNAME} --password-stdin 24 | 25 | - run: # Update chrome to stable version for karma 26 | name: Install Chromedriver latest version 27 | command: | 28 | wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - 29 | sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' 30 | sudo apt-get update 31 | sudo apt-get install -y google-chrome-stable 32 | 33 | - run: 34 | name: checkout scalardl-samples repository as it contains the script to spin up scalardl environment and easier for us to maintain the CI 35 | command: | 36 | git init 37 | git pull https://${GHCR_USERNAME}:${GHCR_PAT}@github.com/scalar-labs/scalardl-samples.git 3.3 38 | working_directory: .circleci/ 39 | 40 | - run: 41 | name: Spin container via docker compose 42 | command: docker-compose -f docker-compose.yml -f docker-compose-open-cassandra-port.yml up -d 43 | working_directory: .circleci/ 44 | 45 | - run: 46 | name: Install Node LTS # Update node for karma to work 47 | command: | 48 | export NVM_DIR="/opt/circleci/.nvm" 49 | [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" 50 | nvm install --lts 51 | nvm use --lts 52 | 53 | - run: 54 | name: Install npm 55 | command: npm install 56 | 57 | - run: 58 | name: Wait for Cassandra to spin up to be able to update the Cassandra schema in the next step 59 | command: | 60 | echo -n "Wait for C* " 61 | until docker exec scalardl-samples-cassandra-1 cqlsh 2> /dev/null ; do 62 | sleep 0.5 63 | echo -n "#" 64 | done 65 | 66 | - run: 67 | name: Insert function table and wait 68 | command: | 69 | docker cp function_schema.cql \ 70 | scalardl-samples-cassandra-1:function_schema.cql 71 | docker exec scalardl-samples-cassandra-1 cqlsh -f function_schema.cql 72 | sleep 10 73 | working_directory: .circleci/ 74 | 75 | - save_cache: 76 | key: v1-dependencies-{{ checksum "package-lock.json" }} 77 | paths: 78 | - ./node_modules 79 | 80 | # run tests 81 | - run: 82 | command: npm test 83 | 84 | - store_test_results: 85 | path: ~/scalardl-web-client-sdk/test/test-reports 86 | 87 | - store_artifacts: 88 | path: ~/scalardl-web-client-sdk/test/test-reports 89 | 90 | e2e-with-auditor: 91 | machine: 92 | image: ubuntu-2004:current 93 | 94 | working_directory: ~/scalardl-web-client-sdk 95 | 96 | steps: 97 | - checkout 98 | # Restore dependencies 99 | - restore_cache: 100 | keys: 101 | - dependency-cache-{{ checksum "package-lock.json" }} 102 | 103 | - run: 104 | name: Docker login 105 | command: | 106 | echo ${GHCR_PAT} | docker login https://ghcr.io -u ${GHCR_USERNAME} --password-stdin 107 | 108 | - run: # Update chrome to stable version for karma 109 | name: Install Chromedriver latest version 110 | command: | 111 | wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - 112 | sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' 113 | sudo apt-get update 114 | sudo apt-get install -y google-chrome-stable 115 | 116 | - run: 117 | name: Install Node LTS # Update node for karma to work 118 | command: | 119 | export NVM_DIR="/opt/circleci/.nvm" 120 | [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" 121 | nvm install --lts 122 | nvm use --lts 123 | 124 | - run: 125 | name: Install npm 126 | command: npm install 127 | 128 | - save_cache: 129 | key: v1-dependencies-{{ checksum "package-lock.json" }} 130 | paths: 131 | - ./node_modules 132 | 133 | - run: 134 | name: checkout scalardl-samples repository as it contains the script to spin up scalardl environment and easier for us to maintain the CI 135 | command: | 136 | git init 137 | git pull https://${GHCR_USERNAME}:${GHCR_PAT}@github.com/scalar-labs/scalardl-samples.git 3.3 138 | working_directory: .circleci/ 139 | 140 | - run: 141 | name: Start Scalar DL environment with auditor 142 | command: | 143 | docker-compose -f docker-compose.yml -f docker-compose-auditor.yml up -d cassandra 144 | echo -n "Wait for C* " 145 | until docker exec scalardl-samples-cassandra-1 cqlsh 2> /dev/null ; do 146 | sleep 0.5 147 | echo -n "#" 148 | done 149 | echo "" 150 | docker-compose -f docker-compose.yml -f docker-compose-auditor.yml up scalardl-ledger-schema-loader-cassandra 151 | docker-compose -f docker-compose.yml -f docker-compose-auditor.yml up scalardl-auditor-schema-loader-cassandra 152 | docker-compose -f docker-compose.yml -f docker-compose-auditor.yml up -d scalar-ledger 153 | docker-compose -f docker-compose.yml -f docker-compose-auditor.yml up -d scalar-auditor 154 | docker-compose -f docker-compose.yml -f docker-compose-auditor.yml up -d ledger-envoy 155 | docker-compose -f docker-compose.yml -f docker-compose-auditor.yml up -d auditor-envoy 156 | sleep 5 157 | docker restart scalardl-samples-scalar-ledger-1 # just in case 158 | docker restart scalardl-samples-scalar-auditor-1 # just in case 159 | docker restart scalardl-samples-auditor-envoy-1 # just in case 160 | docker restart scalardl-samples-ledger-envoy-1 # just in case 161 | sleep 5 162 | docker-compose -f docker-compose.yml -f docker-compose-auditor.yml up scalar-ledger-as-client 163 | docker-compose -f docker-compose.yml -f docker-compose-auditor.yml up scalar-audior-as-client 164 | working_directory: .circleci/ 165 | 166 | # run tests with auditor 167 | - run: 168 | command: npm run test-auditor 169 | 170 | - store_test_results: 171 | path: ~/scalardl-web-client-sdk/test/test-reports 172 | 173 | - store_artifacts: 174 | path: ~/scalardl-web-client-sdk/test/test-reports 175 | 176 | deploy: 177 | docker: 178 | #Node LTS 179 | - image: cimg/node:lts 180 | steps: 181 | - checkout 182 | - run: 183 | name: Authenticate with registry 184 | command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc 185 | - run: 186 | name: Publish package 187 | command: npm publish --access public 188 | 189 | workflows: 190 | version: 2 191 | build-deploy: 192 | jobs: 193 | - e2e-with-auditor: 194 | context: "scalar" 195 | filters: # required since `deploy` has tag filters AND requires `e2e-with-auditor` 196 | tags: 197 | only: /.*/ 198 | - e2e-without-auditor: 199 | context: "scalar" 200 | filters: # required since `deploy` has tag filters AND requires `e2e-without-auditor` 201 | tags: 202 | only: /.*/ 203 | - deploy: 204 | context: "scalar" 205 | requires: 206 | - e2e-without-auditor 207 | - e2e-with-auditor 208 | filters: 209 | tags: 210 | only: /v[0-9]+\.[0-9]+\.[0-9]+/ 211 | branches: 212 | ignore: /.*/ 213 | -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |

Register a certificate

10 |
11 |
12 |
13 | 18 | 19 |
20 | 21 | 22 | 23 |
24 |
25 | 26 |
27 |
28 | Key: 29 |
30 |
31 | Certificate: 32 |
33 |
34 | 37 | 38 |
39 |
40 | 41 |
42 |

Register a contract

43 |
44 |
45 | 46 | 47 |
48 |
49 | Contract: 50 | 51 |
52 |
53 | 56 | 57 |
58 |
59 | 60 |
61 |

List registered contracts

62 |
63 | 66 | 67 |
68 | 69 |
70 |

Execute a contract

71 |
72 |
73 | Contract ID: 74 | 75 |
76 |
77 | 80 | 81 |
82 |
83 | 84 |
85 |

Validate an asset in the ledger

86 |
87 |
88 | 89 |
90 |
91 | 92 | 93 |
94 |
95 | 96 | 97 | 274 | 275 | 276 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | > [!CAUTION] 2 | > 3 | > The `docs` folder has been moved to the centralized documentation repository, [docs-internal](https://github.com/scalar-labs/docs-internal). Please update this documentation in that repository instead. 4 | > 5 | > To view the ScalarDL documentation, visit [ScalarDL Documentation](https://scalardl.scalar-labs.com/docs/). 6 | 7 | ## Scalar DL Web Client SDK 8 | 9 | This is a library for web applications by which the applications can interact with a [Scalar DL](https://github.com/scalar-labs/scalardl) network. 10 | 11 | ## Node version used for development and testing 12 | This package has been developed and tested using Node LTS v14.16.0. named "fermium". 13 | This means we cannot guarantee the package nominal behaviour when using other Node versions. 14 | 15 | ## Install 16 | 17 | We can use package manager to install this library. For example, to install with NPM: 18 | 19 | **NPM** 20 | ``` 21 | npm install @scalar-labs/scalardl-web-client-sdk 22 | ``` 23 | 24 | You can also find a bundle `scalardl-web-client-sdk.bundle.js` which can be imported statically in @scalar-labs/scalardl-web-client-sdk/dist. 25 | 26 | ## HOWTO 27 | 28 | ### Create ClientService instance 29 | 30 | `ClientService` class is the main class of this package. 31 | It provides following functions to request Scalar DL network. 32 | 33 | |Name|Use| 34 | |----|---| 35 | |registerCertificate|To register a client's certificate to a Scalar DL network| 36 | |registerContract|To register the contracts to the registered client of the Scalar DL network| 37 | |listContracts|To list all registered contracts of the client| 38 | |executeContract|To execute a registered contract of the client| 39 | |validateLedger|To validate an asset of the Scalar DL network to determine if it is tampered| 40 | 41 | If an error occurs when executing one of the above methods, a `ClientError` will be thrown. The 42 | `ClientError.statusCode` provides additional context. Please refer to the [Runtime error](#runtime-error) section below for the status code specification. 43 | 44 | Use the code snippet below to create a ClientService instance. 45 | ```javascript 46 | import { ClientService } from '@scalar-labs/scalardl-web-client-sdk'; 47 | const clientService = new ClientService(clientProperties); 48 | ``` 49 | 50 | Or, if you use the static release, try following 51 | ```html 52 | 53 | 54 | 55 | 56 | 57 | 60 | ``` 61 | 62 | The `clientProperties` argument is mandatory for the constructor. 63 | This is a properties example that a user `foo@example.com` would use to try to connect to the server `scalardl.example.com:50051` of the Scalar DL network. 64 | ```javascript 65 | { 66 | 'scalar.dl.client.server.host': 'scalardl.example.com', 67 | 'scalar.dl.client.server.port': 50051, 68 | 'scalar.dl.client.server.privileged_port': 50052, 69 | 'scalar.dl.client.cert_holder_id': 'foo@example.com', 70 | 'scalar.dl.client.private_key_pem': "-----BEGIN EC PRIVATE KEY-----\nMHc...", 71 | 'scalar.dl.client.cert_pem': "-----BEGIN CERTIFICATE-----\nMIICjTCCAj...n", 72 | 'scalar.dl.client.cert_version': 1, 73 | 'scalar.dl.client.tls.enabled': false, 74 | } 75 | ``` 76 | 77 | If the auditor capability is enabled on the Scalar DL network, specify additional properties like the following example. In this example, the client interacts with the auditor `scalardl-auditor.example.com` and detects Byzantine faults including data tampering when executing contracts. 78 | 79 | ```javascript 80 | { 81 | 'scalar.dl.client.auditor.enabled': true, 82 | 'scalar.dl.client.auditor.host': 'scalardl-auditor.example.com', 83 | 'scalar.dl.client.auditor.port': 40051, 84 | 'scalar.dl.client.auditor.privileged_port': 40052, 85 | } 86 | ``` 87 | 88 | In what follows assume that we have a clientService instance. 89 | 90 | ### Register the certificate 91 | Use the `registerCertificate` function to register a certificate on the Scalar DL network. 92 | ```javascript 93 | await clientService.registerCertificate(); 94 | ``` 95 | Please refer to the [Status code](#status-code) section below for the details of status. 96 | 97 | ### Register contracts 98 | Use the `registerContract` function to register a contract. 99 | ```javascript 100 | await clientService.registerContract('contractId', 'com.example.contract.contractName', contractUint8Array, propertiesObject); 101 | ``` 102 | 103 | ### Register functions 104 | Use the `registerFunction` function to register a function. 105 | ```javascript 106 | await clientService.registerFunction('functionId, 'com.example.function.functionName', functionUint8Array); 107 | ``` 108 | 109 | ### List registered contracts 110 | Use `listContracts` function to list all registered contracts. 111 | ```javascript 112 | const constracts = await clientService.listContracts(); 113 | ``` 114 | 115 | ### Execute a contract 116 | Use `executeContract` function to execute a registered contract. It will also execute a function if `_functions_` is given in the argument. 117 | ```javascript 118 | const response = await clientService.executeContract('contractId', argumentObject); 119 | const executionResult = response.getResult(); 120 | const proofsList = response.getProofs(); 121 | ``` 122 | 123 | ```javascript 124 | const response = await clientService.executeContract('contractId', { 'arg1': 'a', '_functions_': [functionId] }, { 'arg2': 'b' }); 125 | ``` 126 | `{ 'arg1': 'a', ` will be passed via [contractArgument](https://github.com/scalarindetail/scalardl-node-client-sdk/blob/3e531b4c62fb14702a873b07f44cb37212f04be4/test/TestFunction.java#L14), while `{ 'arg2': 'b' }` will be passed via [functionArgument](https://github.com/scalarindetail/scalardl-node-client-sdk/blob/3e531b4c62fb14702a873b07f44cb37212f04be4/test/TestFunction.java#L15). 127 | 128 | 129 | ### Validate an asset 130 | Use the `validateLedger` function to validate an asset in the Scalar DL network. 131 | ```javascript 132 | const response = await clientService.validateLedger('assetId'); 133 | const status = response.getCode(); 134 | const proof = response.getProof(); 135 | ``` 136 | 137 | #### Validate an asset linearizably 138 | The default ledger validation in a Auditor-enabled Scalar DL network is non-linearizable; i.e., there might be cases where Ledger and Auditor look inconsistent temporarily. 139 | Scalar DL supports linearizable ledger validation. 140 | To use it, we can configure the properties as follows 141 | ```javascript 142 | { 143 | 'scalar.dl.client.auditor.enabled': true, 144 | ... 145 | 'scalar.dl.client.auditor.linearizable_validation.enabled': true, 146 | 'scalar.dl.client.auditor.linearizable_validation.contract_id': '', 147 | } 148 | ``` 149 | and, register the [ValidateLedger](https://github.com/scalar-labs/scalardl-java-client-sdk/blob/master/src/main/java/com/scalar/dl/client/contract/ValidateLedger.java) contract as the contract ID we specified in the properties. 150 | Then, the ClientService.validateLedger function can provide linearizable ledger validation. 151 | 152 | ### Runtime error 153 | Error thrown by the client present a status code. 154 | ```javascript 155 | try { 156 | await clientService.registerCertificate(); 157 | } catch (clientError) { 158 | const message = clientError.message; 159 | const statusCode = clientError.code; 160 | } 161 | ``` 162 | Enumeration `StatusCode` enumerates all the possible status. 163 | ``` 164 | StatusCode = { 165 | OK: 200, 166 | INVALID_HASH: 300, 167 | INVALID_PREV_HASH: 301, 168 | INVALID_CONTRACT: 302, 169 | INVALID_OUTPUT: 303, 170 | INVALID_NONCE: 304, 171 | INCONSISTENT_STATES: 305, 172 | INVALID_SIGNATURE: 400, 173 | UNLOADABLE_KEY: 401, 174 | UNLOADABLE_CONTRACT: 402, 175 | CERTIFICATE_NOT_FOUND: 403, 176 | CONTRACT_NOT_FOUND: 404, 177 | CERTIFICATE_ALREADY_REGISTERED: 405, 178 | CONTRACT_ALREADY_REGISTERED: 406, 179 | INVALID_REQUEST: 407, 180 | CONTRACT_CONTEXTUAL_ERROR: 408, 181 | ASSET_NOT_FOUND: 409, 182 | FUNCTION_NOT_FOUND: 410, 183 | UNLOADABLE_FUNCTION: 411, 184 | INVALID_FUNCTION: 412, 185 | DATABASE_ERROR: 500, 186 | UNKNOWN_TRANSACTION_STATUS: 501, 187 | RUNTIME_ERROR: 502, 188 | CLIENT_IO_ERROR: 600, 189 | CLIENT_DATABASE_ERROR: 601, 190 | CLIENT_RUNTIME_ERROR: 602, 191 | }; 192 | ``` 193 | 194 | ## IndexedDB support 195 | This library supports storing private keys in the browsers' [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API). 196 | To use the feature, please decorate `ClientService` object with `ClientServiceWithIndexedDb` as follows. 197 | 198 | ``` 199 | const clientService = await new ClientServiceWithIndexedDb(new ClientService(properties)); 200 | ``` 201 | 202 | `ClientServiceWithIndexedDb` stores a private key in IndexedDB if the key is specified in client properties and reads a private key from the IndexedDB if the key is not specified in client properties. 203 | 204 | Based on the behavior, it is recommended to use it as follows. 205 | If a private key is not found, `IndexedDbKeyNotFoundError` will be thrown and the application needs to get a private key from an external service. 206 | 207 | ```javascript 208 | let properties = { 209 | 'scalar.dl.client.cert_holder_id': 'foo@example.com', 210 | 'scalar.dl.client.cert_version': 1, 211 | ... 212 | }; // Not specify 'scalar.dl.client.private_key_pem' or 'scalar.dl.client.private_key_cryptokey' 213 | 214 | let clientService; 215 | try { 216 | // It tries to read a private key from IndexedDB 217 | clientService = await new ClientServiceWithIndexedDb(new ClientService(properties)); 218 | } catch (err) { 219 | if (err instanceof IndexedDbKeyNotFoundError) { 220 | properties['scalar.dl.client.private_key_pem'] = /* from some place */ 221 | // This time, it stores the specified private key in IndexedDB 222 | clientService = await new ClientServiceWithIndexedDb(new ClientService(properties)); 223 | } else { 224 | throw err; // How to handle the error should be decided by application side 225 | } 226 | } 227 | ``` 228 | 229 | ### deleteIndexedDb 230 | deleteIndexedDb removes a private key in IndexedDB according to `scalar.dl.client.cert_holder_id` and `scalar.dl.client.cert_version` in client properties. 231 | 232 | ```javascript 233 | clientService = await new ClientServiceWithIndexedDb(new ClientService(properties)); 234 | clientService.deleteIndexedDb(); // Remove stored key in indexedDb 235 | ``` 236 | 237 | ## Envoy configuration 238 | Scalar DLT server (grpc) uses a custom header called `rpc.status-bin` to share error metadata with the client. This means envoy needs to be 239 | configured to expose the header to clients. 240 | More specifically, `rpc.status-bin` needs to be added to the `expose-headers` field of the [cors configuration](https://www.envoyproxy.io/docs/envoy/latest/api-v2/api/v2/route/route_components.proto#envoy-api-msg-route-corspolicy). 241 | 242 | ## Contributing 243 | This library is mainly maintained by the Scalar Engineering Team, but of course we appreciate any help. 244 | 245 | * For asking questions, finding answers and helping other users, please go to [stackoverflow](https://stackoverflow.com/) and use [scalardl](https://stackoverflow.com/questions/tagged/scalardl) tag. 246 | * For filing bugs, suggesting improvements, or requesting new features, help us out by opening an issue. 247 | 248 | ## License 249 | Scalar DL client SDK is dual-licensed under both the AGPL (found in the LICENSE file in the root directory) and a commercial license. You may select, at your option, one of the above-listed licenses. Regarding the commercial license, please [contact us](https://scalar-labs.com/contact_us/) for more information. 250 | -------------------------------------------------------------------------------- /test/integration.test.js: -------------------------------------------------------------------------------- 1 | describe('ClientService', () => { 2 | const { 3 | ClientService, 4 | ClientServiceWithIndexedDb, 5 | StatusCode, 6 | } = require('../scalardl-web-client-sdk.js'); 7 | const properties = { 8 | 'scalar.dl.client.server.host': '127.0.0.1', 9 | 'scalar.dl.client.server.port': 50051, 10 | 'scalar.dl.client.server.privileged_port': 50052, 11 | 12 | // Make the test idempotent. 13 | 'scalar.dl.client.cert_holder_id': `foo@${Date.now()}`, 14 | 15 | 'scalar.dl.client.private_key_pem': 16 | '-----BEGIN EC PRIVATE KEY-----\n' + 17 | 'MHcCAQEEICcJGMEw3dyXUGFu/5a36HqY0ynZi9gLUfKgYWMYgr/IoAoGCCqGSM49\n' + 18 | 'AwEHoUQDQgAEBGuhqumyh7BVNqcNKAQQipDGooUpURve2dO66pQCgjtSfu7lJV20\n' + 19 | 'XYWdrgo0Y3eXEhvK0lsURO9N0nrPiQWT4A==\n-----END EC PRIVATE KEY-----\n', 20 | 21 | 'scalar.dl.client.cert_pem': 22 | '-----BEGIN CERTIFICATE-----\n' + 23 | 'MIICizCCAjKgAwIBAgIUMEUDTdWsQpftFkqs6bCd6U++4nEwCgYIKoZIzj0EAwIw\n' + 24 | 'bzELMAkGA1UEBhMCSlAxDjAMBgNVBAgTBVRva3lvMQ4wDAYDVQQHEwVUb2t5bzEf\n' + 25 | 'MB0GA1UEChMWU2FtcGxlIEludGVybWVkaWF0ZSBDQTEfMB0GA1UEAxMWU2FtcGxl\n' + 26 | 'IEludGVybWVkaWF0ZSBDQTAeFw0xODA5MTAwODA3MDBaFw0yMTA5MDkwODA3MDBa\n' + 27 | 'MEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJ\n' + 28 | 'bnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNC\n' + 29 | 'AAQEa6Gq6bKHsFU2pw0oBBCKkMaihSlRG97Z07rqlAKCO1J+7uUlXbRdhZ2uCjRj\n' + 30 | 'd5cSG8rSWxRE703Ses+JBZPgo4HVMIHSMA4GA1UdDwEB/wQEAwIFoDATBgNVHSUE\n' + 31 | 'DDAKBggrBgEFBQcDAjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBRDd2MS9Ndo68PJ\n' + 32 | 'y9K/RNY6syZW0zAfBgNVHSMEGDAWgBR+Y+v8yByDNp39G7trYrTfZ0UjJzAxBggr\n' + 33 | 'BgEFBQcBAQQlMCMwIQYIKwYBBQUHMAGGFWh0dHA6Ly9sb2NhbGhvc3Q6ODg4OTAq\n' + 34 | 'BgNVHR8EIzAhMB+gHaAbhhlodHRwOi8vbG9jYWxob3N0Ojg4ODgvY3JsMAoGCCqG\n' + 35 | 'SM49BAMCA0cAMEQCIC/Bo4oNU6yHFLJeme5ApxoNdyu3rWyiqWPxJmJAr9L0AiBl\n' + 36 | 'Gc/v+yh4dHIDhCrimajTQAYOG9n0kajULI70Gg7TNw==\n' + 37 | '-----END CERTIFICATE-----\n', 38 | 39 | 'scalar.dl.client.cert_version': 1, 40 | 'scalar.dl.client.tls.enabled': false, 41 | 42 | 'scalar.dl.client.tls.ca_root_cert_pem': 43 | '-----BEGIN CERTIFICATE-----\n' + 44 | 'MIIE/jCCAuagAwIBAgIJAJO8tpVEEORLMA0GCSqGSIb3DQEBCwUAMBQxEjAQBgNV\n' + 45 | 'BAMMCWxvY2FsaG9zdDAeFw0xOTAzMTMxMDUyMTFaFw0yMDAzMTIxMDUyMTFaMBQx\n' + 46 | 'EjAQBgNVBAMMCWxvY2FsaG9zdDCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoC\n' + 47 | 'ggIBAKFeFSrXRh5jA+OodMPw0XFO4sd4G9wYERlxgCjDmd9eC+loLpjGwRwwO7os\n' + 48 | '/+rhW+Cg/NGhNn64xCmS/JtZf91SBD1QfQ4wk4094sAUIHsztaWtZTATl6aIy0BN\n' + 49 | '21A0ueFgVQGehwO1FdRKtS7X+45YV2vMMK/UQ69VSCwY82olBRgWp45TXLUmWVgC\n' + 50 | 'UAJkE/V2Ch8WLyKpCggtaxYmn8YfzA1X20QDK1b2IW4YPDcPapQLtU6wqIjrXX1E\n' + 51 | 'w992GgfERm//I14QEyu+qIPafsniDGYxiR6HK8nqeR70QcGHt+Qql24xyjwWHEA/\n' + 52 | '43pn3jjrNVRhiVAD8tkVyRmfWjIngksRHPwEh3jG34gshOi9xAaID+mx2AWhThsk\n' + 53 | 'XbuqSxHckPlvgWHugZmFOwKZAgU5/gpnWR7oHPOSYffhGwmc/+SK/SQ4UDeTFI2c\n' + 54 | '40Xw22P8CWbIq4gKi66kSvuFbLSeKQIRMJd50hf7kw3SqnkqEaeRXy5jBovut7CU\n' + 55 | 'nwcgGPceYmWhKxhkg5urzk+CQZENf+9+pVvArOQemn9bMuaBPwtwXE42+fktQpQ2\n' + 56 | 'PG3k7ryVL5R0jhuVNXf9ioU2z1ONQ2IdsuFtCKnozfVBAhy9bPfm120rTV/UBOCD\n' + 57 | 'zcmfRnv081lG9BN/KtZBo7hfFH/ZD2542yVRvibRIIdPWIkTAgMBAAGjUzBRMB0G\n' + 58 | 'A1UdDgQWBBQ61fQAtAgd7sM/NDtIX4D8GSA/8DAfBgNVHSMEGDAWgBQ61fQAtAgd\n' + 59 | '7sM/NDtIX4D8GSA/8DAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IC\n' + 60 | 'AQCaYh1bxlj9Impoq3rmFHl5/9Fb2o2H2Ne8VjTHb8eSoHuLwXdWzKnw6UhiCaN4\n' + 61 | 'EZgrsqq1L2Tc8Y+eqT4gz3uDLc5Cj29HHC/suZezIo3lgyZ/A6stYQXE5Gy8e+to\n' + 62 | 'Qhmf4u8RMZ8zt6i355un6mTJxJq7JxoVqpECf5tg6pMdOUzbcKLTmN6i50jH/PSO\n' + 63 | 'NQsJhiSJg3caNdWviob+UwEuUineMF/X08dB3gphZ7kmfDeRjmONALMXS1uvPwk2\n' + 64 | '3s8S45LmxETx+tcJSvckKRC9JaQf6dgHfKAWHpkIqvLKyqy9Dmvg2RSJi3kI9oaj\n' + 65 | 'dm64zc6CAsqVaPvoMfWIN7JZq9jvzc8msGiilfhiYoc+M3jvnmM81FuGbAw7Utq4\n' + 66 | 'uuHtpCcpbxRMChD4WdlrPeBONyBKp+RRWTGfBY1GW5aGWVp/cbcpIc2RSgnZcrxb\n' + 67 | '6ef2iTMtUjRd76JlkobTyvgo0GKdLgnr8c711I2YNp+TabKIKZOEvw2X+oGbfxBN\n' + 68 | '1WvRB5YJo2rzwZj0fSvN9IwT9TGxSZIo5zcaQuwLEmDZBJShgXN5Ya71Vag1AP2i\n' + 69 | 'mOwUJRvfTVPWg+wtF2JQwaPpK0+Kb7oCq9tl3PUW40FRgqWV1Tgp6Co/U1W/1BU6\n' + 70 | '02Vmic/M/HmRMwWuX1PyVOVr8Mjyj+OMF1JsmdR5eL5Mtg==\n' + 71 | '-----END CERTIFICATE-----\n', 72 | }; 73 | 74 | describe('Integration test on ClientService', async () => { 75 | const mockedFunctionId = 'TestFunction'; 76 | const mockedContractId = `StateUpdater${Date.now()}`; 77 | const mockedContractName = 'com.org1.contract.StateUpdater'; 78 | const mockedFunctionName = 'com.org1.function.TestFunction'; 79 | const mockedAssetId = `mockedAssetId${Date.now()}`; 80 | const mockedState = 1; 81 | const mockedContractArgument = { 82 | asset_id: mockedAssetId, 83 | state: mockedState, 84 | }; 85 | const contractProperty = { 86 | properties: 'bar', 87 | }; 88 | const mockedByteContract = new Uint8Array( 89 | require('arraybuffer-loader!./StateUpdater.class'), 90 | ); 91 | const mockedByteFunction = new Uint8Array( 92 | require('arraybuffer-loader!./TestFunction.class'), 93 | ); 94 | const clientService = new ClientService(properties); 95 | describe('registerCertificate', () => { 96 | it('should be successful', async () => { 97 | const response = await clientService.registerCertificate(); 98 | assert.deepEqual(response); 99 | assert.deepEqual(response, undefined); 100 | }); 101 | }); 102 | describe('registerFunction', () => { 103 | it('should return 200 when correct inputs are specified', async () => { 104 | const response = await clientService.registerFunction( 105 | mockedFunctionId, 106 | mockedFunctionName, 107 | mockedByteFunction, 108 | ); 109 | assert.deepEqual(response, undefined); 110 | }); 111 | }); 112 | describe('registerContract', () => { 113 | it('should be successful', async () => { 114 | const response = await clientService.registerContract( 115 | mockedContractId, 116 | mockedContractName, 117 | mockedByteContract, 118 | contractProperty, 119 | ); 120 | assert.deepEqual(response, undefined); 121 | }); 122 | }); 123 | describe('listContracts', () => { 124 | it( 125 | 'should return contract metadata ' + 126 | 'when the correct contract id is specified', 127 | async () => { 128 | const response = await clientService.listContracts(); 129 | assert.ok(response.hasOwnProperty(mockedContractId)); 130 | }, 131 | ); 132 | }); 133 | describe('executeContract', () => { 134 | it( 135 | 'should work as expected ' + 'when executing a registered contract', 136 | async () => { 137 | const response = await clientService.executeContract( 138 | mockedContractId, 139 | mockedContractArgument, 140 | {}, 141 | ); 142 | const contractResult = response.getResult(); 143 | assert.equal(contractResult.asset_id, mockedAssetId); 144 | assert.equal(contractResult.state, mockedState); 145 | assert.equal( 146 | contractResult.properties, 147 | contractProperty.properties, 148 | ); 149 | }, 150 | ); 151 | it( 152 | 'should work as expected ' + 153 | 'when executing a registered contract and function', 154 | async () => { 155 | const functionArgument = { 156 | asset_id: mockedAssetId, 157 | state: mockedState, 158 | }; 159 | const contractArgumentWithFunction = { 160 | asset_id: mockedAssetId, 161 | state: Date.now(), 162 | _functions_: [mockedFunctionId], 163 | }; 164 | const response = await clientService.executeContract( 165 | mockedContractId, 166 | contractArgumentWithFunction, 167 | functionArgument, 168 | ); 169 | assert.equal( 170 | response.getResult().state, 171 | contractArgumentWithFunction.state, 172 | ); 173 | }, 174 | ); 175 | }); 176 | describe('validateLedger', () => { 177 | it( 178 | 'should return 200 ' + 'when correct asset id and age are specified', 179 | async () => { 180 | const response = await clientService.validateLedger( 181 | mockedAssetId, 182 | 0, 183 | 1, 184 | ); 185 | assert.equal(response.getCode(), 200); 186 | }, 187 | ); 188 | it( 189 | 'should return 200 ' + 'even only correct asset id is specified', 190 | async () => { 191 | const response = await clientService.validateLedger(mockedAssetId); 192 | assert.equal(response.getCode(), 200); 193 | }, 194 | ); 195 | it('should return 409 when incorrect asset id is specified', async () => { 196 | const response = await clientService.validateLedger( 197 | 'incorrect_asset_id', 198 | ); 199 | assert.equal(response.getCode(), 409); 200 | }); 201 | }); 202 | }); 203 | 204 | describe('Integration test with ClientServiceWithIndexedDb', function() { 205 | it('should be able to use prestored private key', async function() { 206 | const Dexie = require('dexie').default; 207 | const db = new Dexie('scalar'); 208 | db.version(1).stores({keystore: 'id'}); 209 | 210 | const holderId = `foo${Date.now()}`; 211 | const certVersion = 1; 212 | const keyId = `${holderId}_${certVersion}`; 213 | const {toCryptoKeyFromJwk, toJwkFromPkcs1} = require('../lib/keyutil'); 214 | const pem = 215 | '-----BEGIN EC PRIVATE KEY-----\n' + 216 | 'MHcCAQEEICcJGMEw3dyXUGFu/5a36HqY0ynZi9gLUfKgYWMYgr/IoAoGCCqGSM49\n' + 217 | 'AwEHoUQDQgAEBGuhqumyh7BVNqcNKAQQipDGooUpURve2dO66pQCgjtSfu7lJV20\n' + 218 | 'XYWdrgo0Y3eXEhvK0lsURO9N0nrPiQWT4A==\n' + 219 | '-----END EC PRIVATE KEY-----\n'; 220 | const key = await toCryptoKeyFromJwk(toJwkFromPkcs1(pem)); 221 | await db.keystore.put({id: keyId, key: key}); 222 | const properties = { 223 | 'scalar.dl.client.server.host': '127.0.0.1', 224 | 'scalar.dl.client.server.port': 50051, 225 | 'scalar.dl.client.server.privileged_port': 50052, 226 | 'scalar.dl.client.cert_holder_id': holderId, 227 | 'scalar.dl.client.cert_version': certVersion, 228 | 'scalar.dl.client.cert_pem': 229 | '-----BEGIN CERTIFICATE-----\n' + 230 | 'MIICizCCAjKgAwIBAgIUMEUDTdWsQpftFkqs6bCd6U++4nEwCgYIKoZIzj0EAwIw\n' + 231 | 'bzELMAkGA1UEBhMCSlAxDjAMBgNVBAgTBVRva3lvMQ4wDAYDVQQHEwVUb2t5bzEf\n' + 232 | 'MB0GA1UEChMWU2FtcGxlIEludGVybWVkaWF0ZSBDQTEfMB0GA1UEAxMWU2FtcGxl\n' + 233 | 'IEludGVybWVkaWF0ZSBDQTAeFw0xODA5MTAwODA3MDBaFw0yMTA5MDkwODA3MDBa\n' + 234 | 'MEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJ\n' + 235 | 'bnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNC\n' + 236 | 'AAQEa6Gq6bKHsFU2pw0oBBCKkMaihSlRG97Z07rqlAKCO1J+7uUlXbRdhZ2uCjRj\n' + 237 | 'd5cSG8rSWxRE703Ses+JBZPgo4HVMIHSMA4GA1UdDwEB/wQEAwIFoDATBgNVHSUE\n' + 238 | 'DDAKBggrBgEFBQcDAjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBRDd2MS9Ndo68PJ\n' + 239 | 'y9K/RNY6syZW0zAfBgNVHSMEGDAWgBR+Y+v8yByDNp39G7trYrTfZ0UjJzAxBggr\n' + 240 | 'BgEFBQcBAQQlMCMwIQYIKwYBBQUHMAGGFWh0dHA6Ly9sb2NhbGhvc3Q6ODg4OTAq\n' + 241 | 'BgNVHR8EIzAhMB+gHaAbhhlodHRwOi8vbG9jYWxob3N0Ojg4ODgvY3JsMAoGCCqG\n' + 242 | 'SM49BAMCA0cAMEQCIC/Bo4oNU6yHFLJeme5ApxoNdyu3rWyiqWPxJmJAr9L0AiBl\n' + 243 | 'Gc/v+yh4dHIDhCrimajTQAYOG9n0kajULI70Gg7TNw==\n' + 244 | '-----END CERTIFICATE-----\n', 245 | }; 246 | 247 | const clientService = await new ClientServiceWithIndexedDb( 248 | new ClientService(properties), 249 | ); 250 | await clientService.registerCertificate(); 251 | const response = await clientService.validateLedger( 252 | 'non_existing_asset', 253 | 0, 254 | 1, 255 | ); 256 | 257 | assert.equal(StatusCode.ASSET_NOT_FOUND, response.getCode()); 258 | }); 259 | }); 260 | }); 261 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This software is dual-licensed under both the AGPL and a commercial license. 2 | You can be released from the requirements of the following AGPL license by 3 | purchasing a commercial license. For more information, please contact Scalar, Inc. 4 | 5 | 6 | GNU AFFERO GENERAL PUBLIC LICENSE 7 | Version 3, 19 November 2007 8 | 9 | Copyright (C) 2007 Free Software Foundation, Inc. 10 | Everyone is permitted to copy and distribute verbatim copies 11 | of this license document, but changing it is not allowed. 12 | 13 | Preamble 14 | 15 | The GNU Affero General Public License is a free, copyleft license for 16 | software and other kinds of works, specifically designed to ensure 17 | cooperation with the community in the case of network server software. 18 | 19 | The licenses for most software and other practical works are designed 20 | to take away your freedom to share and change the works. By contrast, 21 | our General Public Licenses are intended to guarantee your freedom to 22 | share and change all versions of a program--to make sure it remains free 23 | software for all its users. 24 | 25 | When we speak of free software, we are referring to freedom, not 26 | price. Our General Public Licenses are designed to make sure that you 27 | have the freedom to distribute copies of free software (and charge for 28 | them if you wish), that you receive source code or can get it if you 29 | want it, that you can change the software or use pieces of it in new 30 | free programs, and that you know you can do these things. 31 | 32 | Developers that use our General Public Licenses protect your rights 33 | with two steps: (1) assert copyright on the software, and (2) offer 34 | you this License which gives you legal permission to copy, distribute 35 | and/or modify the software. 36 | 37 | A secondary benefit of defending all users' freedom is that 38 | improvements made in alternate versions of the program, if they 39 | receive widespread use, become available for other developers to 40 | incorporate. Many developers of free software are heartened and 41 | encouraged by the resulting cooperation. However, in the case of 42 | software used on network servers, this result may fail to come about. 43 | The GNU General Public License permits making a modified version and 44 | letting the public access it on a server without ever releasing its 45 | source code to the public. 46 | 47 | The GNU Affero General Public License is designed specifically to 48 | ensure that, in such cases, the modified source code becomes available 49 | to the community. It requires the operator of a network server to 50 | provide the source code of the modified version running there to the 51 | users of that server. Therefore, public use of a modified version, on 52 | a publicly accessible server, gives the public access to the source 53 | code of the modified version. 54 | 55 | An older license, called the Affero General Public License and 56 | published by Affero, was designed to accomplish similar goals. This is 57 | a different license, not a version of the Affero GPL, but Affero has 58 | released a new version of the Affero GPL which permits relicensing under 59 | this license. 60 | 61 | The precise terms and conditions for copying, distribution and 62 | modification follow. 63 | 64 | TERMS AND CONDITIONS 65 | 66 | 0. Definitions. 67 | 68 | "This License" refers to version 3 of the GNU Affero General Public License. 69 | 70 | "Copyright" also means copyright-like laws that apply to other kinds of 71 | works, such as semiconductor masks. 72 | 73 | "The Program" refers to any copyrightable work licensed under this 74 | License. Each licensee is addressed as "you". "Licensees" and 75 | "recipients" may be individuals or organizations. 76 | 77 | To "modify" a work means to copy from or adapt all or part of the work 78 | in a fashion requiring copyright permission, other than the making of an 79 | exact copy. The resulting work is called a "modified version" of the 80 | earlier work or a work "based on" the earlier work. 81 | 82 | A "covered work" means either the unmodified Program or a work based 83 | on the Program. 84 | 85 | To "propagate" a work means to do anything with it that, without 86 | permission, would make you directly or secondarily liable for 87 | infringement under applicable copyright law, except executing it on a 88 | computer or modifying a private copy. Propagation includes copying, 89 | distribution (with or without modification), making available to the 90 | public, and in some countries other activities as well. 91 | 92 | To "convey" a work means any kind of propagation that enables other 93 | parties to make or receive copies. Mere interaction with a user through 94 | a computer network, with no transfer of a copy, is not conveying. 95 | 96 | An interactive user interface displays "Appropriate Legal Notices" 97 | to the extent that it includes a convenient and prominently visible 98 | feature that (1) displays an appropriate copyright notice, and (2) 99 | tells the user that there is no warranty for the work (except to the 100 | extent that warranties are provided), that licensees may convey the 101 | work under this License, and how to view a copy of this License. If 102 | the interface presents a list of user commands or options, such as a 103 | menu, a prominent item in the list meets this criterion. 104 | 105 | 1. Source Code. 106 | 107 | The "source code" for a work means the preferred form of the work 108 | for making modifications to it. "Object code" means any non-source 109 | form of a work. 110 | 111 | A "Standard Interface" means an interface that either is an official 112 | standard defined by a recognized standards body, or, in the case of 113 | interfaces specified for a particular programming language, one that 114 | is widely used among developers working in that language. 115 | 116 | The "System Libraries" of an executable work include anything, other 117 | than the work as a whole, that (a) is included in the normal form of 118 | packaging a Major Component, but which is not part of that Major 119 | Component, and (b) serves only to enable use of the work with that 120 | Major Component, or to implement a Standard Interface for which an 121 | implementation is available to the public in source code form. A 122 | "Major Component", in this context, means a major essential component 123 | (kernel, window system, and so on) of the specific operating system 124 | (if any) on which the executable work runs, or a compiler used to 125 | produce the work, or an object code interpreter used to run it. 126 | 127 | The "Corresponding Source" for a work in object code form means all 128 | the source code needed to generate, install, and (for an executable 129 | work) run the object code and to modify the work, including scripts to 130 | control those activities. However, it does not include the work's 131 | System Libraries, or general-purpose tools or generally available free 132 | programs which are used unmodified in performing those activities but 133 | which are not part of the work. For example, Corresponding Source 134 | includes interface definition files associated with source files for 135 | the work, and the source code for shared libraries and dynamically 136 | linked subprograms that the work is specifically designed to require, 137 | such as by intimate data communication or control flow between those 138 | subprograms and other parts of the work. 139 | 140 | The Corresponding Source need not include anything that users 141 | can regenerate automatically from other parts of the Corresponding 142 | Source. 143 | 144 | The Corresponding Source for a work in source code form is that 145 | same work. 146 | 147 | 2. Basic Permissions. 148 | 149 | All rights granted under this License are granted for the term of 150 | copyright on the Program, and are irrevocable provided the stated 151 | conditions are met. This License explicitly affirms your unlimited 152 | permission to run the unmodified Program. The output from running a 153 | covered work is covered by this License only if the output, given its 154 | content, constitutes a covered work. This License acknowledges your 155 | rights of fair use or other equivalent, as provided by copyright law. 156 | 157 | You may make, run and propagate covered works that you do not 158 | convey, without conditions so long as your license otherwise remains 159 | in force. You may convey covered works to others for the sole purpose 160 | of having them make modifications exclusively for you, or provide you 161 | with facilities for running those works, provided that you comply with 162 | the terms of this License in conveying all material for which you do 163 | not control copyright. Those thus making or running the covered works 164 | for you must do so exclusively on your behalf, under your direction 165 | and control, on terms that prohibit them from making any copies of 166 | your copyrighted material outside their relationship with you. 167 | 168 | Conveying under any other circumstances is permitted solely under 169 | the conditions stated below. Sublicensing is not allowed; section 10 170 | makes it unnecessary. 171 | 172 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 173 | 174 | No covered work shall be deemed part of an effective technological 175 | measure under any applicable law fulfilling obligations under article 176 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 177 | similar laws prohibiting or restricting circumvention of such 178 | measures. 179 | 180 | When you convey a covered work, you waive any legal power to forbid 181 | circumvention of technological measures to the extent such circumvention 182 | is effected by exercising rights under this License with respect to 183 | the covered work, and you disclaim any intention to limit operation or 184 | modification of the work as a means of enforcing, against the work's 185 | users, your or third parties' legal rights to forbid circumvention of 186 | technological measures. 187 | 188 | 4. Conveying Verbatim Copies. 189 | 190 | You may convey verbatim copies of the Program's source code as you 191 | receive it, in any medium, provided that you conspicuously and 192 | appropriately publish on each copy an appropriate copyright notice; 193 | keep intact all notices stating that this License and any 194 | non-permissive terms added in accord with section 7 apply to the code; 195 | keep intact all notices of the absence of any warranty; and give all 196 | recipients a copy of this License along with the Program. 197 | 198 | You may charge any price or no price for each copy that you convey, 199 | and you may offer support or warranty protection for a fee. 200 | 201 | 5. Conveying Modified Source Versions. 202 | 203 | You may convey a work based on the Program, or the modifications to 204 | produce it from the Program, in the form of source code under the 205 | terms of section 4, provided that you also meet all of these conditions: 206 | 207 | a) The work must carry prominent notices stating that you modified 208 | it, and giving a relevant date. 209 | 210 | b) The work must carry prominent notices stating that it is 211 | released under this License and any conditions added under section 212 | 7. This requirement modifies the requirement in section 4 to 213 | "keep intact all notices". 214 | 215 | c) You must license the entire work, as a whole, under this 216 | License to anyone who comes into possession of a copy. This 217 | License will therefore apply, along with any applicable section 7 218 | additional terms, to the whole of the work, and all its parts, 219 | regardless of how they are packaged. This License gives no 220 | permission to license the work in any other way, but it does not 221 | invalidate such permission if you have separately received it. 222 | 223 | d) If the work has interactive user interfaces, each must display 224 | Appropriate Legal Notices; however, if the Program has interactive 225 | interfaces that do not display Appropriate Legal Notices, your 226 | work need not make them do so. 227 | 228 | A compilation of a covered work with other separate and independent 229 | works, which are not by their nature extensions of the covered work, 230 | and which are not combined with it such as to form a larger program, 231 | in or on a volume of a storage or distribution medium, is called an 232 | "aggregate" if the compilation and its resulting copyright are not 233 | used to limit the access or legal rights of the compilation's users 234 | beyond what the individual works permit. Inclusion of a covered work 235 | in an aggregate does not cause this License to apply to the other 236 | parts of the aggregate. 237 | 238 | 6. Conveying Non-Source Forms. 239 | 240 | You may convey a covered work in object code form under the terms 241 | of sections 4 and 5, provided that you also convey the 242 | machine-readable Corresponding Source under the terms of this License, 243 | in one of these ways: 244 | 245 | a) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by the 247 | Corresponding Source fixed on a durable physical medium 248 | customarily used for software interchange. 249 | 250 | b) Convey the object code in, or embodied in, a physical product 251 | (including a physical distribution medium), accompanied by a 252 | written offer, valid for at least three years and valid for as 253 | long as you offer spare parts or customer support for that product 254 | model, to give anyone who possesses the object code either (1) a 255 | copy of the Corresponding Source for all the software in the 256 | product that is covered by this License, on a durable physical 257 | medium customarily used for software interchange, for a price no 258 | more than your reasonable cost of physically performing this 259 | conveying of source, or (2) access to copy the 260 | Corresponding Source from a network server at no charge. 261 | 262 | c) Convey individual copies of the object code with a copy of the 263 | written offer to provide the Corresponding Source. This 264 | alternative is allowed only occasionally and noncommercially, and 265 | only if you received the object code with such an offer, in accord 266 | with subsection 6b. 267 | 268 | d) Convey the object code by offering access from a designated 269 | place (gratis or for a charge), and offer equivalent access to the 270 | Corresponding Source in the same way through the same place at no 271 | further charge. You need not require recipients to copy the 272 | Corresponding Source along with the object code. If the place to 273 | copy the object code is a network server, the Corresponding Source 274 | may be on a different server (operated by you or a third party) 275 | that supports equivalent copying facilities, provided you maintain 276 | clear directions next to the object code saying where to find the 277 | Corresponding Source. Regardless of what server hosts the 278 | Corresponding Source, you remain obligated to ensure that it is 279 | available for as long as needed to satisfy these requirements. 280 | 281 | e) Convey the object code using peer-to-peer transmission, provided 282 | you inform other peers where the object code and Corresponding 283 | Source of the work are being offered to the general public at no 284 | charge under subsection 6d. 285 | 286 | A separable portion of the object code, whose source code is excluded 287 | from the Corresponding Source as a System Library, need not be 288 | included in conveying the object code work. 289 | 290 | A "User Product" is either (1) a "consumer product", which means any 291 | tangible personal property which is normally used for personal, family, 292 | or household purposes, or (2) anything designed or sold for incorporation 293 | into a dwelling. In determining whether a product is a consumer product, 294 | doubtful cases shall be resolved in favor of coverage. For a particular 295 | product received by a particular user, "normally used" refers to a 296 | typical or common use of that class of product, regardless of the status 297 | of the particular user or of the way in which the particular user 298 | actually uses, or expects or is expected to use, the product. A product 299 | is a consumer product regardless of whether the product has substantial 300 | commercial, industrial or non-consumer uses, unless such uses represent 301 | the only significant mode of use of the product. 302 | 303 | "Installation Information" for a User Product means any methods, 304 | procedures, authorization keys, or other information required to install 305 | and execute modified versions of a covered work in that User Product from 306 | a modified version of its Corresponding Source. The information must 307 | suffice to ensure that the continued functioning of the modified object 308 | code is in no case prevented or interfered with solely because 309 | modification has been made. 310 | 311 | If you convey an object code work under this section in, or with, or 312 | specifically for use in, a User Product, and the conveying occurs as 313 | part of a transaction in which the right of possession and use of the 314 | User Product is transferred to the recipient in perpetuity or for a 315 | fixed term (regardless of how the transaction is characterized), the 316 | Corresponding Source conveyed under this section must be accompanied 317 | by the Installation Information. But this requirement does not apply 318 | if neither you nor any third party retains the ability to install 319 | modified object code on the User Product (for example, the work has 320 | been installed in ROM). 321 | 322 | The requirement to provide Installation Information does not include a 323 | requirement to continue to provide support service, warranty, or updates 324 | for a work that has been modified or installed by the recipient, or for 325 | the User Product in which it has been modified or installed. Access to a 326 | network may be denied when the modification itself materially and 327 | adversely affects the operation of the network or violates the rules and 328 | protocols for communication across the network. 329 | 330 | Corresponding Source conveyed, and Installation Information provided, 331 | in accord with this section must be in a format that is publicly 332 | documented (and with an implementation available to the public in 333 | source code form), and must require no special password or key for 334 | unpacking, reading or copying. 335 | 336 | 7. Additional Terms. 337 | 338 | "Additional permissions" are terms that supplement the terms of this 339 | License by making exceptions from one or more of its conditions. 340 | Additional permissions that are applicable to the entire Program shall 341 | be treated as though they were included in this License, to the extent 342 | that they are valid under applicable law. If additional permissions 343 | apply only to part of the Program, that part may be used separately 344 | under those permissions, but the entire Program remains governed by 345 | this License without regard to the additional permissions. 346 | 347 | When you convey a copy of a covered work, you may at your option 348 | remove any additional permissions from that copy, or from any part of 349 | it. (Additional permissions may be written to require their own 350 | removal in certain cases when you modify the work.) You may place 351 | additional permissions on material, added by you to a covered work, 352 | for which you have or can give appropriate copyright permission. 353 | 354 | Notwithstanding any other provision of this License, for material you 355 | add to a covered work, you may (if authorized by the copyright holders of 356 | that material) supplement the terms of this License with terms: 357 | 358 | a) Disclaiming warranty or limiting liability differently from the 359 | terms of sections 15 and 16 of this License; or 360 | 361 | b) Requiring preservation of specified reasonable legal notices or 362 | author attributions in that material or in the Appropriate Legal 363 | Notices displayed by works containing it; or 364 | 365 | c) Prohibiting misrepresentation of the origin of that material, or 366 | requiring that modified versions of such material be marked in 367 | reasonable ways as different from the original version; or 368 | 369 | d) Limiting the use for publicity purposes of names of licensors or 370 | authors of the material; or 371 | 372 | e) Declining to grant rights under trademark law for use of some 373 | trade names, trademarks, or service marks; or 374 | 375 | f) Requiring indemnification of licensors and authors of that 376 | material by anyone who conveys the material (or modified versions of 377 | it) with contractual assumptions of liability to the recipient, for 378 | any liability that these contractual assumptions directly impose on 379 | those licensors and authors. 380 | 381 | All other non-permissive additional terms are considered "further 382 | restrictions" within the meaning of section 10. If the Program as you 383 | received it, or any part of it, contains a notice stating that it is 384 | governed by this License along with a term that is a further 385 | restriction, you may remove that term. If a license document contains 386 | a further restriction but permits relicensing or conveying under this 387 | License, you may add to a covered work material governed by the terms 388 | of that license document, provided that the further restriction does 389 | not survive such relicensing or conveying. 390 | 391 | If you add terms to a covered work in accord with this section, you 392 | must place, in the relevant source files, a statement of the 393 | additional terms that apply to those files, or a notice indicating 394 | where to find the applicable terms. 395 | 396 | Additional terms, permissive or non-permissive, may be stated in the 397 | form of a separately written license, or stated as exceptions; 398 | the above requirements apply either way. 399 | 400 | 8. Termination. 401 | 402 | You may not propagate or modify a covered work except as expressly 403 | provided under this License. Any attempt otherwise to propagate or 404 | modify it is void, and will automatically terminate your rights under 405 | this License (including any patent licenses granted under the third 406 | paragraph of section 11). 407 | 408 | However, if you cease all violation of this License, then your 409 | license from a particular copyright holder is reinstated (a) 410 | provisionally, unless and until the copyright holder explicitly and 411 | finally terminates your license, and (b) permanently, if the copyright 412 | holder fails to notify you of the violation by some reasonable means 413 | prior to 60 days after the cessation. 414 | 415 | Moreover, your license from a particular copyright holder is 416 | reinstated permanently if the copyright holder notifies you of the 417 | violation by some reasonable means, this is the first time you have 418 | received notice of violation of this License (for any work) from that 419 | copyright holder, and you cure the violation prior to 30 days after 420 | your receipt of the notice. 421 | 422 | Termination of your rights under this section does not terminate the 423 | licenses of parties who have received copies or rights from you under 424 | this License. If your rights have been terminated and not permanently 425 | reinstated, you do not qualify to receive new licenses for the same 426 | material under section 10. 427 | 428 | 9. Acceptance Not Required for Having Copies. 429 | 430 | You are not required to accept this License in order to receive or 431 | run a copy of the Program. Ancillary propagation of a covered work 432 | occurring solely as a consequence of using peer-to-peer transmission 433 | to receive a copy likewise does not require acceptance. However, 434 | nothing other than this License grants you permission to propagate or 435 | modify any covered work. These actions infringe copyright if you do 436 | not accept this License. Therefore, by modifying or propagating a 437 | covered work, you indicate your acceptance of this License to do so. 438 | 439 | 10. Automatic Licensing of Downstream Recipients. 440 | 441 | Each time you convey a covered work, the recipient automatically 442 | receives a license from the original licensors, to run, modify and 443 | propagate that work, subject to this License. You are not responsible 444 | for enforcing compliance by third parties with this License. 445 | 446 | An "entity transaction" is a transaction transferring control of an 447 | organization, or substantially all assets of one, or subdividing an 448 | organization, or merging organizations. If propagation of a covered 449 | work results from an entity transaction, each party to that 450 | transaction who receives a copy of the work also receives whatever 451 | licenses to the work the party's predecessor in interest had or could 452 | give under the previous paragraph, plus a right to possession of the 453 | Corresponding Source of the work from the predecessor in interest, if 454 | the predecessor has it or can get it with reasonable efforts. 455 | 456 | You may not impose any further restrictions on the exercise of the 457 | rights granted or affirmed under this License. For example, you may 458 | not impose a license fee, royalty, or other charge for exercise of 459 | rights granted under this License, and you may not initiate litigation 460 | (including a cross-claim or counterclaim in a lawsuit) alleging that 461 | any patent claim is infringed by making, using, selling, offering for 462 | sale, or importing the Program or any portion of it. 463 | 464 | 11. Patents. 465 | 466 | A "contributor" is a copyright holder who authorizes use under this 467 | License of the Program or a work on which the Program is based. The 468 | work thus licensed is called the contributor's "contributor version". 469 | 470 | A contributor's "essential patent claims" are all patent claims 471 | owned or controlled by the contributor, whether already acquired or 472 | hereafter acquired, that would be infringed by some manner, permitted 473 | by this License, of making, using, or selling its contributor version, 474 | but do not include claims that would be infringed only as a 475 | consequence of further modification of the contributor version. For 476 | purposes of this definition, "control" includes the right to grant 477 | patent sublicenses in a manner consistent with the requirements of 478 | this License. 479 | 480 | Each contributor grants you a non-exclusive, worldwide, royalty-free 481 | patent license under the contributor's essential patent claims, to 482 | make, use, sell, offer for sale, import and otherwise run, modify and 483 | propagate the contents of its contributor version. 484 | 485 | In the following three paragraphs, a "patent license" is any express 486 | agreement or commitment, however denominated, not to enforce a patent 487 | (such as an express permission to practice a patent or covenant not to 488 | sue for patent infringement). To "grant" such a patent license to a 489 | party means to make such an agreement or commitment not to enforce a 490 | patent against the party. 491 | 492 | If you convey a covered work, knowingly relying on a patent license, 493 | and the Corresponding Source of the work is not available for anyone 494 | to copy, free of charge and under the terms of this License, through a 495 | publicly available network server or other readily accessible means, 496 | then you must either (1) cause the Corresponding Source to be so 497 | available, or (2) arrange to deprive yourself of the benefit of the 498 | patent license for this particular work, or (3) arrange, in a manner 499 | consistent with the requirements of this License, to extend the patent 500 | license to downstream recipients. "Knowingly relying" means you have 501 | actual knowledge that, but for the patent license, your conveying the 502 | covered work in a country, or your recipient's use of the covered work 503 | in a country, would infringe one or more identifiable patents in that 504 | country that you have reason to believe are valid. 505 | 506 | If, pursuant to or in connection with a single transaction or 507 | arrangement, you convey, or propagate by procuring conveyance of, a 508 | covered work, and grant a patent license to some of the parties 509 | receiving the covered work authorizing them to use, propagate, modify 510 | or convey a specific copy of the covered work, then the patent license 511 | you grant is automatically extended to all recipients of the covered 512 | work and works based on it. 513 | 514 | A patent license is "discriminatory" if it does not include within 515 | the scope of its coverage, prohibits the exercise of, or is 516 | conditioned on the non-exercise of one or more of the rights that are 517 | specifically granted under this License. You may not convey a covered 518 | work if you are a party to an arrangement with a third party that is 519 | in the business of distributing software, under which you make payment 520 | to the third party based on the extent of your activity of conveying 521 | the work, and under which the third party grants, to any of the 522 | parties who would receive the covered work from you, a discriminatory 523 | patent license (a) in connection with copies of the covered work 524 | conveyed by you (or copies made from those copies), or (b) primarily 525 | for and in connection with specific products or compilations that 526 | contain the covered work, unless you entered into that arrangement, 527 | or that patent license was granted, prior to 28 March 2007. 528 | 529 | Nothing in this License shall be construed as excluding or limiting 530 | any implied license or other defenses to infringement that may 531 | otherwise be available to you under applicable patent law. 532 | 533 | 12. No Surrender of Others' Freedom. 534 | 535 | If conditions are imposed on you (whether by court order, agreement or 536 | otherwise) that contradict the conditions of this License, they do not 537 | excuse you from the conditions of this License. If you cannot convey a 538 | covered work so as to satisfy simultaneously your obligations under this 539 | License and any other pertinent obligations, then as a consequence you may 540 | not convey it at all. For example, if you agree to terms that obligate you 541 | to collect a royalty for further conveying from those to whom you convey 542 | the Program, the only way you could satisfy both those terms and this 543 | License would be to refrain entirely from conveying the Program. 544 | 545 | 13. Remote Network Interaction; Use with the GNU General Public License. 546 | 547 | Notwithstanding any other provision of this License, if you modify the 548 | Program, your modified version must prominently offer all users 549 | interacting with it remotely through a computer network (if your version 550 | supports such interaction) an opportunity to receive the Corresponding 551 | Source of your version by providing access to the Corresponding Source 552 | from a network server at no charge, through some standard or customary 553 | means of facilitating copying of software. This Corresponding Source 554 | shall include the Corresponding Source for any work covered by version 3 555 | of the GNU General Public License that is incorporated pursuant to the 556 | following paragraph. 557 | 558 | Notwithstanding any other provision of this License, you have 559 | permission to link or combine any covered work with a work licensed 560 | under version 3 of the GNU General Public License into a single 561 | combined work, and to convey the resulting work. The terms of this 562 | License will continue to apply to the part which is the covered work, 563 | but the work with which it is combined will remain governed by version 564 | 3 of the GNU General Public License. 565 | 566 | 14. Revised Versions of this License. 567 | 568 | The Free Software Foundation may publish revised and/or new versions of 569 | the GNU Affero General Public License from time to time. Such new versions 570 | will be similar in spirit to the present version, but may differ in detail to 571 | address new problems or concerns. 572 | 573 | Each version is given a distinguishing version number. If the 574 | Program specifies that a certain numbered version of the GNU Affero General 575 | Public License "or any later version" applies to it, you have the 576 | option of following the terms and conditions either of that numbered 577 | version or of any later version published by the Free Software 578 | Foundation. If the Program does not specify a version number of the 579 | GNU Affero General Public License, you may choose any version ever published 580 | by the Free Software Foundation. 581 | 582 | If the Program specifies that a proxy can decide which future 583 | versions of the GNU Affero General Public License can be used, that proxy's 584 | public statement of acceptance of a version permanently authorizes you 585 | to choose that version for the Program. 586 | 587 | Later license versions may give you additional or different 588 | permissions. However, no additional obligations are imposed on any 589 | author or copyright holder as a result of your choosing to follow a 590 | later version. 591 | 592 | 15. Disclaimer of Warranty. 593 | 594 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 595 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 596 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 597 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 598 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 599 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 600 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 601 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 602 | 603 | 16. Limitation of Liability. 604 | 605 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 606 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 607 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 608 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 609 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 610 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 611 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 612 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 613 | SUCH DAMAGES. 614 | 615 | 17. Interpretation of Sections 15 and 16. 616 | 617 | If the disclaimer of warranty and limitation of liability provided 618 | above cannot be given local legal effect according to their terms, 619 | reviewing courts shall apply local law that most closely approximates 620 | an absolute waiver of all civil liability in connection with the 621 | Program, unless a warranty or assumption of liability accompanies a 622 | copy of the Program in return for a fee. 623 | 624 | END OF TERMS AND CONDITIONS 625 | 626 | How to Apply These Terms to Your New Programs 627 | 628 | If you develop a new program, and you want it to be of the greatest 629 | possible use to the public, the best way to achieve this is to make it 630 | free software which everyone can redistribute and change under these terms. 631 | 632 | To do so, attach the following notices to the program. It is safest 633 | to attach them to the start of each source file to most effectively 634 | state the exclusion of warranty; and each file should have at least 635 | the "copyright" line and a pointer to where the full notice is found. 636 | 637 | 638 | Copyright (C) 639 | 640 | This program is free software: you can redistribute it and/or modify 641 | it under the terms of the GNU Affero General Public License as published 642 | by the Free Software Foundation, either version 3 of the License, or 643 | (at your option) any later version. 644 | 645 | This program is distributed in the hope that it will be useful, 646 | but WITHOUT ANY WARRANTY; without even the implied warranty of 647 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 648 | GNU Affero General Public License for more details. 649 | 650 | You should have received a copy of the GNU Affero General Public License 651 | along with this program. If not, see . 652 | 653 | Also add information on how to contact you by electronic and paper mail. 654 | 655 | If your software can interact with users remotely through a computer 656 | network, you should also make sure that it provides a way for users to 657 | get its source. For example, if your program is a web application, its 658 | interface could display a "Source" link that leads users to an archive 659 | of the code. There are many ways you could offer source, and different 660 | solutions will be better for different programs; see section 13 for the 661 | specific requirements. 662 | 663 | You should also get your employer (if you work as a programmer) or school, 664 | if any, to sign a "copyright disclaimer" for the program, if necessary. 665 | For more information on this, and how to apply and follow the GNU AGPL, see 666 | . 667 | -------------------------------------------------------------------------------- /scalar_grpc_web_pb.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview gRPC-Web generated client stub for rpc 3 | * @enhanceable 4 | * @public 5 | */ 6 | 7 | // GENERATED CODE -- DO NOT EDIT! 8 | 9 | 10 | /* eslint-disable */ 11 | // @ts-nocheck 12 | 13 | 14 | 15 | const grpc = {}; 16 | grpc.web = require('grpc-web'); 17 | 18 | 19 | var google_protobuf_empty_pb = require('google-protobuf/google/protobuf/empty_pb.js') 20 | const proto = {}; 21 | proto.rpc = require('./scalar_pb.js'); 22 | 23 | /** 24 | * @param {string} hostname 25 | * @param {?Object} credentials 26 | * @param {?grpc.web.ClientOptions} options 27 | * @constructor 28 | * @struct 29 | * @final 30 | */ 31 | proto.rpc.LedgerClient = 32 | function(hostname, credentials, options) { 33 | if (!options) options = {}; 34 | options.format = 'text'; 35 | 36 | /** 37 | * @private @const {!grpc.web.GrpcWebClientBase} The client 38 | */ 39 | this.client_ = new grpc.web.GrpcWebClientBase(options); 40 | 41 | /** 42 | * @private @const {string} The hostname 43 | */ 44 | this.hostname_ = hostname; 45 | 46 | }; 47 | 48 | 49 | /** 50 | * @param {string} hostname 51 | * @param {?Object} credentials 52 | * @param {?grpc.web.ClientOptions} options 53 | * @constructor 54 | * @struct 55 | * @final 56 | */ 57 | proto.rpc.LedgerPromiseClient = 58 | function(hostname, credentials, options) { 59 | if (!options) options = {}; 60 | options.format = 'text'; 61 | 62 | /** 63 | * @private @const {!grpc.web.GrpcWebClientBase} The client 64 | */ 65 | this.client_ = new grpc.web.GrpcWebClientBase(options); 66 | 67 | /** 68 | * @private @const {string} The hostname 69 | */ 70 | this.hostname_ = hostname; 71 | 72 | }; 73 | 74 | 75 | /** 76 | * @const 77 | * @type {!grpc.web.MethodDescriptor< 78 | * !proto.rpc.ContractRegistrationRequest, 79 | * !proto.google.protobuf.Empty>} 80 | */ 81 | const methodDescriptor_Ledger_RegisterContract = new grpc.web.MethodDescriptor( 82 | '/rpc.Ledger/RegisterContract', 83 | grpc.web.MethodType.UNARY, 84 | proto.rpc.ContractRegistrationRequest, 85 | google_protobuf_empty_pb.Empty, 86 | /** 87 | * @param {!proto.rpc.ContractRegistrationRequest} request 88 | * @return {!Uint8Array} 89 | */ 90 | function(request) { 91 | return request.serializeBinary(); 92 | }, 93 | google_protobuf_empty_pb.Empty.deserializeBinary 94 | ); 95 | 96 | 97 | /** 98 | * @param {!proto.rpc.ContractRegistrationRequest} request The 99 | * request proto 100 | * @param {?Object} metadata User defined 101 | * call metadata 102 | * @param {function(?grpc.web.RpcError, ?proto.google.protobuf.Empty)} 103 | * callback The callback function(error, response) 104 | * @return {!grpc.web.ClientReadableStream|undefined} 105 | * The XHR Node Readable Stream 106 | */ 107 | proto.rpc.LedgerClient.prototype.registerContract = 108 | function(request, metadata, callback) { 109 | return this.client_.rpcCall(this.hostname_ + 110 | '/rpc.Ledger/RegisterContract', 111 | request, 112 | metadata || {}, 113 | methodDescriptor_Ledger_RegisterContract, 114 | callback); 115 | }; 116 | 117 | 118 | /** 119 | * @param {!proto.rpc.ContractRegistrationRequest} request The 120 | * request proto 121 | * @param {?Object=} metadata User defined 122 | * call metadata 123 | * @return {!Promise} 124 | * Promise that resolves to the response 125 | */ 126 | proto.rpc.LedgerPromiseClient.prototype.registerContract = 127 | function(request, metadata) { 128 | return this.client_.unaryCall(this.hostname_ + 129 | '/rpc.Ledger/RegisterContract', 130 | request, 131 | metadata || {}, 132 | methodDescriptor_Ledger_RegisterContract); 133 | }; 134 | 135 | 136 | /** 137 | * @const 138 | * @type {!grpc.web.MethodDescriptor< 139 | * !proto.rpc.ContractsListingRequest, 140 | * !proto.rpc.ContractsListingResponse>} 141 | */ 142 | const methodDescriptor_Ledger_ListContracts = new grpc.web.MethodDescriptor( 143 | '/rpc.Ledger/ListContracts', 144 | grpc.web.MethodType.UNARY, 145 | proto.rpc.ContractsListingRequest, 146 | proto.rpc.ContractsListingResponse, 147 | /** 148 | * @param {!proto.rpc.ContractsListingRequest} request 149 | * @return {!Uint8Array} 150 | */ 151 | function(request) { 152 | return request.serializeBinary(); 153 | }, 154 | proto.rpc.ContractsListingResponse.deserializeBinary 155 | ); 156 | 157 | 158 | /** 159 | * @param {!proto.rpc.ContractsListingRequest} request The 160 | * request proto 161 | * @param {?Object} metadata User defined 162 | * call metadata 163 | * @param {function(?grpc.web.RpcError, ?proto.rpc.ContractsListingResponse)} 164 | * callback The callback function(error, response) 165 | * @return {!grpc.web.ClientReadableStream|undefined} 166 | * The XHR Node Readable Stream 167 | */ 168 | proto.rpc.LedgerClient.prototype.listContracts = 169 | function(request, metadata, callback) { 170 | return this.client_.rpcCall(this.hostname_ + 171 | '/rpc.Ledger/ListContracts', 172 | request, 173 | metadata || {}, 174 | methodDescriptor_Ledger_ListContracts, 175 | callback); 176 | }; 177 | 178 | 179 | /** 180 | * @param {!proto.rpc.ContractsListingRequest} request The 181 | * request proto 182 | * @param {?Object=} metadata User defined 183 | * call metadata 184 | * @return {!Promise} 185 | * Promise that resolves to the response 186 | */ 187 | proto.rpc.LedgerPromiseClient.prototype.listContracts = 188 | function(request, metadata) { 189 | return this.client_.unaryCall(this.hostname_ + 190 | '/rpc.Ledger/ListContracts', 191 | request, 192 | metadata || {}, 193 | methodDescriptor_Ledger_ListContracts); 194 | }; 195 | 196 | 197 | /** 198 | * @const 199 | * @type {!grpc.web.MethodDescriptor< 200 | * !proto.rpc.ContractExecutionRequest, 201 | * !proto.rpc.ContractExecutionResponse>} 202 | */ 203 | const methodDescriptor_Ledger_ExecuteContract = new grpc.web.MethodDescriptor( 204 | '/rpc.Ledger/ExecuteContract', 205 | grpc.web.MethodType.UNARY, 206 | proto.rpc.ContractExecutionRequest, 207 | proto.rpc.ContractExecutionResponse, 208 | /** 209 | * @param {!proto.rpc.ContractExecutionRequest} request 210 | * @return {!Uint8Array} 211 | */ 212 | function(request) { 213 | return request.serializeBinary(); 214 | }, 215 | proto.rpc.ContractExecutionResponse.deserializeBinary 216 | ); 217 | 218 | 219 | /** 220 | * @param {!proto.rpc.ContractExecutionRequest} request The 221 | * request proto 222 | * @param {?Object} metadata User defined 223 | * call metadata 224 | * @param {function(?grpc.web.RpcError, ?proto.rpc.ContractExecutionResponse)} 225 | * callback The callback function(error, response) 226 | * @return {!grpc.web.ClientReadableStream|undefined} 227 | * The XHR Node Readable Stream 228 | */ 229 | proto.rpc.LedgerClient.prototype.executeContract = 230 | function(request, metadata, callback) { 231 | return this.client_.rpcCall(this.hostname_ + 232 | '/rpc.Ledger/ExecuteContract', 233 | request, 234 | metadata || {}, 235 | methodDescriptor_Ledger_ExecuteContract, 236 | callback); 237 | }; 238 | 239 | 240 | /** 241 | * @param {!proto.rpc.ContractExecutionRequest} request The 242 | * request proto 243 | * @param {?Object=} metadata User defined 244 | * call metadata 245 | * @return {!Promise} 246 | * Promise that resolves to the response 247 | */ 248 | proto.rpc.LedgerPromiseClient.prototype.executeContract = 249 | function(request, metadata) { 250 | return this.client_.unaryCall(this.hostname_ + 251 | '/rpc.Ledger/ExecuteContract', 252 | request, 253 | metadata || {}, 254 | methodDescriptor_Ledger_ExecuteContract); 255 | }; 256 | 257 | 258 | /** 259 | * @const 260 | * @type {!grpc.web.MethodDescriptor< 261 | * !proto.rpc.LedgerValidationRequest, 262 | * !proto.rpc.LedgerValidationResponse>} 263 | */ 264 | const methodDescriptor_Ledger_ValidateLedger = new grpc.web.MethodDescriptor( 265 | '/rpc.Ledger/ValidateLedger', 266 | grpc.web.MethodType.UNARY, 267 | proto.rpc.LedgerValidationRequest, 268 | proto.rpc.LedgerValidationResponse, 269 | /** 270 | * @param {!proto.rpc.LedgerValidationRequest} request 271 | * @return {!Uint8Array} 272 | */ 273 | function(request) { 274 | return request.serializeBinary(); 275 | }, 276 | proto.rpc.LedgerValidationResponse.deserializeBinary 277 | ); 278 | 279 | 280 | /** 281 | * @param {!proto.rpc.LedgerValidationRequest} request The 282 | * request proto 283 | * @param {?Object} metadata User defined 284 | * call metadata 285 | * @param {function(?grpc.web.RpcError, ?proto.rpc.LedgerValidationResponse)} 286 | * callback The callback function(error, response) 287 | * @return {!grpc.web.ClientReadableStream|undefined} 288 | * The XHR Node Readable Stream 289 | */ 290 | proto.rpc.LedgerClient.prototype.validateLedger = 291 | function(request, metadata, callback) { 292 | return this.client_.rpcCall(this.hostname_ + 293 | '/rpc.Ledger/ValidateLedger', 294 | request, 295 | metadata || {}, 296 | methodDescriptor_Ledger_ValidateLedger, 297 | callback); 298 | }; 299 | 300 | 301 | /** 302 | * @param {!proto.rpc.LedgerValidationRequest} request The 303 | * request proto 304 | * @param {?Object=} metadata User defined 305 | * call metadata 306 | * @return {!Promise} 307 | * Promise that resolves to the response 308 | */ 309 | proto.rpc.LedgerPromiseClient.prototype.validateLedger = 310 | function(request, metadata) { 311 | return this.client_.unaryCall(this.hostname_ + 312 | '/rpc.Ledger/ValidateLedger', 313 | request, 314 | metadata || {}, 315 | methodDescriptor_Ledger_ValidateLedger); 316 | }; 317 | 318 | 319 | /** 320 | * @const 321 | * @type {!grpc.web.MethodDescriptor< 322 | * !proto.rpc.AssetProofRetrievalRequest, 323 | * !proto.rpc.AssetProofRetrievalResponse>} 324 | */ 325 | const methodDescriptor_Ledger_RetrieveAssetProof = new grpc.web.MethodDescriptor( 326 | '/rpc.Ledger/RetrieveAssetProof', 327 | grpc.web.MethodType.UNARY, 328 | proto.rpc.AssetProofRetrievalRequest, 329 | proto.rpc.AssetProofRetrievalResponse, 330 | /** 331 | * @param {!proto.rpc.AssetProofRetrievalRequest} request 332 | * @return {!Uint8Array} 333 | */ 334 | function(request) { 335 | return request.serializeBinary(); 336 | }, 337 | proto.rpc.AssetProofRetrievalResponse.deserializeBinary 338 | ); 339 | 340 | 341 | /** 342 | * @param {!proto.rpc.AssetProofRetrievalRequest} request The 343 | * request proto 344 | * @param {?Object} metadata User defined 345 | * call metadata 346 | * @param {function(?grpc.web.RpcError, ?proto.rpc.AssetProofRetrievalResponse)} 347 | * callback The callback function(error, response) 348 | * @return {!grpc.web.ClientReadableStream|undefined} 349 | * The XHR Node Readable Stream 350 | */ 351 | proto.rpc.LedgerClient.prototype.retrieveAssetProof = 352 | function(request, metadata, callback) { 353 | return this.client_.rpcCall(this.hostname_ + 354 | '/rpc.Ledger/RetrieveAssetProof', 355 | request, 356 | metadata || {}, 357 | methodDescriptor_Ledger_RetrieveAssetProof, 358 | callback); 359 | }; 360 | 361 | 362 | /** 363 | * @param {!proto.rpc.AssetProofRetrievalRequest} request The 364 | * request proto 365 | * @param {?Object=} metadata User defined 366 | * call metadata 367 | * @return {!Promise} 368 | * Promise that resolves to the response 369 | */ 370 | proto.rpc.LedgerPromiseClient.prototype.retrieveAssetProof = 371 | function(request, metadata) { 372 | return this.client_.unaryCall(this.hostname_ + 373 | '/rpc.Ledger/RetrieveAssetProof', 374 | request, 375 | metadata || {}, 376 | methodDescriptor_Ledger_RetrieveAssetProof); 377 | }; 378 | 379 | 380 | /** 381 | * @const 382 | * @type {!grpc.web.MethodDescriptor< 383 | * !proto.rpc.ExecutionAbortRequest, 384 | * !proto.rpc.ExecutionAbortResponse>} 385 | */ 386 | const methodDescriptor_Ledger_AbortExecution = new grpc.web.MethodDescriptor( 387 | '/rpc.Ledger/AbortExecution', 388 | grpc.web.MethodType.UNARY, 389 | proto.rpc.ExecutionAbortRequest, 390 | proto.rpc.ExecutionAbortResponse, 391 | /** 392 | * @param {!proto.rpc.ExecutionAbortRequest} request 393 | * @return {!Uint8Array} 394 | */ 395 | function(request) { 396 | return request.serializeBinary(); 397 | }, 398 | proto.rpc.ExecutionAbortResponse.deserializeBinary 399 | ); 400 | 401 | 402 | /** 403 | * @param {!proto.rpc.ExecutionAbortRequest} request The 404 | * request proto 405 | * @param {?Object} metadata User defined 406 | * call metadata 407 | * @param {function(?grpc.web.RpcError, ?proto.rpc.ExecutionAbortResponse)} 408 | * callback The callback function(error, response) 409 | * @return {!grpc.web.ClientReadableStream|undefined} 410 | * The XHR Node Readable Stream 411 | */ 412 | proto.rpc.LedgerClient.prototype.abortExecution = 413 | function(request, metadata, callback) { 414 | return this.client_.rpcCall(this.hostname_ + 415 | '/rpc.Ledger/AbortExecution', 416 | request, 417 | metadata || {}, 418 | methodDescriptor_Ledger_AbortExecution, 419 | callback); 420 | }; 421 | 422 | 423 | /** 424 | * @param {!proto.rpc.ExecutionAbortRequest} request The 425 | * request proto 426 | * @param {?Object=} metadata User defined 427 | * call metadata 428 | * @return {!Promise} 429 | * Promise that resolves to the response 430 | */ 431 | proto.rpc.LedgerPromiseClient.prototype.abortExecution = 432 | function(request, metadata) { 433 | return this.client_.unaryCall(this.hostname_ + 434 | '/rpc.Ledger/AbortExecution', 435 | request, 436 | metadata || {}, 437 | methodDescriptor_Ledger_AbortExecution); 438 | }; 439 | 440 | 441 | /** 442 | * @param {string} hostname 443 | * @param {?Object} credentials 444 | * @param {?grpc.web.ClientOptions} options 445 | * @constructor 446 | * @struct 447 | * @final 448 | */ 449 | proto.rpc.LedgerPrivilegedClient = 450 | function(hostname, credentials, options) { 451 | if (!options) options = {}; 452 | options.format = 'text'; 453 | 454 | /** 455 | * @private @const {!grpc.web.GrpcWebClientBase} The client 456 | */ 457 | this.client_ = new grpc.web.GrpcWebClientBase(options); 458 | 459 | /** 460 | * @private @const {string} The hostname 461 | */ 462 | this.hostname_ = hostname; 463 | 464 | }; 465 | 466 | 467 | /** 468 | * @param {string} hostname 469 | * @param {?Object} credentials 470 | * @param {?grpc.web.ClientOptions} options 471 | * @constructor 472 | * @struct 473 | * @final 474 | */ 475 | proto.rpc.LedgerPrivilegedPromiseClient = 476 | function(hostname, credentials, options) { 477 | if (!options) options = {}; 478 | options.format = 'text'; 479 | 480 | /** 481 | * @private @const {!grpc.web.GrpcWebClientBase} The client 482 | */ 483 | this.client_ = new grpc.web.GrpcWebClientBase(options); 484 | 485 | /** 486 | * @private @const {string} The hostname 487 | */ 488 | this.hostname_ = hostname; 489 | 490 | }; 491 | 492 | 493 | /** 494 | * @const 495 | * @type {!grpc.web.MethodDescriptor< 496 | * !proto.rpc.CertificateRegistrationRequest, 497 | * !proto.google.protobuf.Empty>} 498 | */ 499 | const methodDescriptor_LedgerPrivileged_RegisterCert = new grpc.web.MethodDescriptor( 500 | '/rpc.LedgerPrivileged/RegisterCert', 501 | grpc.web.MethodType.UNARY, 502 | proto.rpc.CertificateRegistrationRequest, 503 | google_protobuf_empty_pb.Empty, 504 | /** 505 | * @param {!proto.rpc.CertificateRegistrationRequest} request 506 | * @return {!Uint8Array} 507 | */ 508 | function(request) { 509 | return request.serializeBinary(); 510 | }, 511 | google_protobuf_empty_pb.Empty.deserializeBinary 512 | ); 513 | 514 | 515 | /** 516 | * @param {!proto.rpc.CertificateRegistrationRequest} request The 517 | * request proto 518 | * @param {?Object} metadata User defined 519 | * call metadata 520 | * @param {function(?grpc.web.RpcError, ?proto.google.protobuf.Empty)} 521 | * callback The callback function(error, response) 522 | * @return {!grpc.web.ClientReadableStream|undefined} 523 | * The XHR Node Readable Stream 524 | */ 525 | proto.rpc.LedgerPrivilegedClient.prototype.registerCert = 526 | function(request, metadata, callback) { 527 | return this.client_.rpcCall(this.hostname_ + 528 | '/rpc.LedgerPrivileged/RegisterCert', 529 | request, 530 | metadata || {}, 531 | methodDescriptor_LedgerPrivileged_RegisterCert, 532 | callback); 533 | }; 534 | 535 | 536 | /** 537 | * @param {!proto.rpc.CertificateRegistrationRequest} request The 538 | * request proto 539 | * @param {?Object=} metadata User defined 540 | * call metadata 541 | * @return {!Promise} 542 | * Promise that resolves to the response 543 | */ 544 | proto.rpc.LedgerPrivilegedPromiseClient.prototype.registerCert = 545 | function(request, metadata) { 546 | return this.client_.unaryCall(this.hostname_ + 547 | '/rpc.LedgerPrivileged/RegisterCert', 548 | request, 549 | metadata || {}, 550 | methodDescriptor_LedgerPrivileged_RegisterCert); 551 | }; 552 | 553 | 554 | /** 555 | * @const 556 | * @type {!grpc.web.MethodDescriptor< 557 | * !proto.rpc.FunctionRegistrationRequest, 558 | * !proto.google.protobuf.Empty>} 559 | */ 560 | const methodDescriptor_LedgerPrivileged_RegisterFunction = new grpc.web.MethodDescriptor( 561 | '/rpc.LedgerPrivileged/RegisterFunction', 562 | grpc.web.MethodType.UNARY, 563 | proto.rpc.FunctionRegistrationRequest, 564 | google_protobuf_empty_pb.Empty, 565 | /** 566 | * @param {!proto.rpc.FunctionRegistrationRequest} request 567 | * @return {!Uint8Array} 568 | */ 569 | function(request) { 570 | return request.serializeBinary(); 571 | }, 572 | google_protobuf_empty_pb.Empty.deserializeBinary 573 | ); 574 | 575 | 576 | /** 577 | * @param {!proto.rpc.FunctionRegistrationRequest} request The 578 | * request proto 579 | * @param {?Object} metadata User defined 580 | * call metadata 581 | * @param {function(?grpc.web.RpcError, ?proto.google.protobuf.Empty)} 582 | * callback The callback function(error, response) 583 | * @return {!grpc.web.ClientReadableStream|undefined} 584 | * The XHR Node Readable Stream 585 | */ 586 | proto.rpc.LedgerPrivilegedClient.prototype.registerFunction = 587 | function(request, metadata, callback) { 588 | return this.client_.rpcCall(this.hostname_ + 589 | '/rpc.LedgerPrivileged/RegisterFunction', 590 | request, 591 | metadata || {}, 592 | methodDescriptor_LedgerPrivileged_RegisterFunction, 593 | callback); 594 | }; 595 | 596 | 597 | /** 598 | * @param {!proto.rpc.FunctionRegistrationRequest} request The 599 | * request proto 600 | * @param {?Object=} metadata User defined 601 | * call metadata 602 | * @return {!Promise} 603 | * Promise that resolves to the response 604 | */ 605 | proto.rpc.LedgerPrivilegedPromiseClient.prototype.registerFunction = 606 | function(request, metadata) { 607 | return this.client_.unaryCall(this.hostname_ + 608 | '/rpc.LedgerPrivileged/RegisterFunction', 609 | request, 610 | metadata || {}, 611 | methodDescriptor_LedgerPrivileged_RegisterFunction); 612 | }; 613 | 614 | 615 | /** 616 | * @const 617 | * @type {!grpc.web.MethodDescriptor< 618 | * !proto.rpc.StateRetrievalRequest, 619 | * !proto.rpc.StateRetrievalResponse>} 620 | */ 621 | const methodDescriptor_LedgerPrivileged_RetrieveState = new grpc.web.MethodDescriptor( 622 | '/rpc.LedgerPrivileged/RetrieveState', 623 | grpc.web.MethodType.UNARY, 624 | proto.rpc.StateRetrievalRequest, 625 | proto.rpc.StateRetrievalResponse, 626 | /** 627 | * @param {!proto.rpc.StateRetrievalRequest} request 628 | * @return {!Uint8Array} 629 | */ 630 | function(request) { 631 | return request.serializeBinary(); 632 | }, 633 | proto.rpc.StateRetrievalResponse.deserializeBinary 634 | ); 635 | 636 | 637 | /** 638 | * @param {!proto.rpc.StateRetrievalRequest} request The 639 | * request proto 640 | * @param {?Object} metadata User defined 641 | * call metadata 642 | * @param {function(?grpc.web.RpcError, ?proto.rpc.StateRetrievalResponse)} 643 | * callback The callback function(error, response) 644 | * @return {!grpc.web.ClientReadableStream|undefined} 645 | * The XHR Node Readable Stream 646 | */ 647 | proto.rpc.LedgerPrivilegedClient.prototype.retrieveState = 648 | function(request, metadata, callback) { 649 | return this.client_.rpcCall(this.hostname_ + 650 | '/rpc.LedgerPrivileged/RetrieveState', 651 | request, 652 | metadata || {}, 653 | methodDescriptor_LedgerPrivileged_RetrieveState, 654 | callback); 655 | }; 656 | 657 | 658 | /** 659 | * @param {!proto.rpc.StateRetrievalRequest} request The 660 | * request proto 661 | * @param {?Object=} metadata User defined 662 | * call metadata 663 | * @return {!Promise} 664 | * Promise that resolves to the response 665 | */ 666 | proto.rpc.LedgerPrivilegedPromiseClient.prototype.retrieveState = 667 | function(request, metadata) { 668 | return this.client_.unaryCall(this.hostname_ + 669 | '/rpc.LedgerPrivileged/RetrieveState', 670 | request, 671 | metadata || {}, 672 | methodDescriptor_LedgerPrivileged_RetrieveState); 673 | }; 674 | 675 | 676 | /** 677 | * @param {string} hostname 678 | * @param {?Object} credentials 679 | * @param {?grpc.web.ClientOptions} options 680 | * @constructor 681 | * @struct 682 | * @final 683 | */ 684 | proto.rpc.AuditorClient = 685 | function(hostname, credentials, options) { 686 | if (!options) options = {}; 687 | options.format = 'text'; 688 | 689 | /** 690 | * @private @const {!grpc.web.GrpcWebClientBase} The client 691 | */ 692 | this.client_ = new grpc.web.GrpcWebClientBase(options); 693 | 694 | /** 695 | * @private @const {string} The hostname 696 | */ 697 | this.hostname_ = hostname; 698 | 699 | }; 700 | 701 | 702 | /** 703 | * @param {string} hostname 704 | * @param {?Object} credentials 705 | * @param {?grpc.web.ClientOptions} options 706 | * @constructor 707 | * @struct 708 | * @final 709 | */ 710 | proto.rpc.AuditorPromiseClient = 711 | function(hostname, credentials, options) { 712 | if (!options) options = {}; 713 | options.format = 'text'; 714 | 715 | /** 716 | * @private @const {!grpc.web.GrpcWebClientBase} The client 717 | */ 718 | this.client_ = new grpc.web.GrpcWebClientBase(options); 719 | 720 | /** 721 | * @private @const {string} The hostname 722 | */ 723 | this.hostname_ = hostname; 724 | 725 | }; 726 | 727 | 728 | /** 729 | * @const 730 | * @type {!grpc.web.MethodDescriptor< 731 | * !proto.rpc.ContractRegistrationRequest, 732 | * !proto.google.protobuf.Empty>} 733 | */ 734 | const methodDescriptor_Auditor_RegisterContract = new grpc.web.MethodDescriptor( 735 | '/rpc.Auditor/RegisterContract', 736 | grpc.web.MethodType.UNARY, 737 | proto.rpc.ContractRegistrationRequest, 738 | google_protobuf_empty_pb.Empty, 739 | /** 740 | * @param {!proto.rpc.ContractRegistrationRequest} request 741 | * @return {!Uint8Array} 742 | */ 743 | function(request) { 744 | return request.serializeBinary(); 745 | }, 746 | google_protobuf_empty_pb.Empty.deserializeBinary 747 | ); 748 | 749 | 750 | /** 751 | * @param {!proto.rpc.ContractRegistrationRequest} request The 752 | * request proto 753 | * @param {?Object} metadata User defined 754 | * call metadata 755 | * @param {function(?grpc.web.RpcError, ?proto.google.protobuf.Empty)} 756 | * callback The callback function(error, response) 757 | * @return {!grpc.web.ClientReadableStream|undefined} 758 | * The XHR Node Readable Stream 759 | */ 760 | proto.rpc.AuditorClient.prototype.registerContract = 761 | function(request, metadata, callback) { 762 | return this.client_.rpcCall(this.hostname_ + 763 | '/rpc.Auditor/RegisterContract', 764 | request, 765 | metadata || {}, 766 | methodDescriptor_Auditor_RegisterContract, 767 | callback); 768 | }; 769 | 770 | 771 | /** 772 | * @param {!proto.rpc.ContractRegistrationRequest} request The 773 | * request proto 774 | * @param {?Object=} metadata User defined 775 | * call metadata 776 | * @return {!Promise} 777 | * Promise that resolves to the response 778 | */ 779 | proto.rpc.AuditorPromiseClient.prototype.registerContract = 780 | function(request, metadata) { 781 | return this.client_.unaryCall(this.hostname_ + 782 | '/rpc.Auditor/RegisterContract', 783 | request, 784 | metadata || {}, 785 | methodDescriptor_Auditor_RegisterContract); 786 | }; 787 | 788 | 789 | /** 790 | * @const 791 | * @type {!grpc.web.MethodDescriptor< 792 | * !proto.rpc.ContractsListingRequest, 793 | * !proto.rpc.ContractsListingResponse>} 794 | */ 795 | const methodDescriptor_Auditor_ListContracts = new grpc.web.MethodDescriptor( 796 | '/rpc.Auditor/ListContracts', 797 | grpc.web.MethodType.UNARY, 798 | proto.rpc.ContractsListingRequest, 799 | proto.rpc.ContractsListingResponse, 800 | /** 801 | * @param {!proto.rpc.ContractsListingRequest} request 802 | * @return {!Uint8Array} 803 | */ 804 | function(request) { 805 | return request.serializeBinary(); 806 | }, 807 | proto.rpc.ContractsListingResponse.deserializeBinary 808 | ); 809 | 810 | 811 | /** 812 | * @param {!proto.rpc.ContractsListingRequest} request The 813 | * request proto 814 | * @param {?Object} metadata User defined 815 | * call metadata 816 | * @param {function(?grpc.web.RpcError, ?proto.rpc.ContractsListingResponse)} 817 | * callback The callback function(error, response) 818 | * @return {!grpc.web.ClientReadableStream|undefined} 819 | * The XHR Node Readable Stream 820 | */ 821 | proto.rpc.AuditorClient.prototype.listContracts = 822 | function(request, metadata, callback) { 823 | return this.client_.rpcCall(this.hostname_ + 824 | '/rpc.Auditor/ListContracts', 825 | request, 826 | metadata || {}, 827 | methodDescriptor_Auditor_ListContracts, 828 | callback); 829 | }; 830 | 831 | 832 | /** 833 | * @param {!proto.rpc.ContractsListingRequest} request The 834 | * request proto 835 | * @param {?Object=} metadata User defined 836 | * call metadata 837 | * @return {!Promise} 838 | * Promise that resolves to the response 839 | */ 840 | proto.rpc.AuditorPromiseClient.prototype.listContracts = 841 | function(request, metadata) { 842 | return this.client_.unaryCall(this.hostname_ + 843 | '/rpc.Auditor/ListContracts', 844 | request, 845 | metadata || {}, 846 | methodDescriptor_Auditor_ListContracts); 847 | }; 848 | 849 | 850 | /** 851 | * @const 852 | * @type {!grpc.web.MethodDescriptor< 853 | * !proto.rpc.ContractExecutionRequest, 854 | * !proto.rpc.ExecutionOrderingResponse>} 855 | */ 856 | const methodDescriptor_Auditor_OrderExecution = new grpc.web.MethodDescriptor( 857 | '/rpc.Auditor/OrderExecution', 858 | grpc.web.MethodType.UNARY, 859 | proto.rpc.ContractExecutionRequest, 860 | proto.rpc.ExecutionOrderingResponse, 861 | /** 862 | * @param {!proto.rpc.ContractExecutionRequest} request 863 | * @return {!Uint8Array} 864 | */ 865 | function(request) { 866 | return request.serializeBinary(); 867 | }, 868 | proto.rpc.ExecutionOrderingResponse.deserializeBinary 869 | ); 870 | 871 | 872 | /** 873 | * @param {!proto.rpc.ContractExecutionRequest} request The 874 | * request proto 875 | * @param {?Object} metadata User defined 876 | * call metadata 877 | * @param {function(?grpc.web.RpcError, ?proto.rpc.ExecutionOrderingResponse)} 878 | * callback The callback function(error, response) 879 | * @return {!grpc.web.ClientReadableStream|undefined} 880 | * The XHR Node Readable Stream 881 | */ 882 | proto.rpc.AuditorClient.prototype.orderExecution = 883 | function(request, metadata, callback) { 884 | return this.client_.rpcCall(this.hostname_ + 885 | '/rpc.Auditor/OrderExecution', 886 | request, 887 | metadata || {}, 888 | methodDescriptor_Auditor_OrderExecution, 889 | callback); 890 | }; 891 | 892 | 893 | /** 894 | * @param {!proto.rpc.ContractExecutionRequest} request The 895 | * request proto 896 | * @param {?Object=} metadata User defined 897 | * call metadata 898 | * @return {!Promise} 899 | * Promise that resolves to the response 900 | */ 901 | proto.rpc.AuditorPromiseClient.prototype.orderExecution = 902 | function(request, metadata) { 903 | return this.client_.unaryCall(this.hostname_ + 904 | '/rpc.Auditor/OrderExecution', 905 | request, 906 | metadata || {}, 907 | methodDescriptor_Auditor_OrderExecution); 908 | }; 909 | 910 | 911 | /** 912 | * @const 913 | * @type {!grpc.web.MethodDescriptor< 914 | * !proto.rpc.ExecutionValidationRequest, 915 | * !proto.rpc.ContractExecutionResponse>} 916 | */ 917 | const methodDescriptor_Auditor_ValidateExecution = new grpc.web.MethodDescriptor( 918 | '/rpc.Auditor/ValidateExecution', 919 | grpc.web.MethodType.UNARY, 920 | proto.rpc.ExecutionValidationRequest, 921 | proto.rpc.ContractExecutionResponse, 922 | /** 923 | * @param {!proto.rpc.ExecutionValidationRequest} request 924 | * @return {!Uint8Array} 925 | */ 926 | function(request) { 927 | return request.serializeBinary(); 928 | }, 929 | proto.rpc.ContractExecutionResponse.deserializeBinary 930 | ); 931 | 932 | 933 | /** 934 | * @param {!proto.rpc.ExecutionValidationRequest} request The 935 | * request proto 936 | * @param {?Object} metadata User defined 937 | * call metadata 938 | * @param {function(?grpc.web.RpcError, ?proto.rpc.ContractExecutionResponse)} 939 | * callback The callback function(error, response) 940 | * @return {!grpc.web.ClientReadableStream|undefined} 941 | * The XHR Node Readable Stream 942 | */ 943 | proto.rpc.AuditorClient.prototype.validateExecution = 944 | function(request, metadata, callback) { 945 | return this.client_.rpcCall(this.hostname_ + 946 | '/rpc.Auditor/ValidateExecution', 947 | request, 948 | metadata || {}, 949 | methodDescriptor_Auditor_ValidateExecution, 950 | callback); 951 | }; 952 | 953 | 954 | /** 955 | * @param {!proto.rpc.ExecutionValidationRequest} request The 956 | * request proto 957 | * @param {?Object=} metadata User defined 958 | * call metadata 959 | * @return {!Promise} 960 | * Promise that resolves to the response 961 | */ 962 | proto.rpc.AuditorPromiseClient.prototype.validateExecution = 963 | function(request, metadata) { 964 | return this.client_.unaryCall(this.hostname_ + 965 | '/rpc.Auditor/ValidateExecution', 966 | request, 967 | metadata || {}, 968 | methodDescriptor_Auditor_ValidateExecution); 969 | }; 970 | 971 | 972 | /** 973 | * @const 974 | * @type {!grpc.web.MethodDescriptor< 975 | * !proto.rpc.LedgerValidationRequest, 976 | * !proto.rpc.LedgerValidationResponse>} 977 | */ 978 | const methodDescriptor_Auditor_ValidateLedger = new grpc.web.MethodDescriptor( 979 | '/rpc.Auditor/ValidateLedger', 980 | grpc.web.MethodType.UNARY, 981 | proto.rpc.LedgerValidationRequest, 982 | proto.rpc.LedgerValidationResponse, 983 | /** 984 | * @param {!proto.rpc.LedgerValidationRequest} request 985 | * @return {!Uint8Array} 986 | */ 987 | function(request) { 988 | return request.serializeBinary(); 989 | }, 990 | proto.rpc.LedgerValidationResponse.deserializeBinary 991 | ); 992 | 993 | 994 | /** 995 | * @param {!proto.rpc.LedgerValidationRequest} request The 996 | * request proto 997 | * @param {?Object} metadata User defined 998 | * call metadata 999 | * @param {function(?grpc.web.RpcError, ?proto.rpc.LedgerValidationResponse)} 1000 | * callback The callback function(error, response) 1001 | * @return {!grpc.web.ClientReadableStream|undefined} 1002 | * The XHR Node Readable Stream 1003 | */ 1004 | proto.rpc.AuditorClient.prototype.validateLedger = 1005 | function(request, metadata, callback) { 1006 | return this.client_.rpcCall(this.hostname_ + 1007 | '/rpc.Auditor/ValidateLedger', 1008 | request, 1009 | metadata || {}, 1010 | methodDescriptor_Auditor_ValidateLedger, 1011 | callback); 1012 | }; 1013 | 1014 | 1015 | /** 1016 | * @param {!proto.rpc.LedgerValidationRequest} request The 1017 | * request proto 1018 | * @param {?Object=} metadata User defined 1019 | * call metadata 1020 | * @return {!Promise} 1021 | * Promise that resolves to the response 1022 | */ 1023 | proto.rpc.AuditorPromiseClient.prototype.validateLedger = 1024 | function(request, metadata) { 1025 | return this.client_.unaryCall(this.hostname_ + 1026 | '/rpc.Auditor/ValidateLedger', 1027 | request, 1028 | metadata || {}, 1029 | methodDescriptor_Auditor_ValidateLedger); 1030 | }; 1031 | 1032 | 1033 | /** 1034 | * @param {string} hostname 1035 | * @param {?Object} credentials 1036 | * @param {?grpc.web.ClientOptions} options 1037 | * @constructor 1038 | * @struct 1039 | * @final 1040 | */ 1041 | proto.rpc.AuditorPrivilegedClient = 1042 | function(hostname, credentials, options) { 1043 | if (!options) options = {}; 1044 | options.format = 'text'; 1045 | 1046 | /** 1047 | * @private @const {!grpc.web.GrpcWebClientBase} The client 1048 | */ 1049 | this.client_ = new grpc.web.GrpcWebClientBase(options); 1050 | 1051 | /** 1052 | * @private @const {string} The hostname 1053 | */ 1054 | this.hostname_ = hostname; 1055 | 1056 | }; 1057 | 1058 | 1059 | /** 1060 | * @param {string} hostname 1061 | * @param {?Object} credentials 1062 | * @param {?grpc.web.ClientOptions} options 1063 | * @constructor 1064 | * @struct 1065 | * @final 1066 | */ 1067 | proto.rpc.AuditorPrivilegedPromiseClient = 1068 | function(hostname, credentials, options) { 1069 | if (!options) options = {}; 1070 | options.format = 'text'; 1071 | 1072 | /** 1073 | * @private @const {!grpc.web.GrpcWebClientBase} The client 1074 | */ 1075 | this.client_ = new grpc.web.GrpcWebClientBase(options); 1076 | 1077 | /** 1078 | * @private @const {string} The hostname 1079 | */ 1080 | this.hostname_ = hostname; 1081 | 1082 | }; 1083 | 1084 | 1085 | /** 1086 | * @const 1087 | * @type {!grpc.web.MethodDescriptor< 1088 | * !proto.rpc.CertificateRegistrationRequest, 1089 | * !proto.google.protobuf.Empty>} 1090 | */ 1091 | const methodDescriptor_AuditorPrivileged_RegisterCert = new grpc.web.MethodDescriptor( 1092 | '/rpc.AuditorPrivileged/RegisterCert', 1093 | grpc.web.MethodType.UNARY, 1094 | proto.rpc.CertificateRegistrationRequest, 1095 | google_protobuf_empty_pb.Empty, 1096 | /** 1097 | * @param {!proto.rpc.CertificateRegistrationRequest} request 1098 | * @return {!Uint8Array} 1099 | */ 1100 | function(request) { 1101 | return request.serializeBinary(); 1102 | }, 1103 | google_protobuf_empty_pb.Empty.deserializeBinary 1104 | ); 1105 | 1106 | 1107 | /** 1108 | * @param {!proto.rpc.CertificateRegistrationRequest} request The 1109 | * request proto 1110 | * @param {?Object} metadata User defined 1111 | * call metadata 1112 | * @param {function(?grpc.web.RpcError, ?proto.google.protobuf.Empty)} 1113 | * callback The callback function(error, response) 1114 | * @return {!grpc.web.ClientReadableStream|undefined} 1115 | * The XHR Node Readable Stream 1116 | */ 1117 | proto.rpc.AuditorPrivilegedClient.prototype.registerCert = 1118 | function(request, metadata, callback) { 1119 | return this.client_.rpcCall(this.hostname_ + 1120 | '/rpc.AuditorPrivileged/RegisterCert', 1121 | request, 1122 | metadata || {}, 1123 | methodDescriptor_AuditorPrivileged_RegisterCert, 1124 | callback); 1125 | }; 1126 | 1127 | 1128 | /** 1129 | * @param {!proto.rpc.CertificateRegistrationRequest} request The 1130 | * request proto 1131 | * @param {?Object=} metadata User defined 1132 | * call metadata 1133 | * @return {!Promise} 1134 | * Promise that resolves to the response 1135 | */ 1136 | proto.rpc.AuditorPrivilegedPromiseClient.prototype.registerCert = 1137 | function(request, metadata) { 1138 | return this.client_.unaryCall(this.hostname_ + 1139 | '/rpc.AuditorPrivileged/RegisterCert', 1140 | request, 1141 | metadata || {}, 1142 | methodDescriptor_AuditorPrivileged_RegisterCert); 1143 | }; 1144 | 1145 | 1146 | /** 1147 | * @param {string} hostname 1148 | * @param {?Object} credentials 1149 | * @param {?grpc.web.ClientOptions} options 1150 | * @constructor 1151 | * @struct 1152 | * @final 1153 | */ 1154 | proto.rpc.ProofRegistryClient = 1155 | function(hostname, credentials, options) { 1156 | if (!options) options = {}; 1157 | options.format = 'text'; 1158 | 1159 | /** 1160 | * @private @const {!grpc.web.GrpcWebClientBase} The client 1161 | */ 1162 | this.client_ = new grpc.web.GrpcWebClientBase(options); 1163 | 1164 | /** 1165 | * @private @const {string} The hostname 1166 | */ 1167 | this.hostname_ = hostname; 1168 | 1169 | }; 1170 | 1171 | 1172 | /** 1173 | * @param {string} hostname 1174 | * @param {?Object} credentials 1175 | * @param {?grpc.web.ClientOptions} options 1176 | * @constructor 1177 | * @struct 1178 | * @final 1179 | */ 1180 | proto.rpc.ProofRegistryPromiseClient = 1181 | function(hostname, credentials, options) { 1182 | if (!options) options = {}; 1183 | options.format = 'text'; 1184 | 1185 | /** 1186 | * @private @const {!grpc.web.GrpcWebClientBase} The client 1187 | */ 1188 | this.client_ = new grpc.web.GrpcWebClientBase(options); 1189 | 1190 | /** 1191 | * @private @const {string} The hostname 1192 | */ 1193 | this.hostname_ = hostname; 1194 | 1195 | }; 1196 | 1197 | 1198 | /** 1199 | * @const 1200 | * @type {!grpc.web.MethodDescriptor< 1201 | * !proto.rpc.ProofsRegistrationRequest, 1202 | * !proto.google.protobuf.Empty>} 1203 | */ 1204 | const methodDescriptor_ProofRegistry_RegisterProofs = new grpc.web.MethodDescriptor( 1205 | '/rpc.ProofRegistry/RegisterProofs', 1206 | grpc.web.MethodType.UNARY, 1207 | proto.rpc.ProofsRegistrationRequest, 1208 | google_protobuf_empty_pb.Empty, 1209 | /** 1210 | * @param {!proto.rpc.ProofsRegistrationRequest} request 1211 | * @return {!Uint8Array} 1212 | */ 1213 | function(request) { 1214 | return request.serializeBinary(); 1215 | }, 1216 | google_protobuf_empty_pb.Empty.deserializeBinary 1217 | ); 1218 | 1219 | 1220 | /** 1221 | * @param {!proto.rpc.ProofsRegistrationRequest} request The 1222 | * request proto 1223 | * @param {?Object} metadata User defined 1224 | * call metadata 1225 | * @param {function(?grpc.web.RpcError, ?proto.google.protobuf.Empty)} 1226 | * callback The callback function(error, response) 1227 | * @return {!grpc.web.ClientReadableStream|undefined} 1228 | * The XHR Node Readable Stream 1229 | */ 1230 | proto.rpc.ProofRegistryClient.prototype.registerProofs = 1231 | function(request, metadata, callback) { 1232 | return this.client_.rpcCall(this.hostname_ + 1233 | '/rpc.ProofRegistry/RegisterProofs', 1234 | request, 1235 | metadata || {}, 1236 | methodDescriptor_ProofRegistry_RegisterProofs, 1237 | callback); 1238 | }; 1239 | 1240 | 1241 | /** 1242 | * @param {!proto.rpc.ProofsRegistrationRequest} request The 1243 | * request proto 1244 | * @param {?Object=} metadata User defined 1245 | * call metadata 1246 | * @return {!Promise} 1247 | * Promise that resolves to the response 1248 | */ 1249 | proto.rpc.ProofRegistryPromiseClient.prototype.registerProofs = 1250 | function(request, metadata) { 1251 | return this.client_.unaryCall(this.hostname_ + 1252 | '/rpc.ProofRegistry/RegisterProofs', 1253 | request, 1254 | metadata || {}, 1255 | methodDescriptor_ProofRegistry_RegisterProofs); 1256 | }; 1257 | 1258 | 1259 | /** 1260 | * @const 1261 | * @type {!grpc.web.MethodDescriptor< 1262 | * !proto.rpc.ProofRetrievalRequest, 1263 | * !proto.rpc.ProofRetrievalResponse>} 1264 | */ 1265 | const methodDescriptor_ProofRegistry_RetrieveProof = new grpc.web.MethodDescriptor( 1266 | '/rpc.ProofRegistry/RetrieveProof', 1267 | grpc.web.MethodType.UNARY, 1268 | proto.rpc.ProofRetrievalRequest, 1269 | proto.rpc.ProofRetrievalResponse, 1270 | /** 1271 | * @param {!proto.rpc.ProofRetrievalRequest} request 1272 | * @return {!Uint8Array} 1273 | */ 1274 | function(request) { 1275 | return request.serializeBinary(); 1276 | }, 1277 | proto.rpc.ProofRetrievalResponse.deserializeBinary 1278 | ); 1279 | 1280 | 1281 | /** 1282 | * @param {!proto.rpc.ProofRetrievalRequest} request The 1283 | * request proto 1284 | * @param {?Object} metadata User defined 1285 | * call metadata 1286 | * @param {function(?grpc.web.RpcError, ?proto.rpc.ProofRetrievalResponse)} 1287 | * callback The callback function(error, response) 1288 | * @return {!grpc.web.ClientReadableStream|undefined} 1289 | * The XHR Node Readable Stream 1290 | */ 1291 | proto.rpc.ProofRegistryClient.prototype.retrieveProof = 1292 | function(request, metadata, callback) { 1293 | return this.client_.rpcCall(this.hostname_ + 1294 | '/rpc.ProofRegistry/RetrieveProof', 1295 | request, 1296 | metadata || {}, 1297 | methodDescriptor_ProofRegistry_RetrieveProof, 1298 | callback); 1299 | }; 1300 | 1301 | 1302 | /** 1303 | * @param {!proto.rpc.ProofRetrievalRequest} request The 1304 | * request proto 1305 | * @param {?Object=} metadata User defined 1306 | * call metadata 1307 | * @return {!Promise} 1308 | * Promise that resolves to the response 1309 | */ 1310 | proto.rpc.ProofRegistryPromiseClient.prototype.retrieveProof = 1311 | function(request, metadata) { 1312 | return this.client_.unaryCall(this.hostname_ + 1313 | '/rpc.ProofRegistry/RetrieveProof', 1314 | request, 1315 | metadata || {}, 1316 | methodDescriptor_ProofRegistry_RetrieveProof); 1317 | }; 1318 | 1319 | 1320 | /** 1321 | * @param {string} hostname 1322 | * @param {?Object} credentials 1323 | * @param {?grpc.web.ClientOptions} options 1324 | * @constructor 1325 | * @struct 1326 | * @final 1327 | */ 1328 | proto.rpc.ProxyClient = 1329 | function(hostname, credentials, options) { 1330 | if (!options) options = {}; 1331 | options.format = 'text'; 1332 | 1333 | /** 1334 | * @private @const {!grpc.web.GrpcWebClientBase} The client 1335 | */ 1336 | this.client_ = new grpc.web.GrpcWebClientBase(options); 1337 | 1338 | /** 1339 | * @private @const {string} The hostname 1340 | */ 1341 | this.hostname_ = hostname; 1342 | 1343 | }; 1344 | 1345 | 1346 | /** 1347 | * @param {string} hostname 1348 | * @param {?Object} credentials 1349 | * @param {?grpc.web.ClientOptions} options 1350 | * @constructor 1351 | * @struct 1352 | * @final 1353 | */ 1354 | proto.rpc.ProxyPromiseClient = 1355 | function(hostname, credentials, options) { 1356 | if (!options) options = {}; 1357 | options.format = 'text'; 1358 | 1359 | /** 1360 | * @private @const {!grpc.web.GrpcWebClientBase} The client 1361 | */ 1362 | this.client_ = new grpc.web.GrpcWebClientBase(options); 1363 | 1364 | /** 1365 | * @private @const {string} The hostname 1366 | */ 1367 | this.hostname_ = hostname; 1368 | 1369 | }; 1370 | 1371 | 1372 | /** 1373 | * @const 1374 | * @type {!grpc.web.MethodDescriptor< 1375 | * !proto.rpc.CertificateRegistrationRequest, 1376 | * !proto.google.protobuf.Empty>} 1377 | */ 1378 | const methodDescriptor_Proxy_RegisterCert = new grpc.web.MethodDescriptor( 1379 | '/rpc.Proxy/RegisterCert', 1380 | grpc.web.MethodType.UNARY, 1381 | proto.rpc.CertificateRegistrationRequest, 1382 | google_protobuf_empty_pb.Empty, 1383 | /** 1384 | * @param {!proto.rpc.CertificateRegistrationRequest} request 1385 | * @return {!Uint8Array} 1386 | */ 1387 | function(request) { 1388 | return request.serializeBinary(); 1389 | }, 1390 | google_protobuf_empty_pb.Empty.deserializeBinary 1391 | ); 1392 | 1393 | 1394 | /** 1395 | * @param {!proto.rpc.CertificateRegistrationRequest} request The 1396 | * request proto 1397 | * @param {?Object} metadata User defined 1398 | * call metadata 1399 | * @param {function(?grpc.web.RpcError, ?proto.google.protobuf.Empty)} 1400 | * callback The callback function(error, response) 1401 | * @return {!grpc.web.ClientReadableStream|undefined} 1402 | * The XHR Node Readable Stream 1403 | */ 1404 | proto.rpc.ProxyClient.prototype.registerCert = 1405 | function(request, metadata, callback) { 1406 | return this.client_.rpcCall(this.hostname_ + 1407 | '/rpc.Proxy/RegisterCert', 1408 | request, 1409 | metadata || {}, 1410 | methodDescriptor_Proxy_RegisterCert, 1411 | callback); 1412 | }; 1413 | 1414 | 1415 | /** 1416 | * @param {!proto.rpc.CertificateRegistrationRequest} request The 1417 | * request proto 1418 | * @param {?Object=} metadata User defined 1419 | * call metadata 1420 | * @return {!Promise} 1421 | * Promise that resolves to the response 1422 | */ 1423 | proto.rpc.ProxyPromiseClient.prototype.registerCert = 1424 | function(request, metadata) { 1425 | return this.client_.unaryCall(this.hostname_ + 1426 | '/rpc.Proxy/RegisterCert', 1427 | request, 1428 | metadata || {}, 1429 | methodDescriptor_Proxy_RegisterCert); 1430 | }; 1431 | 1432 | 1433 | /** 1434 | * @const 1435 | * @type {!grpc.web.MethodDescriptor< 1436 | * !proto.rpc.ContractRegistrationRequest, 1437 | * !proto.google.protobuf.Empty>} 1438 | */ 1439 | const methodDescriptor_Proxy_RegisterContract = new grpc.web.MethodDescriptor( 1440 | '/rpc.Proxy/RegisterContract', 1441 | grpc.web.MethodType.UNARY, 1442 | proto.rpc.ContractRegistrationRequest, 1443 | google_protobuf_empty_pb.Empty, 1444 | /** 1445 | * @param {!proto.rpc.ContractRegistrationRequest} request 1446 | * @return {!Uint8Array} 1447 | */ 1448 | function(request) { 1449 | return request.serializeBinary(); 1450 | }, 1451 | google_protobuf_empty_pb.Empty.deserializeBinary 1452 | ); 1453 | 1454 | 1455 | /** 1456 | * @param {!proto.rpc.ContractRegistrationRequest} request The 1457 | * request proto 1458 | * @param {?Object} metadata User defined 1459 | * call metadata 1460 | * @param {function(?grpc.web.RpcError, ?proto.google.protobuf.Empty)} 1461 | * callback The callback function(error, response) 1462 | * @return {!grpc.web.ClientReadableStream|undefined} 1463 | * The XHR Node Readable Stream 1464 | */ 1465 | proto.rpc.ProxyClient.prototype.registerContract = 1466 | function(request, metadata, callback) { 1467 | return this.client_.rpcCall(this.hostname_ + 1468 | '/rpc.Proxy/RegisterContract', 1469 | request, 1470 | metadata || {}, 1471 | methodDescriptor_Proxy_RegisterContract, 1472 | callback); 1473 | }; 1474 | 1475 | 1476 | /** 1477 | * @param {!proto.rpc.ContractRegistrationRequest} request The 1478 | * request proto 1479 | * @param {?Object=} metadata User defined 1480 | * call metadata 1481 | * @return {!Promise} 1482 | * Promise that resolves to the response 1483 | */ 1484 | proto.rpc.ProxyPromiseClient.prototype.registerContract = 1485 | function(request, metadata) { 1486 | return this.client_.unaryCall(this.hostname_ + 1487 | '/rpc.Proxy/RegisterContract', 1488 | request, 1489 | metadata || {}, 1490 | methodDescriptor_Proxy_RegisterContract); 1491 | }; 1492 | 1493 | 1494 | /** 1495 | * @const 1496 | * @type {!grpc.web.MethodDescriptor< 1497 | * !proto.rpc.FunctionRegistrationRequest, 1498 | * !proto.google.protobuf.Empty>} 1499 | */ 1500 | const methodDescriptor_Proxy_RegisterFunction = new grpc.web.MethodDescriptor( 1501 | '/rpc.Proxy/RegisterFunction', 1502 | grpc.web.MethodType.UNARY, 1503 | proto.rpc.FunctionRegistrationRequest, 1504 | google_protobuf_empty_pb.Empty, 1505 | /** 1506 | * @param {!proto.rpc.FunctionRegistrationRequest} request 1507 | * @return {!Uint8Array} 1508 | */ 1509 | function(request) { 1510 | return request.serializeBinary(); 1511 | }, 1512 | google_protobuf_empty_pb.Empty.deserializeBinary 1513 | ); 1514 | 1515 | 1516 | /** 1517 | * @param {!proto.rpc.FunctionRegistrationRequest} request The 1518 | * request proto 1519 | * @param {?Object} metadata User defined 1520 | * call metadata 1521 | * @param {function(?grpc.web.RpcError, ?proto.google.protobuf.Empty)} 1522 | * callback The callback function(error, response) 1523 | * @return {!grpc.web.ClientReadableStream|undefined} 1524 | * The XHR Node Readable Stream 1525 | */ 1526 | proto.rpc.ProxyClient.prototype.registerFunction = 1527 | function(request, metadata, callback) { 1528 | return this.client_.rpcCall(this.hostname_ + 1529 | '/rpc.Proxy/RegisterFunction', 1530 | request, 1531 | metadata || {}, 1532 | methodDescriptor_Proxy_RegisterFunction, 1533 | callback); 1534 | }; 1535 | 1536 | 1537 | /** 1538 | * @param {!proto.rpc.FunctionRegistrationRequest} request The 1539 | * request proto 1540 | * @param {?Object=} metadata User defined 1541 | * call metadata 1542 | * @return {!Promise} 1543 | * Promise that resolves to the response 1544 | */ 1545 | proto.rpc.ProxyPromiseClient.prototype.registerFunction = 1546 | function(request, metadata) { 1547 | return this.client_.unaryCall(this.hostname_ + 1548 | '/rpc.Proxy/RegisterFunction', 1549 | request, 1550 | metadata || {}, 1551 | methodDescriptor_Proxy_RegisterFunction); 1552 | }; 1553 | 1554 | 1555 | /** 1556 | * @const 1557 | * @type {!grpc.web.MethodDescriptor< 1558 | * !proto.rpc.ContractExecutionRequest, 1559 | * !proto.rpc.ContractExecutionResponse>} 1560 | */ 1561 | const methodDescriptor_Proxy_ExecuteContract = new grpc.web.MethodDescriptor( 1562 | '/rpc.Proxy/ExecuteContract', 1563 | grpc.web.MethodType.UNARY, 1564 | proto.rpc.ContractExecutionRequest, 1565 | proto.rpc.ContractExecutionResponse, 1566 | /** 1567 | * @param {!proto.rpc.ContractExecutionRequest} request 1568 | * @return {!Uint8Array} 1569 | */ 1570 | function(request) { 1571 | return request.serializeBinary(); 1572 | }, 1573 | proto.rpc.ContractExecutionResponse.deserializeBinary 1574 | ); 1575 | 1576 | 1577 | /** 1578 | * @param {!proto.rpc.ContractExecutionRequest} request The 1579 | * request proto 1580 | * @param {?Object} metadata User defined 1581 | * call metadata 1582 | * @param {function(?grpc.web.RpcError, ?proto.rpc.ContractExecutionResponse)} 1583 | * callback The callback function(error, response) 1584 | * @return {!grpc.web.ClientReadableStream|undefined} 1585 | * The XHR Node Readable Stream 1586 | */ 1587 | proto.rpc.ProxyClient.prototype.executeContract = 1588 | function(request, metadata, callback) { 1589 | return this.client_.rpcCall(this.hostname_ + 1590 | '/rpc.Proxy/ExecuteContract', 1591 | request, 1592 | metadata || {}, 1593 | methodDescriptor_Proxy_ExecuteContract, 1594 | callback); 1595 | }; 1596 | 1597 | 1598 | /** 1599 | * @param {!proto.rpc.ContractExecutionRequest} request The 1600 | * request proto 1601 | * @param {?Object=} metadata User defined 1602 | * call metadata 1603 | * @return {!Promise} 1604 | * Promise that resolves to the response 1605 | */ 1606 | proto.rpc.ProxyPromiseClient.prototype.executeContract = 1607 | function(request, metadata) { 1608 | return this.client_.unaryCall(this.hostname_ + 1609 | '/rpc.Proxy/ExecuteContract', 1610 | request, 1611 | metadata || {}, 1612 | methodDescriptor_Proxy_ExecuteContract); 1613 | }; 1614 | 1615 | 1616 | /** 1617 | * @const 1618 | * @type {!grpc.web.MethodDescriptor< 1619 | * !proto.rpc.LedgersValidationRequest, 1620 | * !proto.rpc.LedgersValidationResponse>} 1621 | */ 1622 | const methodDescriptor_Proxy_ValidateLedgers = new grpc.web.MethodDescriptor( 1623 | '/rpc.Proxy/ValidateLedgers', 1624 | grpc.web.MethodType.UNARY, 1625 | proto.rpc.LedgersValidationRequest, 1626 | proto.rpc.LedgersValidationResponse, 1627 | /** 1628 | * @param {!proto.rpc.LedgersValidationRequest} request 1629 | * @return {!Uint8Array} 1630 | */ 1631 | function(request) { 1632 | return request.serializeBinary(); 1633 | }, 1634 | proto.rpc.LedgersValidationResponse.deserializeBinary 1635 | ); 1636 | 1637 | 1638 | /** 1639 | * @param {!proto.rpc.LedgersValidationRequest} request The 1640 | * request proto 1641 | * @param {?Object} metadata User defined 1642 | * call metadata 1643 | * @param {function(?grpc.web.RpcError, ?proto.rpc.LedgersValidationResponse)} 1644 | * callback The callback function(error, response) 1645 | * @return {!grpc.web.ClientReadableStream|undefined} 1646 | * The XHR Node Readable Stream 1647 | */ 1648 | proto.rpc.ProxyClient.prototype.validateLedgers = 1649 | function(request, metadata, callback) { 1650 | return this.client_.rpcCall(this.hostname_ + 1651 | '/rpc.Proxy/ValidateLedgers', 1652 | request, 1653 | metadata || {}, 1654 | methodDescriptor_Proxy_ValidateLedgers, 1655 | callback); 1656 | }; 1657 | 1658 | 1659 | /** 1660 | * @param {!proto.rpc.LedgersValidationRequest} request The 1661 | * request proto 1662 | * @param {?Object=} metadata User defined 1663 | * call metadata 1664 | * @return {!Promise} 1665 | * Promise that resolves to the response 1666 | */ 1667 | proto.rpc.ProxyPromiseClient.prototype.validateLedgers = 1668 | function(request, metadata) { 1669 | return this.client_.unaryCall(this.hostname_ + 1670 | '/rpc.Proxy/ValidateLedgers', 1671 | request, 1672 | metadata || {}, 1673 | methodDescriptor_Proxy_ValidateLedgers); 1674 | }; 1675 | 1676 | 1677 | /** 1678 | * @const 1679 | * @type {!grpc.web.MethodDescriptor< 1680 | * !proto.rpc.IdentifiableResponse, 1681 | * !proto.google.protobuf.Empty>} 1682 | */ 1683 | const methodDescriptor_Proxy_ProxyResponse = new grpc.web.MethodDescriptor( 1684 | '/rpc.Proxy/ProxyResponse', 1685 | grpc.web.MethodType.UNARY, 1686 | proto.rpc.IdentifiableResponse, 1687 | google_protobuf_empty_pb.Empty, 1688 | /** 1689 | * @param {!proto.rpc.IdentifiableResponse} request 1690 | * @return {!Uint8Array} 1691 | */ 1692 | function(request) { 1693 | return request.serializeBinary(); 1694 | }, 1695 | google_protobuf_empty_pb.Empty.deserializeBinary 1696 | ); 1697 | 1698 | 1699 | /** 1700 | * @param {!proto.rpc.IdentifiableResponse} request The 1701 | * request proto 1702 | * @param {?Object} metadata User defined 1703 | * call metadata 1704 | * @param {function(?grpc.web.RpcError, ?proto.google.protobuf.Empty)} 1705 | * callback The callback function(error, response) 1706 | * @return {!grpc.web.ClientReadableStream|undefined} 1707 | * The XHR Node Readable Stream 1708 | */ 1709 | proto.rpc.ProxyClient.prototype.proxyResponse = 1710 | function(request, metadata, callback) { 1711 | return this.client_.rpcCall(this.hostname_ + 1712 | '/rpc.Proxy/ProxyResponse', 1713 | request, 1714 | metadata || {}, 1715 | methodDescriptor_Proxy_ProxyResponse, 1716 | callback); 1717 | }; 1718 | 1719 | 1720 | /** 1721 | * @param {!proto.rpc.IdentifiableResponse} request The 1722 | * request proto 1723 | * @param {?Object=} metadata User defined 1724 | * call metadata 1725 | * @return {!Promise} 1726 | * Promise that resolves to the response 1727 | */ 1728 | proto.rpc.ProxyPromiseClient.prototype.proxyResponse = 1729 | function(request, metadata) { 1730 | return this.client_.unaryCall(this.hostname_ + 1731 | '/rpc.Proxy/ProxyResponse', 1732 | request, 1733 | metadata || {}, 1734 | methodDescriptor_Proxy_ProxyResponse); 1735 | }; 1736 | 1737 | 1738 | module.exports = proto.rpc; 1739 | 1740 | --------------------------------------------------------------------------------