├── lib ├── config.js ├── network │ ├── api.js │ └── http.js ├── crypto │ ├── hash.js │ ├── encryption.js │ ├── key.js │ ├── tools.js │ ├── account.js │ └── protocol.js ├── common │ ├── errors.js │ ├── serialize.js │ └── math.js ├── transaction │ ├── transaction.js │ └── payload.js ├── wallet.js └── pb │ └── transaction_pb.js ├── Gruntfile.js ├── package.json ├── examples └── node_example.js ├── .gitignore ├── README.md └── LICENSE /lib/config.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | rpcAddr: 'https://mainnet-rpc-node-0001.nkn.org/mainnet/api/wallet', 5 | } 6 | -------------------------------------------------------------------------------- /lib/network/api.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | let baseInfo = function () { 4 | return {"jsonrpc":"2.0", "id":"nkn-wallet"} 5 | } 6 | 7 | module.exports = { 8 | getBalanceByAddr: Object.assign(baseInfo(), {method: "getbalancebyaddr", params: {address: ""}}), 9 | getNonceByAddr: Object.assign(baseInfo(), {method: "getnoncebyaddr", params: {address: ""}}), 10 | sendRawTransaction: Object.assign(baseInfo(), {method: "sendrawtransaction", params: {tx: ""}}), 11 | getAddressByName: Object.assign(baseInfo(), {method: "getaddressbyname", params: {name: ""}}), 12 | getBlockCount: Object.assign(baseInfo(), {method: "getblockcount", params: {name: ""}}), 13 | } 14 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function(grunt) { 2 | grunt.initConfig({ 3 | pkg: grunt.file.readJSON('package.json'), 4 | browserify: { 5 | dist: { 6 | files: { 7 | 'dist/nkn-wallet.js': [ 'lib/wallet.js' ] 8 | }, 9 | options: { 10 | exclude: ['crypto'], 11 | browserifyOptions: { 12 | standalone: 'nkn-wallet' 13 | } 14 | } 15 | } 16 | }, 17 | uglify: { 18 | options: { 19 | sourceMap: true, 20 | sourceMapIncludeSources: true, 21 | sourceMapName: 'dist/nkn-wallet.min.js.map' 22 | }, 23 | dist: { 24 | files: { 25 | 'dist/nkn-wallet.min.js' : [ 'dist/nkn-wallet.js' ] 26 | } 27 | } 28 | } 29 | }); 30 | 31 | grunt.loadNpmTasks('grunt-browserify'); 32 | grunt.loadNpmTasks('grunt-contrib-uglify-es'); 33 | 34 | grunt.registerTask('dist', ['browserify', 'uglify']); 35 | }; 36 | -------------------------------------------------------------------------------- /lib/crypto/hash.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const CryptoJS = require('crypto-js'); 4 | 5 | function cryptoHexStringParse(hexString) { 6 | return CryptoJS.enc.Hex.parse(hexString) 7 | } 8 | 9 | function sha256(str) { 10 | return CryptoJS.SHA256(str).toString(); 11 | } 12 | 13 | function sha256Hex(hexStr) { 14 | return sha256(cryptoHexStringParse(hexStr)); 15 | } 16 | 17 | function doubleSha256(str) { 18 | return CryptoJS.SHA256(CryptoJS.SHA256(str)).toString(); 19 | } 20 | 21 | function doubleSha256Hex(hexStr) { 22 | return CryptoJS.SHA256(CryptoJS.SHA256(cryptoHexStringParse(hexStr))).toString(); 23 | } 24 | 25 | function ripemd160(str) { 26 | return CryptoJS.RIPEMD160(str).toString(); 27 | } 28 | 29 | function ripemd160Hex(hexStr) { 30 | return CryptoJS.RIPEMD160(cryptoHexStringParse(hexStr)).toString(); 31 | } 32 | 33 | module.exports = { 34 | sha256, 35 | sha256Hex, 36 | doubleSha256, 37 | doubleSha256Hex, 38 | ripemd160, 39 | ripemd160Hex, 40 | cryptoHexStringParse, 41 | } 42 | -------------------------------------------------------------------------------- /lib/common/errors.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const errorCode = { 4 | unknownError: 0, 5 | notEnoughBalance: 1, 6 | invalidAddress: 2, 7 | wrongPassword: 3, 8 | invalidWalletFormat: 4, 9 | invalidWalletVersion: 5, 10 | invalidArgument: 6, 11 | invalidResponse: 7, 12 | noRPCServer: 8, 13 | serverError: 9, 14 | }; 15 | 16 | const defaultErrorMsg = { 17 | [errorCode.unknownError]: 'unknown error', 18 | [errorCode.notEnoughBalance]: 'not enough balance', 19 | [errorCode.invalidWalletAddress]: 'invalid wallet address', 20 | [errorCode.wrongPassword]: 'invalid password', 21 | [errorCode.invalidWalletFormat]: 'invalid wallet format', 22 | [errorCode.invalidWalletVersion]: 'invalid wallet verison', 23 | [errorCode.invalidArgument]: 'invalid argument', 24 | [errorCode.invalidResponse]: 'invalid response from server', 25 | [errorCode.noRPCServer]: 'RPC server address is not set', 26 | [errorCode.serverError]: 'error from server', 27 | }; 28 | 29 | function Error(code, msg) { 30 | if (!(this instanceof Error)) { 31 | return new Error(code, msg); 32 | } 33 | 34 | this.code = code || errorCode.unknownError; 35 | this.msg = msg || defaultErrorMsg[code] || defaultErrorMsg.unknownError; 36 | } 37 | 38 | module.exports = { 39 | code: errorCode, 40 | Error, 41 | } 42 | -------------------------------------------------------------------------------- /lib/crypto/encryption.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const CryptoJS = require('crypto-js'); 4 | const nacl = require('tweetnacl'); 5 | 6 | const hash = require('./hash'); 7 | const tools = require('./tools'); 8 | 9 | function genAESIV() { 10 | return tools.randomBytesHex(16) 11 | } 12 | 13 | function genAESPassword() { 14 | return tools.randomBytesHex(32) 15 | } 16 | 17 | function encrypt(plaintext, password, iv, isSimplePassword = false) { 18 | password = isSimplePassword ? hash.doubleSha256(password) : password 19 | 20 | return CryptoJS.AES.encrypt( 21 | plaintext, 22 | hash.cryptoHexStringParse(password), 23 | { 24 | iv: hash.cryptoHexStringParse(iv), 25 | mode: CryptoJS.mode.CBC, 26 | padding: CryptoJS.pad.NoPadding 27 | } 28 | ).ciphertext.toString(CryptoJS.enc.Hex) 29 | } 30 | 31 | function decrypt(ciphertext, password, iv, isSimplePassword = false) { 32 | password = isSimplePassword ? hash.doubleSha256(password) : password 33 | 34 | return CryptoJS.AES.decrypt( 35 | CryptoJS.enc.Base64.stringify(ciphertext), 36 | hash.cryptoHexStringParse(password), 37 | { 38 | iv: hash.cryptoHexStringParse(iv), 39 | mode: CryptoJS.mode.CBC, 40 | padding: CryptoJS.pad.NoPadding 41 | } 42 | ).toString() 43 | } 44 | 45 | module.exports = { 46 | encrypt, 47 | decrypt, 48 | genAESIV, 49 | genAESPassword, 50 | } 51 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nkn-wallet", 3 | "version": "0.4.9", 4 | "description": "nkn wallet sdk", 5 | "main": "lib/wallet.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/nknorg/nkn-wallet-js.git" 12 | }, 13 | "keywords": [ 14 | "NKN", 15 | "blockchain", 16 | "wallet", 17 | "js", 18 | "sdk" 19 | ], 20 | "author": "NKN", 21 | "license": "Apache-2.0", 22 | "bugs": { 23 | "url": "https://github.com/nknorg/nkn-wallet-js/issues" 24 | }, 25 | "homepage": "https://nkn.org", 26 | "browserify": { 27 | "transform": [ 28 | [ 29 | "browserify-replace", 30 | { 31 | "replace": [ 32 | { 33 | "from": "var global = Function\\('return this'\\)\\(\\);", 34 | "to": "var global = (function(){ return this }).call(null);" 35 | } 36 | ] 37 | } 38 | ] 39 | ] 40 | }, 41 | "dependencies": { 42 | "axios": ">=0.18.1", 43 | "base-x": "3.0.4", 44 | "buffer": "^5.2.1", 45 | "crypto-js": "3.1.9-1", 46 | "decimal.js": "10.0.1", 47 | "es6-promise": "4.2.4", 48 | "google-protobuf": "^3.7.1", 49 | "is": "3.2.1", 50 | "tweetnacl": "^1.0.1" 51 | }, 52 | "devDependencies": { 53 | "browserify-replace": "^1.0.0", 54 | "grunt": "^1.0.2", 55 | "grunt-browserify": "^5.3.0", 56 | "grunt-contrib-uglify-es": "^3.3.0", 57 | "uglify-js": "^3.3.24" 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /lib/crypto/key.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const nacl = require('tweetnacl');; 4 | const is = require('is'); 5 | 6 | const protocol = require('./protocol'); 7 | const tools = require('./tools'); 8 | const errors = require('../common/errors'); 9 | 10 | let Key = function (seed) { 11 | this.sign = function (message) { 12 | let sig = nacl.sign.detached(message, this.key.secretKey); 13 | return tools.paddingSignature(tools.bytesToHex(sig), nacl.sign.signatureLength) 14 | } 15 | 16 | if(is.string(seed)) { 17 | let seedBytes 18 | try { 19 | seedBytes = tools.hexToBytes(seed); 20 | } catch (e) { 21 | throw errors.Error(errors.code.invalidArgument, 'seed is not a valid hex string') 22 | } 23 | setKeyPair.call(this, seedBytes); 24 | } else { 25 | setKeyPair.call(this, tools.randomBytes(nacl.sign.seedLength)); 26 | } 27 | } 28 | 29 | function setKeyPair(seed) { 30 | let key = nacl.sign.keyPair.fromSeed(seed); 31 | this.key = key; 32 | this.publicKey = tools.bytesToHex(key.publicKey); 33 | this.privateKey = tools.bytesToHex(key.secretKey); 34 | this.seed = tools.bytesToHex(seed); 35 | this.signatureRedeem = protocol.publicKeyToSignatureRedeem(this.publicKey); 36 | this.programHash = protocol.hexStringToProgramHash(this.signatureRedeem); 37 | return key; 38 | } 39 | 40 | function newKey() { 41 | return new Key() 42 | } 43 | 44 | function restoreKey(seed) { 45 | if(!is.string(seed)) { 46 | throw errors.Error(errors.code.invalidArgument, 'seed is not a string') 47 | } 48 | return new Key(seed) 49 | } 50 | 51 | module.exports = { 52 | newKey, 53 | restoreKey, 54 | } 55 | -------------------------------------------------------------------------------- /lib/common/serialize.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const errors = require('./errors'); 4 | 5 | const maxUintBits = 48; 6 | const maxUint = 2**maxUintBits; 7 | 8 | function encodeUint8(value) { 9 | let buf = Buffer.alloc(1, 0); 10 | buf.writeUInt8(value); 11 | return buf.toString('hex'); 12 | } 13 | 14 | function encodeUint16(value) { 15 | let buf = Buffer.alloc(2, 0); 16 | buf.writeUInt16LE(value); 17 | return buf.toString('hex'); 18 | } 19 | 20 | function encodeUint32(value) { 21 | let buf = Buffer.alloc(4, 0); 22 | buf.writeUInt32LE(value); 23 | return buf.toString('hex'); 24 | } 25 | 26 | function encodeUint64(value) { 27 | if (value > maxUint) { 28 | throw errors.Error(errors.code.invalidArgument, 'value out of range: full 64 bit integer is not supported in JavaScript') 29 | } 30 | let buf = Buffer.alloc(8, 0); 31 | buf.writeUIntLE(value, 0, 6); 32 | return buf.toString('hex'); 33 | } 34 | 35 | function encodeUint(value) { 36 | if (value < 0xfd) { 37 | return encodeUint8(value); 38 | } else if (value <= 0xffff) { 39 | return 'fd' + encodeUint16(value); 40 | } else if (value <= 0xffffffff) { 41 | return 'fe' + encodeUint32(value); 42 | } else { 43 | return 'ff' + encodeUint64(value); 44 | } 45 | } 46 | 47 | function encodeBytes(value) { 48 | let buf = Buffer.from(value); 49 | return encodeUint(buf.length) + buf.toString('hex'); 50 | } 51 | 52 | function encodeString(value) { 53 | let buf = Buffer.from(value, 'utf8'); 54 | return encodeUint(buf.length) + buf.toString('hex'); 55 | } 56 | 57 | module.exports = { 58 | maxUintBits, 59 | maxUint, 60 | encodeUint8, 61 | encodeUint16, 62 | encodeUint32, 63 | encodeUint64, 64 | encodeUint, 65 | encodeBytes, 66 | encodeString, 67 | } 68 | -------------------------------------------------------------------------------- /lib/transaction/transaction.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const hash = require('../crypto/hash'); 4 | const payload = require('./payload'); 5 | const protocol = require('../crypto/protocol'); 6 | const nknMath = require('../common/math'); 7 | const serialize = require('../common/serialize'); 8 | const transaction = require('../pb/transaction_pb'); 9 | 10 | function newTransaction(account, pld, nonce, fee = 0, attrs = '') { 11 | fee = nknMath.mulAndFloor(nknMath.newNum(fee), nknMath.NKN_ACC_MUL); 12 | 13 | let unsignedTx = new transaction.UnsignedTx(); 14 | unsignedTx.setPayload(pld); 15 | unsignedTx.setNonce(nonce); 16 | unsignedTx.setFee(fee); 17 | unsignedTx.setAttributes(Buffer.from(attrs, 'hex')); 18 | 19 | let txn = new transaction.Transaction(); 20 | txn.setUnsignedTx(unsignedTx); 21 | signTx(account, txn); 22 | 23 | return txn; 24 | } 25 | 26 | function serializeUnsignedTx(unsignedTx) { 27 | let hex = ''; 28 | hex += payload.serialize(unsignedTx.getPayload()) 29 | hex += serialize.encodeUint64(unsignedTx.getNonce()); 30 | hex += serialize.encodeUint64(unsignedTx.getFee()); 31 | hex += serialize.encodeBytes(unsignedTx.getAttributes()); 32 | return hex; 33 | } 34 | 35 | function signTx(account, txn) { 36 | let unsignedTx = txn.getUnsignedTx(); 37 | let hex = serializeUnsignedTx(unsignedTx); 38 | let digest = hash.sha256Hex(hex); 39 | let signature = account.getKey().sign(Buffer.from(digest, 'hex')); 40 | 41 | txn.hash = hash.doubleSha256Hex(hex); 42 | 43 | let prgm = new transaction.Program(); 44 | prgm.setCode(Buffer.from(account.getSignatureRedeem(), 'hex')); 45 | prgm.setParameter(Buffer.from(protocol.signatureToParameter(signature), 'hex')); 46 | 47 | txn.setProgramsList([prgm]); 48 | } 49 | 50 | module.exports = { 51 | newTransaction, 52 | } 53 | -------------------------------------------------------------------------------- /lib/crypto/tools.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const nacl = require('tweetnacl'); 4 | const maxUintBits = require('../common/serialize').maxUintBits; 5 | 6 | function prefixByteCountToHexString(hexString) { 7 | let len = hexString.length 8 | if(0 === len) { 9 | return '00' 10 | } 11 | 12 | if(1 === len%2) { 13 | hexString = '0' + hexString 14 | len += 1 15 | } 16 | 17 | let byteCount = len / 2 18 | 19 | byteCount = byteCount.toString(16) 20 | if(1 === byteCount.length % 2) { 21 | byteCount = '0' + byteCount 22 | } 23 | 24 | return byteCount + hexString 25 | } 26 | 27 | function hexToBytes(hex) { 28 | for (var bytes = [], c = 0; c < hex.length; c += 2) { 29 | bytes.push(parseInt(hex.substr(c, 2), 16)); 30 | } 31 | return new Uint8Array(bytes); 32 | } 33 | 34 | function bytesToHex(bytes) { 35 | return Array.from(bytes, function(byte) { 36 | return ('0' + (byte & 0xFF).toString(16)).slice(-2) 37 | }).join(''); 38 | } 39 | 40 | function paddingSignature(data, len) { 41 | for(let i = 0; i < len - data.length; i++){ 42 | data = '0' + data 43 | } 44 | return data 45 | } 46 | 47 | var randomBytes; 48 | if (typeof navigator != 'undefined' && navigator.product === "ReactNative") { 49 | randomBytes = require('crypto').randomBytes; 50 | } else { 51 | randomBytes = nacl.randomBytes; 52 | } 53 | 54 | function randomBytesHex(len) { 55 | return bytesToHex(randomBytes(len)); 56 | } 57 | 58 | function randomUint64() { 59 | let hex = randomBytesHex(maxUintBits/8); 60 | return parseInt(hex, 16); 61 | } 62 | 63 | function mergeTypedArrays(a, b) { 64 | var c = new a.constructor(a.length + b.length); 65 | c.set(a); 66 | c.set(b, a.length); 67 | return c; 68 | } 69 | 70 | module.exports = { 71 | prefixByteCountToHexString, 72 | hexToBytes, 73 | bytesToHex, 74 | paddingSignature, 75 | randomBytes, 76 | randomBytesHex, 77 | randomUint64, 78 | mergeTypedArrays, 79 | } 80 | -------------------------------------------------------------------------------- /lib/crypto/account.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const is = require('is'); 4 | 5 | const { newKey, restoreKey } = require('./key'); 6 | const protocol = require('./protocol'); 7 | const tools = require('./tools'); 8 | const errors = require('../common/errors'); 9 | 10 | function genAccountContractString(signatureRedeem, programHash) { 11 | let contract = '' 12 | 13 | contract += tools.prefixByteCountToHexString(signatureRedeem) 14 | contract += tools.prefixByteCountToHexString('00') 15 | contract += programHash 16 | 17 | return contract 18 | } 19 | 20 | /*** 21 | * 22 | * @param seed 23 | * @returns {*} 24 | */ 25 | let account = function (seed) { 26 | let key = null 27 | if(is.string(seed)) { 28 | key = restoreKey(seed) 29 | } else { 30 | key = newKey() 31 | } 32 | 33 | let address = protocol.programHashStringToAddress(key.programHash) 34 | let contract = genAccountContractString(key.signatureRedeem, key.programHash) 35 | 36 | this.getAddress = function () { 37 | return address 38 | } 39 | 40 | this.getKey = function () { 41 | return key 42 | } 43 | 44 | this.getPublicKey = function () { 45 | return key.publicKey 46 | } 47 | 48 | this.getPrivateKey = function () { 49 | return key.privateKey 50 | } 51 | 52 | this.getSeed = function () { 53 | return key.seed 54 | } 55 | 56 | this.getProgramHash = function () { 57 | return key.programHash 58 | } 59 | 60 | this.getSignatureRedeem = function () { 61 | return key.signatureRedeem 62 | } 63 | 64 | this.getContractString = function () { 65 | return contract 66 | } 67 | } 68 | 69 | function newAccount() { 70 | return new account() 71 | } 72 | 73 | function restoreAccount(seed) { 74 | if(!is.string(seed)) { 75 | throw errors.Error(errors.code.invalidArgument, 'seed is not a string') 76 | } 77 | 78 | return new account(seed) 79 | } 80 | 81 | module.exports = { 82 | newAccount, 83 | restoreAccount 84 | } 85 | -------------------------------------------------------------------------------- /lib/network/http.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | require('es6-promise/auto'); 4 | const axios = require('axios') 5 | const is = require('is') 6 | const api = require('./api') 7 | const errors = require('../common/errors'); 8 | 9 | let serverAddr = null 10 | 11 | async function axiosRequest(param) { 12 | if(!serverAddr) { 13 | throw errors.Error(errors.code.noRPCServer) 14 | } 15 | 16 | let response = await axios.post(serverAddr, JSON.stringify(param), { 17 | headers: { 'Content-Type': 'text/plain' } 18 | }) 19 | 20 | if(!is.undefined(response.data.result)) { 21 | return response.data.result 22 | } 23 | 24 | if(!is.undefined(response.data.error)) { 25 | throw errors.Error(errors.code.serverError, response.data.error) 26 | } 27 | 28 | throw errors.Error(errors.code.invalidResponse) 29 | } 30 | 31 | function configure(addr) { 32 | serverAddr = addr 33 | } 34 | 35 | function getBalanceByAddr(address, callId) { 36 | let getBalanceByAddrApi = api.getBalanceByAddr 37 | getBalanceByAddrApi.params.address = address 38 | if(!is.undefined(callId)) { 39 | getBalanceByAddrApi.id = callId 40 | } 41 | 42 | return axiosRequest(getBalanceByAddrApi) 43 | } 44 | 45 | function getNonceByAddr(address, callId) { 46 | let getNonceByAddrApi = api.getNonceByAddr 47 | getNonceByAddrApi.params.address = address 48 | if(!is.undefined(callId)) { 49 | getNonceByAddrApi.id = callId 50 | } 51 | 52 | return axiosRequest(getNonceByAddrApi) 53 | } 54 | 55 | function sendRawTransaction(tx, callId) { 56 | let sendRawTransactionApi = api.sendRawTransaction 57 | sendRawTransactionApi.params.tx = tx 58 | if(!is.undefined(callId)) { 59 | sendRawTransactionApi.id = callId 60 | } 61 | 62 | return axiosRequest(sendRawTransactionApi) 63 | } 64 | 65 | function getAddressByName(name, callId) { 66 | let getAddressByNameApi = api.getAddressByName 67 | getAddressByNameApi.params.name = name 68 | if(!is.undefined(callId)) { 69 | getAddressByNameApi.id = callId 70 | } 71 | 72 | return axiosRequest(getAddressByNameApi) 73 | } 74 | 75 | function getBlockCount(callId) { 76 | let getBlockCountApi = api.getBlockCount 77 | if(!is.undefined(callId)) { 78 | getBlockCountApi.id = callId 79 | } 80 | 81 | return axiosRequest(getBlockCountApi) 82 | } 83 | 84 | module.exports = { 85 | configure, 86 | getBalanceByAddr, 87 | getNonceByAddr, 88 | sendRawTransaction, 89 | getAddressByName, 90 | getBlockCount, 91 | } 92 | -------------------------------------------------------------------------------- /lib/common/math.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const Decimal = require('decimal.js') 4 | 5 | let NKN_ACC_MUL = newNum(100000000) 6 | 7 | function newNum(arg) { 8 | return new Decimal(arg) 9 | } 10 | 11 | /*** 12 | * 13 | * @param arg1 14 | * @param arg2 15 | * @returns {Decimal} 16 | */ 17 | function add(arg1, arg2) { 18 | return Decimal.add(arg1, arg2) 19 | } 20 | 21 | /*** 22 | * 23 | * @param arg1 24 | * @param arg2 25 | * @returns {Decimal} 26 | */ 27 | function sub(arg1, arg2) { 28 | return Decimal.sub(arg1, arg2) 29 | } 30 | 31 | /*** 32 | * 33 | * @param arg1 34 | * @param arg2 35 | * @returns {Decimal} 36 | */ 37 | function mul(arg1, arg2) { 38 | return Decimal.mul(arg1, arg2) 39 | } 40 | 41 | function mulAndFloor(arg1, arg2) { 42 | return Decimal.mul(arg1, arg2).floor() 43 | } 44 | 45 | /*** 46 | * 47 | * @param arg1 48 | * @param arg2 49 | * @returns {Decimal} 50 | */ 51 | function div(arg1, arg2) { 52 | return Decimal.div(arg1, arg2) 53 | } 54 | 55 | /*** 56 | * 57 | * @param arg1 58 | * @param arg2 59 | * @returns {boolean} 60 | */ 61 | function eq(arg1, arg2) { 62 | return new Decimal(arg1).eq(arg2) 63 | } 64 | 65 | /** 66 | * 67 | * @param base 68 | * @param target 69 | * @returns {boolean} 70 | */ 71 | function greaterThan(base, target) { 72 | return new Decimal(base).greaterThan(target) 73 | } 74 | 75 | /** 76 | * 77 | * @param base 78 | * @param target 79 | * @returns {boolean} 80 | */ 81 | function greaterThanOrEqualTo(base, target) { 82 | return new Decimal(base).greaterThanOrEqualTo(target) 83 | } 84 | 85 | /** 86 | * 87 | * @param base 88 | * @param target 89 | * @returns {boolean} 90 | */ 91 | function lessThan(base, target) { 92 | return new Decimal(base).lessThan(target) 93 | } 94 | 95 | /*** 96 | * 97 | * @param base 98 | * @param target 99 | * @returns {boolean} 100 | */ 101 | function lessThanOrEqualTo(base, target) { 102 | return new Decimal(base).lessThanOrEqualTo(target) 103 | } 104 | 105 | /*** 106 | * 107 | * @param arg 108 | * @returns {string} 109 | */ 110 | function int2HexString(arg) { 111 | let hexString = new Decimal(arg).floor().toHexadecimal().toString().substring(2) 112 | 113 | if(1 === hexString.length % 2) { 114 | hexString = '0' + hexString 115 | } 116 | 117 | return hexString 118 | } 119 | 120 | /*** 121 | * 122 | * @param arg 123 | * @returns {*} 124 | */ 125 | function hexString2Int(arg) { 126 | return ('0x' === arg.slice(0, 2)) ? new Decimal(arg) : new Decimal("0x" + arg) 127 | } 128 | 129 | module.exports = { 130 | newNum, 131 | 132 | add, 133 | sub, 134 | mul, 135 | div, 136 | 137 | mulAndFloor, 138 | 139 | eq, 140 | greaterThan, 141 | greaterThanOrEqualTo, 142 | lessThan, 143 | lessThanOrEqualTo, 144 | 145 | int2HexString, 146 | hexString2Int, 147 | 148 | NKN_ACC_MUL, 149 | } 150 | -------------------------------------------------------------------------------- /examples/node_example.js: -------------------------------------------------------------------------------- 1 | const nknWallet = require('../lib/wallet'); 2 | 3 | // Uncomment this if you want to use customized rpc node 4 | // nknWallet.configure({ 5 | // rpcAddr: 'http://127.0.0.1:30003' 6 | // }) 7 | 8 | // Create a new wallet 9 | const wallet = nknWallet.newWallet('pswd'); 10 | 11 | // Get wallet's json string 12 | const walletJson = wallet.toJSON(); 13 | 14 | // Load wallet from a wallet json string 15 | const walletFromJson = nknWallet.loadJsonWallet(walletJson, 'pswd'); 16 | 17 | // Restore wallet from a private key 18 | const walletFromSeed = nknWallet.restoreWalletBySeed(wallet.getSeed(), 'new-wallet-password'); 19 | 20 | // Verify whether an address is valid 21 | console.log(nknWallet.verifyAddress(wallet.address)); 22 | 23 | // Verify password of the wallet 24 | console.log(wallet.verifyPassword('pswd')); 25 | 26 | // Get balance of this wallet 27 | wallet.getBalance().then(function(value) { 28 | console.log('Balance for this wallet is:', value.toString()); 29 | }).catch(function(error) { 30 | console.log('Get balance fail:', error); 31 | }); 32 | 33 | // Transfer token to some address 34 | // This call will fail because a new account has no balance 35 | wallet.transferTo(wallet.address, 1).then(function(data) { 36 | console.log('Transfer success:', data); 37 | }).catch(function(error) { 38 | console.log('Transfer fail:', error); 39 | }); 40 | 41 | // Register name for this wallet 42 | wallet.registerName('somename').then(function(data) { 43 | console.log('Register name success:', data); 44 | }).catch(function(error) { 45 | console.log('Register name fail:', error); 46 | }); 47 | 48 | // Delete name for this wallet 49 | // This call will fail because a new account has no name 50 | wallet.deleteName('somename').then(function(data) { 51 | console.log('Delete name success:', data); 52 | }).catch(function(error) { 53 | console.log('Delete name fail:', error); 54 | }); 55 | 56 | // Get wallet address of a name 57 | // This call will likely to fail because we need to wait a block till name registration is completed 58 | wallet.getAddressByName('somename').then(function(data) { 59 | console.log('Get address by name success:', data); 60 | }).catch(function(error) { 61 | console.log('Get address by name fail:', error); 62 | }); 63 | 64 | // Subscribe to a topic for this wallet for next 10 blocks 65 | wallet.subscribe('topic', 10, 'identifier').then(function(data) { 66 | console.log('Subscribe success:', data); 67 | }).catch(function(error) { 68 | console.log('Subscribe fail:', error); 69 | }); 70 | 71 | // Unsubscribe to a topic 72 | wallet.unsubscribe('topic', 'identifier').then(function(data) { 73 | console.log('Unsubscribe success:', data); 74 | }).catch(function(error) { 75 | console.log('Unsubscribe fail:', error); 76 | }); 77 | 78 | // Get nonce for next transaction of this wallet 79 | wallet.getNonce().then(function(value) { 80 | console.log('Nonce for this wallet is:', value); 81 | }).catch(function(error) { 82 | console.log('Get nonce fail:', error); 83 | }); 84 | -------------------------------------------------------------------------------- /lib/transaction/payload.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const nknMath = require('../common/math'); 4 | const protocol = require('../crypto/protocol'); 5 | const serialize = require('../common/serialize'); 6 | const tools = require('../crypto/tools'); 7 | const transaction = require('../pb/transaction_pb'); 8 | 9 | function newTransfer(sender, recipient, amount) { 10 | amount = nknMath.mulAndFloor(nknMath.newNum(amount), nknMath.NKN_ACC_MUL); 11 | 12 | let transfer = new transaction.TransferAsset(); 13 | transfer.setSender(Buffer.from(sender, 'hex')); 14 | transfer.setRecipient(Buffer.from(recipient, 'hex')); 15 | transfer.setAmount(amount); 16 | 17 | let pld = new transaction.Payload(); 18 | pld.setType(transaction.PayloadType.TRANSFER_ASSET_TYPE); 19 | pld.setData(transfer.serializeBinary()); 20 | 21 | return pld; 22 | } 23 | 24 | function newRegisterName(publicKey, name) { 25 | let registerName = new transaction.RegisterName(); 26 | registerName.setRegistrant(Buffer.from(publicKey, 'hex')); 27 | registerName.setName(name); 28 | 29 | let pld = new transaction.Payload(); 30 | pld.setType(transaction.PayloadType.REGISTER_NAME_TYPE); 31 | pld.setData(registerName.serializeBinary()); 32 | 33 | return pld; 34 | } 35 | 36 | function newDeleteName(publicKey, name) { 37 | let deleteName = new transaction.DeleteName(); 38 | deleteName.setRegistrant(Buffer.from(publicKey, 'hex')); 39 | deleteName.setName(name); 40 | 41 | let pld = new transaction.Payload(); 42 | pld.setType(transaction.PayloadType.DELETE_NAME_TYPE); 43 | pld.setData(deleteName.serializeBinary()); 44 | 45 | return pld; 46 | } 47 | 48 | function newSubscribe(subscriber, identifier, topic, duration, meta) { 49 | let subscribe = new transaction.Subscribe(); 50 | subscribe.setSubscriber(Buffer.from(subscriber, 'hex')); 51 | subscribe.setIdentifier(identifier); 52 | subscribe.setTopic(topic); 53 | subscribe.setDuration(duration); 54 | subscribe.setMeta(meta); 55 | 56 | let pld = new transaction.Payload(); 57 | pld.setType(transaction.PayloadType.SUBSCRIBE_TYPE); 58 | pld.setData(subscribe.serializeBinary()); 59 | 60 | return pld; 61 | } 62 | 63 | function newUnsubscribe(subscriber, identifier, topic) { 64 | let unsubscribe = new transaction.Unsubscribe(); 65 | unsubscribe.setSubscriber(Buffer.from(subscriber, 'hex')); 66 | unsubscribe.setIdentifier(identifier); 67 | unsubscribe.setTopic(topic); 68 | 69 | let pld = new transaction.Payload(); 70 | pld.setType(transaction.PayloadType.UNSUBSCRIBE_TYPE); 71 | pld.setData(unsubscribe.serializeBinary()); 72 | 73 | return pld; 74 | } 75 | 76 | function newNanoPay(sender, recipient, id, amount, txnExpiration, nanoPayExpiration) { 77 | amount = nknMath.mulAndFloor(nknMath.newNum(amount), nknMath.NKN_ACC_MUL); 78 | 79 | let nanoPay = new transaction.NanoPay(); 80 | nanoPay.setSender(Buffer.from(sender, 'hex')); 81 | nanoPay.setRecipient(Buffer.from(recipient, 'hex')); 82 | nanoPay.setId(id); 83 | nanoPay.setAmount(amount); 84 | nanoPay.setTxnExpiration(txnExpiration); 85 | nanoPay.setNanoPayExpiration(nanoPayExpiration); 86 | 87 | let pld = new transaction.Payload(); 88 | pld.setType(transaction.PayloadType.NANO_PAY_TYPE); 89 | pld.setData(nanoPay.serializeBinary()); 90 | 91 | return pld; 92 | } 93 | 94 | function serializePayload(payload) { 95 | let hex = ''; 96 | hex += serialize.encodeUint32(payload.getType()); 97 | hex += serialize.encodeBytes(payload.getData()); 98 | return hex; 99 | } 100 | 101 | module.exports = { 102 | newTransfer, 103 | newRegisterName, 104 | newDeleteName, 105 | newSubscribe, 106 | newUnsubscribe, 107 | newNanoPay, 108 | serialize: serializePayload, 109 | } 110 | -------------------------------------------------------------------------------- /lib/crypto/protocol.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const BITCOIN_BASE58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'; 4 | const base58 = require('base-x')(BITCOIN_BASE58); 5 | const CryptoJS = require('crypto-js'); 6 | 7 | const hash = require('./hash'); 8 | const tools = require('./tools'); 9 | 10 | const ADDRESS_GEN_PREFIX = '02b825'; 11 | const ADDRESS_GEN_PREFIX_LEN = ADDRESS_GEN_PREFIX.length / 2; 12 | const UINT160_LEN = 20; 13 | const CHECKSUM_LEN = 4; 14 | const ADDRESS_LEN = ADDRESS_GEN_PREFIX_LEN + UINT160_LEN + CHECKSUM_LEN; 15 | 16 | /*** 17 | * 18 | * @param address 19 | * @returns {boolean} 20 | */ 21 | function verifyAddress(address) { 22 | let addressBytes = base58.decode(address); 23 | 24 | if (addressBytes.length !== ADDRESS_LEN) { 25 | return false; 26 | } 27 | 28 | let addressPrefixBytes = addressBytes.slice(0, ADDRESS_GEN_PREFIX_LEN); 29 | let addressPrefix = tools.bytesToHex(addressPrefixBytes); 30 | if (addressPrefix !== ADDRESS_GEN_PREFIX) { 31 | return false 32 | } 33 | 34 | let programHash = addressStringToProgramHash(address) 35 | let addressVerifyCode = getAddressStringVerifyCode(address) 36 | let programHashVerifyCode = genAddressVerifyCodeFromProgramHash(programHash) 37 | 38 | return addressVerifyCode === programHashVerifyCode; 39 | } 40 | 41 | /*** 42 | * 43 | * @param publicKey 44 | * @returns {string} 45 | */ 46 | function publicKeyToSignatureRedeem(publicKey) { 47 | return '20' + publicKey + 'ac'; 48 | } 49 | 50 | /*** 51 | * 52 | * @param hexString 53 | * @returns {string} 54 | */ 55 | function hexStringToProgramHash(hexStr) { 56 | return hash.ripemd160Hex(hash.sha256Hex(hexStr)) 57 | } 58 | 59 | /*** 60 | * 61 | * @param programHash 62 | * @returns {string|*} 63 | */ 64 | function programHashStringToAddress(programHash) { 65 | let addressVerifyBytes = genAddressVerifyBytesFromProgramHash(programHash) 66 | let addressBaseData = tools.hexToBytes(ADDRESS_GEN_PREFIX + programHash) 67 | return base58.encode(tools.mergeTypedArrays(addressBaseData, addressVerifyBytes)) 68 | } 69 | 70 | /*** 71 | * 72 | * @param address 73 | * @returns {Array} 74 | */ 75 | function addressStringToProgramHash(address) { 76 | let addressBytes = base58.decode(address) 77 | let programHashBytes = addressBytes.slice(ADDRESS_GEN_PREFIX_LEN, addressBytes.length - CHECKSUM_LEN) 78 | return tools.bytesToHex(programHashBytes) 79 | } 80 | 81 | /*** 82 | * 83 | * @param programHash 84 | * @returns {T[] | SharedArrayBuffer | Uint8ClampedArray | Uint32Array | Blob | Int16Array | any} 85 | */ 86 | function genAddressVerifyBytesFromProgramHash(programHash) { 87 | programHash = ADDRESS_GEN_PREFIX + programHash 88 | let verifyBytes = tools.hexToBytes(hash.doubleSha256Hex(programHash)) 89 | return verifyBytes.slice(0, CHECKSUM_LEN) 90 | } 91 | 92 | /*** 93 | * 94 | * @param programHash 95 | * @returns {Array} 96 | */ 97 | function genAddressVerifyCodeFromProgramHash(programHash) { 98 | let verifyBytes = genAddressVerifyBytesFromProgramHash(programHash) 99 | return tools.bytesToHex(verifyBytes) 100 | } 101 | 102 | /*** 103 | * 104 | * @returns {Array} 105 | */ 106 | function getAddressStringVerifyCode(address) { 107 | let addressBytes = base58.decode(address) 108 | let verifyBytes = addressBytes.slice(-CHECKSUM_LEN) 109 | 110 | return tools.bytesToHex(verifyBytes) 111 | } 112 | 113 | function signatureToParameter(signatureHex) { 114 | return '40' + signatureHex; 115 | } 116 | 117 | module.exports = { 118 | verifyAddress, 119 | publicKeyToSignatureRedeem, 120 | hexStringToProgramHash, 121 | programHashStringToAddress, 122 | addressStringToProgramHash, 123 | genAddressVerifyBytesFromProgramHash, 124 | genAddressVerifyCodeFromProgramHash, 125 | getAddressStringVerifyCode, 126 | signatureToParameter, 127 | } 128 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/node,macos,grunt,phpstorm 3 | 4 | ### grunt ### 5 | # Grunt usually compiles files inside this directory 6 | # dist/ 7 | 8 | # Grunt usually preprocesses files such as coffeescript, compass... inside the .tmp directory 9 | .tmp/ 10 | 11 | ### macOS ### 12 | # General 13 | .DS_Store 14 | .AppleDouble 15 | .LSOverride 16 | 17 | # Icon must end with two \r 18 | Icon 19 | 20 | # Thumbnails 21 | ._* 22 | 23 | # Files that might appear in the root of a volume 24 | .DocumentRevisions-V100 25 | .fseventsd 26 | .Spotlight-V100 27 | .TemporaryItems 28 | .Trashes 29 | .VolumeIcon.icns 30 | .com.apple.timemachine.donotpresent 31 | 32 | # Directories potentially created on remote AFP share 33 | .AppleDB 34 | .AppleDesktop 35 | Network Trash Folder 36 | Temporary Items 37 | .apdisk 38 | 39 | ### Node ### 40 | # Logs 41 | logs 42 | *.log 43 | npm-debug.log* 44 | yarn-debug.log* 45 | yarn-error.log* 46 | 47 | # Runtime data 48 | pids 49 | *.pid 50 | *.seed 51 | *.pid.lock 52 | 53 | # Directory for instrumented libs generated by jscoverage/JSCover 54 | lib-cov 55 | 56 | # Coverage directory used by tools like istanbul 57 | coverage 58 | 59 | # nyc test coverage 60 | .nyc_output 61 | 62 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 63 | .grunt 64 | 65 | # Bower dependency directory (https://bower.io/) 66 | bower_components 67 | 68 | # node-waf configuration 69 | .lock-wscript 70 | 71 | # Compiled binary addons (https://nodejs.org/api/addons.html) 72 | build/Release 73 | 74 | # Dependency directories 75 | node_modules/ 76 | jspm_packages/ 77 | 78 | # TypeScript v1 declaration files 79 | typings/ 80 | 81 | # Optional npm cache directory 82 | .npm 83 | 84 | # Optional eslint cache 85 | .eslintcache 86 | 87 | # Optional REPL history 88 | .node_repl_history 89 | 90 | # Output of 'npm pack' 91 | *.tgz 92 | 93 | # Yarn Integrity file 94 | .yarn-integrity 95 | 96 | # dotenv environment variables file 97 | .env 98 | 99 | # parcel-bundler cache (https://parceljs.org/) 100 | .cache 101 | 102 | # next.js build output 103 | .next 104 | 105 | # nuxt.js build output 106 | .nuxt 107 | 108 | # vuepress build output 109 | .vuepress/dist 110 | 111 | # Serverless directories 112 | .serverless 113 | 114 | ### PhpStorm ### 115 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 116 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 117 | 118 | # User-specific stuff 119 | .idea/**/workspace.xml 120 | .idea/**/tasks.xml 121 | .idea/**/usage.statistics.xml 122 | .idea/**/dictionaries 123 | .idea/**/shelf 124 | 125 | # Sensitive or high-churn files 126 | .idea/**/dataSources/ 127 | .idea/**/dataSources.ids 128 | .idea/**/dataSources.local.xml 129 | .idea/**/sqlDataSources.xml 130 | .idea/**/dynamic.xml 131 | .idea/**/uiDesigner.xml 132 | .idea/**/dbnavigator.xml 133 | 134 | # Gradle 135 | .idea/**/gradle.xml 136 | .idea/**/libraries 137 | 138 | # Gradle and Maven with auto-import 139 | # When using Gradle or Maven with auto-import, you should exclude module files, 140 | # since they will be recreated, and may cause churn. Uncomment if using 141 | # auto-import. 142 | # .idea/modules.xml 143 | # .idea/*.iml 144 | # .idea/modules 145 | 146 | # CMake 147 | cmake-build-*/ 148 | 149 | # Mongo Explorer plugin 150 | .idea/**/mongoSettings.xml 151 | 152 | # File-based project format 153 | *.iws 154 | 155 | # IntelliJ 156 | out/ 157 | 158 | # mpeltonen/sbt-idea plugin 159 | .idea_modules/ 160 | 161 | # JIRA plugin 162 | atlassian-ide-plugin.xml 163 | 164 | # Cursive Clojure plugin 165 | .idea/replstate.xml 166 | 167 | # Crashlytics plugin (for Android Studio and IntelliJ) 168 | com_crashlytics_export_strings.xml 169 | crashlytics.properties 170 | crashlytics-build.properties 171 | fabric.properties 172 | 173 | # Editor-based Rest Client 174 | .idea/httpRequests 175 | 176 | ### PhpStorm Patch ### 177 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 178 | 179 | # *.iml 180 | # modules.xml 181 | # .idea/misc.xml 182 | # *.ipr 183 | 184 | # Sonarlint plugin 185 | .idea/sonarlint 186 | 187 | 188 | # End of https://www.gitignore.io/api/node,macos,grunt,phpstorm 189 | 190 | ### my 191 | .idea/ 192 | local_test/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **Note: This repo is deprecated in favor of [nkn-sdk-js](https://github.com/nknorg/nkn-sdk-js).** 2 | 3 | # nkn-wallet-js 4 | 5 | JavaScript implementation of NKN wallet. 6 | 7 | ## Install 8 | 9 | ### Node 10 | 11 | ```shell 12 | npm i nkn-wallet 13 | ``` 14 | 15 | ### Browser 16 | 17 | Use `dist/nkn-wallet.js` or `dist/nkn-wallet.min.js`. 18 | 19 | If you use it in React Native, you also need to follow the installation guide in 20 | [react-native-crypto](https://github.com/tradle/react-native-crypto). 21 | 22 | ## Usage 23 | 24 | + import 25 | ```javascript 26 | // ES6 27 | import nknWallet from 'nkn-wallet'; 28 | 29 | // ES5 30 | var nknWallet = require('nkn-wallet'); 31 | ``` 32 | 33 | + Create a new wallet 34 | ```javascript 35 | const wallet = nknWallet.newWallet('password'); 36 | ``` 37 | 38 | + Get wallet's json string 39 | ```javascript 40 | const walletJson = wallet.toJSON(); 41 | ``` 42 | 43 | + Load wallet from a wallet json string 44 | ```javascript 45 | const walletFromJson = nknWallet.loadJsonWallet(walletJson, 'password'); 46 | ``` 47 | 48 | + Restore wallet from a private key 49 | ```javascript 50 | const walletFromSeed = nknWallet.restoreWalletBySeed(wallet.getSeed(), 'new-wallet-password'); 51 | ``` 52 | 53 | + Verify whether an address is valid 54 | ```javascript 55 | console.log(nknWallet.verifyAddress(wallet.address)); 56 | ``` 57 | 58 | + Verify password of the wallet 59 | ```javascript 60 | console.log(wallet.verifyPassword('password')); 61 | ``` 62 | 63 | + Get balance of this wallet 64 | ```javascript 65 | wallet.getBalance() 66 | .then(function(value) { 67 | console.log('Balance for this wallet is:', value.toString()); 68 | }) 69 | .catch(function(error) { 70 | console.log('Get balance fail:', error); 71 | }); 72 | ``` 73 | 74 | + Transfer token to some address 75 | ```javascript 76 | wallet.transferTo(wallet.address, 1) 77 | .then(function(data) { 78 | console.log('Transfer success:', data); 79 | }) 80 | .catch(function(error) { 81 | console.log('Transfer fail:', error); 82 | }); 83 | ``` 84 | 85 | + Register name for this wallet 86 | ```javascript 87 | wallet.registerName('some-name') 88 | .then(function(data) { 89 | console.log('Register name success:', data); 90 | }) 91 | .catch(function(error) { 92 | console.log('Register name fail:', error); 93 | }); 94 | ``` 95 | 96 | + Delete name for this wallet 97 | ```javascript 98 | wallet.deleteName('some-name') 99 | .then(function(data) { 100 | console.log('Delete name success:', data); 101 | }).catch(function(error) { 102 | console.log('Delete name fail:', error); 103 | }); 104 | ``` 105 | 106 | + Subscribe to specified topic for this wallet for next 10 blocks 107 | ```javascript 108 | wallet.subscribe('topic', 10, 'identifier') 109 | .then(function(data) { 110 | console.log('Subscribe success:', data); 111 | }).catch(function(error) { 112 | console.log('Subscribe fail:', error); 113 | }); 114 | ``` 115 | 116 | Check [examples](examples) for full examples. 117 | 118 | ## Configure 119 | 120 | NKN wallet only stores some static information such as encrypted private keys, 121 | addresses and so on. All dynamic information needs to be queried from a NKN 122 | node. By default it will try to use RPC server provided by NKN, but you can 123 | change it by calling the global configure function: 124 | 125 | ```javascript 126 | nknWallet.configure({ 127 | rpcAddr: 'http://127.0.0.1:30003', 128 | }) 129 | ``` 130 | 131 | Note that configure is optional. If you don't call `configure()`, default 132 | configurations will be used. 133 | 134 | ## API 135 | 136 | + nknWallet 137 | 138 | ```javascript 139 | 140 | /*** 141 | * global configuration: 142 | * { 143 | * rpcAddr:'', 144 | * } 145 | * 146 | * @param config | Object 147 | */ 148 | nknWallet.configure(config) 149 | ``` 150 | 151 | ```javascript 152 | /** 153 | * create a new wallet 154 | * @param password : string : the password to encrypt wallet 155 | * @returns {NknWallet} : a NknWallet instance 156 | */ 157 | nknWallet.newWallet(password) 158 | ``` 159 | 160 | ```javascript 161 | /*** 162 | * load wallet from json string 163 | * @param walletJson : string : a json format wallet 164 | * @param password : string : password for this wallet 165 | * @returns {NknWallet | null} : return NknWallet instance or null if key information is missing. 166 | * 167 | * !this method will thow an error if the password is wrong! 168 | */ 169 | nknWallet.loadJsonWallet(walletJson, password) 170 | ``` 171 | 172 | ```javascript 173 | /*** 174 | * restore a wallet from private key 175 | * @param privateKey : string : the private key for wallet restore 176 | * @param password : string : password for new wallet 177 | * @returns {NknWallet} : a NknWallet instance 178 | */ 179 | nknWallet.restoreWalletBySeed(privateKey, password) 180 | ``` 181 | 182 | ```javascript 183 | /*** 184 | * verify whether an address is valid 185 | * @param address : string : an address 186 | * @returns {boolean} : verifies whether an address is valid 187 | */ 188 | nknWallet.verifyAddress(address) 189 | ``` 190 | 191 | + NknWallet 192 | 193 | All of the following methods are instance methods 194 | 195 | ```javascript 196 | /*** 197 | * generate wallet json 198 | * @returns {string} : wallet json 199 | */ 200 | toJSON() 201 | ``` 202 | 203 | ```javascript 204 | /*** 205 | * get the public key of this wallet 206 | * @returns {string} : the public key of this wallet 207 | */ 208 | getPublicKey() 209 | ``` 210 | 211 | ```javascript 212 | /*** 213 | * verify password of the wallet 214 | * @param password : string : password for this wallet 215 | * @returns {boolean} : verifies whether the password is correct 216 | */ 217 | verifyPassword(password) 218 | ``` 219 | 220 | ```javascript 221 | /*** 222 | * get the private key of this wallet 223 | * @returns {string} : the private key of this wallet 224 | * 225 | * !!! anyone with the private key has the power to restore a full-featured wallet !!!! 226 | */ 227 | getPrivateKey() 228 | ``` 229 | 230 | ```javascript 231 | /*** 232 | * transfer nkn to some valid address 233 | * @param toAddress : string : valid nkn address 234 | * @param value : number : value for transfer 235 | * 236 | * !!! the fail function will be called for any transfer errors 237 | * and the parameter applied is a WalletError instance. !!! 238 | */ 239 | transferTo(toAddress, value) 240 | ``` 241 | 242 | ```javascript 243 | /*** 244 | * register name on nkn for current wallet 245 | * @param name : string : name to register 246 | * 247 | * !!! the fail function will be called for any register errors 248 | * and the parameter applied is a WalletError instance. !!! 249 | */ 250 | registerName(name) 251 | ``` 252 | 253 | ```javascript 254 | /*** 255 | * delete name on nkn for current wallet 256 | * @param name : string : name to delete 257 | * 258 | * !!! the fail function will be called for any delete errors 259 | * and the parameter applied is a WalletError instance. !!! 260 | */ 261 | deleteName(name) 262 | ``` 263 | 264 | ```javascript 265 | /*** 266 | * subscribe to topic on nkn for current wallet 267 | * @param topic : string : topic to subscribe to 268 | * @param duration : number : subscription duration 269 | * @param identifier : string : optional identifier 270 | * @param meta : string : optional metadata 271 | * 272 | * !!! the fail function will be called for any register errors 273 | * and the parameter applied is a WalletError instance. !!! 274 | */ 275 | subscribe(topic, duration, identifier = '', meta = '', options = {}) 276 | ``` 277 | 278 | ```javascript 279 | /*** 280 | * query balance 281 | * @returns {promise} : if resolved, the parameter is a decimal.js instance 282 | */ 283 | getBalance() 284 | ``` 285 | 286 | ## Contributing 287 | 288 | **Can I submit a bug, suggestion or feature request?** 289 | 290 | Yes. Please open an issue for that. 291 | 292 | **Can I contribute patches?** 293 | 294 | Yes, we appreciate your help! To make contributions, please fork the repo, push 295 | your changes to the forked repo with signed-off commits, and open a pull request 296 | here. 297 | 298 | Please sign off your commit. This means adding a line "Signed-off-by: Name 299 | " at the end of each commit, indicating that you wrote the code and have 300 | the right to pass it on as an open source patch. This can be done automatically 301 | by adding -s when committing: 302 | 303 | ```shell 304 | git commit -s 305 | ``` 306 | 307 | ## Community 308 | 309 | * [Discord](https://discord.gg/c7mTynX) 310 | * [Telegram](https://t.me/nknorg) 311 | * [Reddit](https://www.reddit.com/r/nknblockchain/) 312 | * [Twitter](https://twitter.com/NKN_ORG) 313 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /lib/wallet.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('es6-promise/auto'); 4 | 5 | const is = require('is'); 6 | 7 | const { newAccount, restoreAccount } = require('./crypto/account'); 8 | const encryption = require('./crypto/encryption'); 9 | const hash = require('./crypto/hash'); 10 | const protocol = require('./crypto/protocol'); 11 | const payload = require('./transaction/payload'); 12 | const tools = require('./crypto/tools'); 13 | const transaction = require('./transaction/transaction'); 14 | const http = require('./network/http'); 15 | const errors = require('./common/errors'); 16 | const nknMath = require('./common/math'); 17 | 18 | var config = require('./config'); 19 | 20 | const walletVersion = 1; 21 | const minCompatibleWalletVersion = 1; 22 | const maxCompatibleWalletVersion = 1; 23 | 24 | configure(config); 25 | 26 | let NknWallet = function (account) { 27 | this.passwordHash = "" 28 | this.iv = "" 29 | this.masterKey = "" 30 | this.address = "" 31 | this.programHash = "" 32 | this.seedEncrypted = "" 33 | this.contractData = "" 34 | 35 | this.verifyPassword = function (pswd) { 36 | return verifyWalletPassword(this, pswd); 37 | } 38 | 39 | /*** 40 | * query balance 41 | * @returns {promise} : if resolved, the parameter is a decimal.js instance 42 | */ 43 | this.getBalance = async function (targetAddress) { 44 | if(!this.address && !targetAddress) { 45 | throw errors.Error(errors.code.invalidArgument, 'address is empty') 46 | } 47 | 48 | let queryAddress = this.address 49 | if(is.string(targetAddress)) { 50 | queryAddress = targetAddress 51 | } 52 | 53 | let data = await http.getBalanceByAddr(queryAddress) 54 | if (data && data.amount) { 55 | return nknMath.newNum(data.amount) 56 | } 57 | 58 | throw errors.Error(errors.code.invalidResponse) 59 | } 60 | 61 | /*** 62 | * get nonce 63 | * @returns {promise} : if resolved, the parameter is a integer 64 | */ 65 | this.getNonce = async function (targetAddress) { 66 | if(!this.address && !targetAddress) { 67 | throw errors.Error(errors.code.invalidArgument, 'address is empty') 68 | } 69 | 70 | let queryAddress = this.address 71 | if(is.string(targetAddress)) { 72 | queryAddress = targetAddress 73 | } 74 | 75 | let data = await http.getNonceByAddr(queryAddress) 76 | if (data && (is.number(data.nonceInTxPool) || is.number(data.nonce))) { 77 | let nonce = 0 78 | if (is.number(data.nonce) && data.nonce > nonce) { 79 | nonce = data.nonce 80 | } 81 | if (is.number(data.nonceInTxPool) && data.nonceInTxPool > nonce) { 82 | nonce = data.nonceInTxPool 83 | } 84 | return nonce 85 | } 86 | 87 | throw errors.Error(errors.code.invalidResponse) 88 | } 89 | 90 | /*** 91 | * transfer nkn to some valid address 92 | * @param toAddress : string : valid nkn address 93 | * @param value : number : value for transfer 94 | */ 95 | this.transferTo = async function (toAddress, amount, options = {}) { 96 | if(!protocol.verifyAddress(toAddress)) { 97 | throw errors.Error(errors.code.invalidAddress) 98 | } 99 | 100 | let balance = await this.getBalance(); 101 | let fee = options.fee || 0; 102 | if (nknMath.lessThan(balance, amount + fee)) { 103 | throw errors.Error(errors.code.notEnoughBalance) 104 | } 105 | 106 | let nonce = options.nonce || await this.getNonce(); 107 | 108 | let pld = payload.newTransfer( 109 | this.programHash, 110 | protocol.addressStringToProgramHash(toAddress), 111 | amount, 112 | ); 113 | 114 | return this.createTransaction(pld, nonce, options); 115 | } 116 | 117 | /*** 118 | * register name on nkn for current wallet 119 | * @param name : string : name to register 120 | */ 121 | this.registerName = async function (name, options = {}) { 122 | let nonce = options.nonce || await this.getNonce(); 123 | let pld = payload.newRegisterName(this.getPublicKey(), name); 124 | return this.createTransaction(pld, nonce, options); 125 | } 126 | 127 | /*** 128 | * delete name on nkn for current wallet 129 | * @param name : string : name to delete 130 | */ 131 | this.deleteName = async function (name, options = {}) { 132 | let nonce = options.nonce || await this.getNonce(); 133 | let pld = payload.newDeleteName(this.getPublicKey(), name); 134 | return this.createTransaction(pld, nonce, options); 135 | } 136 | 137 | /*** 138 | * get address of a name 139 | * @param name : string : name to delete 140 | */ 141 | this.getAddressByName = async function (name) { 142 | let addr = await http.getAddressByName(name) 143 | if (addr && is.string(addr)) { 144 | return addr 145 | } 146 | return null; 147 | } 148 | 149 | /*** 150 | * subscribe to topic on nkn for current wallet 151 | * @param topic : string : topic to subscribe to 152 | * @param duration : number : subscription duration 153 | * @param identifier : string : optional identifier 154 | * @param meta : string : optional meta data 155 | */ 156 | this.subscribe = async function (topic, duration, identifier = '', meta = '', options = {}) { 157 | let nonce = options.nonce || await this.getNonce(); 158 | let pld = payload.newSubscribe(this.getPublicKey(), identifier, topic, duration, meta); 159 | return this.createTransaction(pld, nonce, options); 160 | } 161 | 162 | /*** 163 | * unsubscribe to topic on nkn for current wallet 164 | * @param topic : string : topic to subscribe to 165 | * @param identifier : string : optional identifier 166 | */ 167 | this.unsubscribe = async function (topic, identifier = '', options = {}) { 168 | let nonce = options.nonce || await this.getNonce(); 169 | let pld = payload.newUnsubscribe(this.getPublicKey(), identifier, topic); 170 | return this.createTransaction(pld, nonce, options); 171 | } 172 | 173 | this.createOrUpdateNanoPay = async function (toAddress, amount, expiration, id, options = {}) { 174 | if(!protocol.verifyAddress(toAddress)) { 175 | throw errors.Error(errors.code.invalidAddress) 176 | } 177 | 178 | let balance = await this.getBalance(); 179 | let fee = options.fee || 0; 180 | if (nknMath.lessThan(balance, amount + fee)) { 181 | throw errors.Error(errors.code.notEnoughBalance) 182 | } 183 | 184 | if (!id) { 185 | id = tools.randomUint64(); 186 | } 187 | 188 | let pld = payload.newNanoPay( 189 | this.programHash, 190 | protocol.addressStringToProgramHash(toAddress), 191 | id, 192 | amount, 193 | expiration, 194 | expiration, 195 | ); 196 | 197 | return this.createTransaction(pld, 0, Object.assign({}, options, { buildOnly: true })); 198 | } 199 | 200 | this.createTransaction = function (pld, nonce, options) { 201 | let txn = transaction.newTransaction(account, pld, nonce, options.fee || 0, options.attrs || ''); 202 | if (options.buildOnly) { 203 | return txn; 204 | } 205 | return this.sendTransaction(txn); 206 | } 207 | 208 | this.sendTransaction = function (txn) { 209 | return http.sendRawTransaction(tools.bytesToHex(txn.serializeBinary())); 210 | } 211 | 212 | /*** 213 | * get the public key of this wallet 214 | * @returns {string} : the public key of this wallet 215 | */ 216 | this.getPublicKey = function () { 217 | return account.getPublicKey() 218 | } 219 | 220 | /*** 221 | * get the private key of this wallet 222 | * @returns {string} : the private key of this wallet 223 | * 224 | * !!! anyone with the private key has the power to restore a full-featured wallet !!!! 225 | */ 226 | this.getPrivateKey = function () { 227 | return account.getPrivateKey() 228 | } 229 | 230 | /*** 231 | * get the seed of this wallet 232 | * @returns {string} : the seed of this wallet 233 | * 234 | * !!! anyone with the seed has the power to restore a full-featured wallet !!!! 235 | */ 236 | this.getSeed = function () { 237 | return account.getSeed() 238 | } 239 | 240 | /*** 241 | * generate a wallet in JSON format 242 | * @returns {string} : wallet json 243 | */ 244 | this.toJSON = function () { 245 | return JSON.stringify({ 246 | Version: this.version, 247 | PasswordHash: this.passwordHash, 248 | MasterKey: this.masterKey, 249 | IV: this.iv, 250 | SeedEncrypted: this.seedEncrypted, 251 | Address: this.address, 252 | ProgramHash: this.programHash, 253 | ContractData: this.contractData, 254 | }) 255 | } 256 | } 257 | 258 | /*** 259 | * 260 | * @param password 261 | * @returns {*} 262 | */ 263 | function passwordHash(password) { 264 | return hash.doubleSha256(password) 265 | } 266 | 267 | 268 | function genWallet(account, password, prevMasterKey, prevIV) { 269 | let wallet = new NknWallet(account) 270 | 271 | let pswdHash = passwordHash(password) 272 | 273 | let iv = prevIV || encryption.genAESIV() 274 | let masterKey = prevMasterKey || encryption.genAESPassword() 275 | 276 | masterKey = hash.cryptoHexStringParse(masterKey) 277 | 278 | let seed = account.getSeed() 279 | seed = hash.cryptoHexStringParse(seed) 280 | 281 | wallet.passwordHash = hash.sha256Hex(pswdHash) 282 | wallet.iv = iv 283 | wallet.masterKey = encryption.encrypt(masterKey, pswdHash, iv) 284 | wallet.address = account.getAddress() 285 | wallet.programHash = account.getProgramHash() 286 | wallet.seedEncrypted = encryption.encrypt(seed, masterKey.toString(), iv) 287 | wallet.contractData = account.getContractString() 288 | wallet.version = walletVersion 289 | 290 | return wallet 291 | } 292 | 293 | function decryptWalletSeed(masterKeyEncrypted, iv, seedEncrypted, password) { 294 | let pswdHash = passwordHash(password) 295 | let masterKey = encryption.decrypt(hash.cryptoHexStringParse(masterKeyEncrypted), pswdHash, iv) 296 | let seed = encryption.decrypt(hash.cryptoHexStringParse(seedEncrypted), masterKey, iv) 297 | 298 | return { 299 | masterKey: masterKey, 300 | seed: seed, 301 | } 302 | } 303 | 304 | /*** 305 | * 306 | * @param wallet 307 | * @param password 308 | */ 309 | function verifyWalletPassword(wallet, password) { 310 | let pswdHash = passwordHash(password) 311 | 312 | if(wallet.passwordHash !== hash.sha256Hex(pswdHash)) { 313 | return false 314 | } 315 | 316 | return true; 317 | } 318 | 319 | /** 320 | * create a new wallet 321 | * @param password : string : the password to encrypt wallet 322 | * @returns {NknWallet} : Object : a NknWallet instance 323 | */ 324 | function newWallet(password) { 325 | let account = newAccount() 326 | return genWallet(account, password) 327 | } 328 | 329 | /*** 330 | * restore a wallet from seed 331 | * @param seed : string : the seed for wallet restore 332 | * @param password : string : password for new wallet 333 | * @returns {NknWallet} : a NknWallet instance 334 | * 335 | * !!! this method will thow an error if the password is wrong !!! 336 | */ 337 | function restoreWalletBySeed(seed, password) { 338 | let account = restoreAccount(seed) 339 | return genWallet(account, password) 340 | } 341 | 342 | /*** 343 | * 344 | * @param seed 345 | * @param password 346 | * @param prevMasterKey 347 | * @param preIV 348 | */ 349 | function restoreWalletFromJson(seed, password, prevMasterKey, preIV) { 350 | let account = restoreAccount(seed) 351 | return genWallet(account, password, prevMasterKey, preIV) 352 | } 353 | 354 | /*** 355 | * load wallet from json string 356 | * @param walletJson : string : a json format wallet 357 | * @param password : string : password for this wallet 358 | * @returns {NknWallet | WalletError} : return NknWallet instance or WalletError if something wrong. 359 | * 360 | * !!! this method will thow an error if the password is wrong !!! 361 | */ 362 | function loadJsonWallet(walletJson, password) { 363 | let walletObj = JSON.parse(walletJson) 364 | if (!is.number(walletObj.Version) || walletObj.Version < minCompatibleWalletVersion || walletObj.Version > maxCompatibleWalletVersion) { 365 | throw errors.Error(errors.code.invalidWalletVersion, "Invalid wallet version " + walletObj.Version + ", should be between " + minCompatibleWalletVersion + " and " + maxCompatibleWalletVersion) 366 | } 367 | 368 | if (!is.string(walletObj.MasterKey) || !is.string(walletObj.IV) || !is.string(walletObj.SeedEncrypted) || !is.string(walletObj.Address)) { 369 | throw errors.Error(errors.code.invalidWalletFormat) 370 | } 371 | 372 | let pswdHash = passwordHash(password); 373 | if (walletObj.PasswordHash !== hash.sha256Hex(pswdHash)) { 374 | throw errors.Error(errors.code.wrongPassword) 375 | } 376 | 377 | let masterKey = encryption.decrypt(hash.cryptoHexStringParse(walletObj.MasterKey), pswdHash, walletObj.IV); 378 | let seed = encryption.decrypt(hash.cryptoHexStringParse(walletObj.SeedEncrypted), masterKey, walletObj.IV); 379 | let wallet = restoreWalletFromJson(seed, password, masterKey, walletObj.IV); 380 | 381 | return wallet 382 | } 383 | 384 | /*** 385 | * global configuration: 386 | * { 387 | * rpcAddr:'', // node addr for dynamic information query 388 | * } 389 | * 390 | * @param newConfig : Object 391 | */ 392 | function configure(newConfig) { 393 | config = Object.assign({}, config, newConfig) 394 | http.configure(config.rpcAddr) 395 | } 396 | 397 | module.exports = { 398 | configure: configure, 399 | newWallet: newWallet, 400 | loadJsonWallet: loadJsonWallet, 401 | restoreWalletBySeed: restoreWalletBySeed, 402 | verifyAddress: protocol.verifyAddress, 403 | } 404 | -------------------------------------------------------------------------------- /lib/pb/transaction_pb.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview 3 | * @enhanceable 4 | * @suppress {messageConventions} JS Compiler reports an error if a variable or 5 | * field starts with 'MSG_' and isn't a translatable message. 6 | * @public 7 | */ 8 | // GENERATED CODE -- DO NOT EDIT! 9 | 10 | var jspb = require('google-protobuf'); 11 | var goog = jspb; 12 | var global = Function('return this')(); 13 | 14 | goog.exportSymbol('proto.pb.Coinbase', null, global); 15 | goog.exportSymbol('proto.pb.DeleteName', null, global); 16 | goog.exportSymbol('proto.pb.GenerateID', null, global); 17 | goog.exportSymbol('proto.pb.IssueAsset', null, global); 18 | goog.exportSymbol('proto.pb.NanoPay', null, global); 19 | goog.exportSymbol('proto.pb.Payload', null, global); 20 | goog.exportSymbol('proto.pb.PayloadType', null, global); 21 | goog.exportSymbol('proto.pb.Program', null, global); 22 | goog.exportSymbol('proto.pb.RegisterName', null, global); 23 | goog.exportSymbol('proto.pb.SigChainTxn', null, global); 24 | goog.exportSymbol('proto.pb.Subscribe', null, global); 25 | goog.exportSymbol('proto.pb.Transaction', null, global); 26 | goog.exportSymbol('proto.pb.TransferAsset', null, global); 27 | goog.exportSymbol('proto.pb.UnsignedTx', null, global); 28 | goog.exportSymbol('proto.pb.Unsubscribe', null, global); 29 | /** 30 | * Generated by JsPbCodeGenerator. 31 | * @param {Array=} opt_data Optional initial data array, typically from a 32 | * server response, or constructed directly in Javascript. The array is used 33 | * in place and becomes part of the constructed object. It is not cloned. 34 | * If no data is provided, the constructed object will be empty, but still 35 | * valid. 36 | * @extends {jspb.Message} 37 | * @constructor 38 | */ 39 | proto.pb.UnsignedTx = function(opt_data) { 40 | jspb.Message.initialize(this, opt_data, 0, -1, null, null); 41 | }; 42 | goog.inherits(proto.pb.UnsignedTx, jspb.Message); 43 | if (goog.DEBUG && !COMPILED) { 44 | /** 45 | * @public 46 | * @override 47 | */ 48 | proto.pb.UnsignedTx.displayName = 'proto.pb.UnsignedTx'; 49 | } 50 | /** 51 | * Generated by JsPbCodeGenerator. 52 | * @param {Array=} opt_data Optional initial data array, typically from a 53 | * server response, or constructed directly in Javascript. The array is used 54 | * in place and becomes part of the constructed object. It is not cloned. 55 | * If no data is provided, the constructed object will be empty, but still 56 | * valid. 57 | * @extends {jspb.Message} 58 | * @constructor 59 | */ 60 | proto.pb.Transaction = function(opt_data) { 61 | jspb.Message.initialize(this, opt_data, 0, -1, proto.pb.Transaction.repeatedFields_, null); 62 | }; 63 | goog.inherits(proto.pb.Transaction, jspb.Message); 64 | if (goog.DEBUG && !COMPILED) { 65 | /** 66 | * @public 67 | * @override 68 | */ 69 | proto.pb.Transaction.displayName = 'proto.pb.Transaction'; 70 | } 71 | /** 72 | * Generated by JsPbCodeGenerator. 73 | * @param {Array=} opt_data Optional initial data array, typically from a 74 | * server response, or constructed directly in Javascript. The array is used 75 | * in place and becomes part of the constructed object. It is not cloned. 76 | * If no data is provided, the constructed object will be empty, but still 77 | * valid. 78 | * @extends {jspb.Message} 79 | * @constructor 80 | */ 81 | proto.pb.Program = function(opt_data) { 82 | jspb.Message.initialize(this, opt_data, 0, -1, null, null); 83 | }; 84 | goog.inherits(proto.pb.Program, jspb.Message); 85 | if (goog.DEBUG && !COMPILED) { 86 | /** 87 | * @public 88 | * @override 89 | */ 90 | proto.pb.Program.displayName = 'proto.pb.Program'; 91 | } 92 | /** 93 | * Generated by JsPbCodeGenerator. 94 | * @param {Array=} opt_data Optional initial data array, typically from a 95 | * server response, or constructed directly in Javascript. The array is used 96 | * in place and becomes part of the constructed object. It is not cloned. 97 | * If no data is provided, the constructed object will be empty, but still 98 | * valid. 99 | * @extends {jspb.Message} 100 | * @constructor 101 | */ 102 | proto.pb.Payload = function(opt_data) { 103 | jspb.Message.initialize(this, opt_data, 0, -1, null, null); 104 | }; 105 | goog.inherits(proto.pb.Payload, jspb.Message); 106 | if (goog.DEBUG && !COMPILED) { 107 | /** 108 | * @public 109 | * @override 110 | */ 111 | proto.pb.Payload.displayName = 'proto.pb.Payload'; 112 | } 113 | /** 114 | * Generated by JsPbCodeGenerator. 115 | * @param {Array=} opt_data Optional initial data array, typically from a 116 | * server response, or constructed directly in Javascript. The array is used 117 | * in place and becomes part of the constructed object. It is not cloned. 118 | * If no data is provided, the constructed object will be empty, but still 119 | * valid. 120 | * @extends {jspb.Message} 121 | * @constructor 122 | */ 123 | proto.pb.Coinbase = function(opt_data) { 124 | jspb.Message.initialize(this, opt_data, 0, -1, null, null); 125 | }; 126 | goog.inherits(proto.pb.Coinbase, jspb.Message); 127 | if (goog.DEBUG && !COMPILED) { 128 | /** 129 | * @public 130 | * @override 131 | */ 132 | proto.pb.Coinbase.displayName = 'proto.pb.Coinbase'; 133 | } 134 | /** 135 | * Generated by JsPbCodeGenerator. 136 | * @param {Array=} opt_data Optional initial data array, typically from a 137 | * server response, or constructed directly in Javascript. The array is used 138 | * in place and becomes part of the constructed object. It is not cloned. 139 | * If no data is provided, the constructed object will be empty, but still 140 | * valid. 141 | * @extends {jspb.Message} 142 | * @constructor 143 | */ 144 | proto.pb.SigChainTxn = function(opt_data) { 145 | jspb.Message.initialize(this, opt_data, 0, -1, null, null); 146 | }; 147 | goog.inherits(proto.pb.SigChainTxn, jspb.Message); 148 | if (goog.DEBUG && !COMPILED) { 149 | /** 150 | * @public 151 | * @override 152 | */ 153 | proto.pb.SigChainTxn.displayName = 'proto.pb.SigChainTxn'; 154 | } 155 | /** 156 | * Generated by JsPbCodeGenerator. 157 | * @param {Array=} opt_data Optional initial data array, typically from a 158 | * server response, or constructed directly in Javascript. The array is used 159 | * in place and becomes part of the constructed object. It is not cloned. 160 | * If no data is provided, the constructed object will be empty, but still 161 | * valid. 162 | * @extends {jspb.Message} 163 | * @constructor 164 | */ 165 | proto.pb.RegisterName = function(opt_data) { 166 | jspb.Message.initialize(this, opt_data, 0, -1, null, null); 167 | }; 168 | goog.inherits(proto.pb.RegisterName, jspb.Message); 169 | if (goog.DEBUG && !COMPILED) { 170 | /** 171 | * @public 172 | * @override 173 | */ 174 | proto.pb.RegisterName.displayName = 'proto.pb.RegisterName'; 175 | } 176 | /** 177 | * Generated by JsPbCodeGenerator. 178 | * @param {Array=} opt_data Optional initial data array, typically from a 179 | * server response, or constructed directly in Javascript. The array is used 180 | * in place and becomes part of the constructed object. It is not cloned. 181 | * If no data is provided, the constructed object will be empty, but still 182 | * valid. 183 | * @extends {jspb.Message} 184 | * @constructor 185 | */ 186 | proto.pb.DeleteName = function(opt_data) { 187 | jspb.Message.initialize(this, opt_data, 0, -1, null, null); 188 | }; 189 | goog.inherits(proto.pb.DeleteName, jspb.Message); 190 | if (goog.DEBUG && !COMPILED) { 191 | /** 192 | * @public 193 | * @override 194 | */ 195 | proto.pb.DeleteName.displayName = 'proto.pb.DeleteName'; 196 | } 197 | /** 198 | * Generated by JsPbCodeGenerator. 199 | * @param {Array=} opt_data Optional initial data array, typically from a 200 | * server response, or constructed directly in Javascript. The array is used 201 | * in place and becomes part of the constructed object. It is not cloned. 202 | * If no data is provided, the constructed object will be empty, but still 203 | * valid. 204 | * @extends {jspb.Message} 205 | * @constructor 206 | */ 207 | proto.pb.Subscribe = function(opt_data) { 208 | jspb.Message.initialize(this, opt_data, 0, -1, null, null); 209 | }; 210 | goog.inherits(proto.pb.Subscribe, jspb.Message); 211 | if (goog.DEBUG && !COMPILED) { 212 | /** 213 | * @public 214 | * @override 215 | */ 216 | proto.pb.Subscribe.displayName = 'proto.pb.Subscribe'; 217 | } 218 | /** 219 | * Generated by JsPbCodeGenerator. 220 | * @param {Array=} opt_data Optional initial data array, typically from a 221 | * server response, or constructed directly in Javascript. The array is used 222 | * in place and becomes part of the constructed object. It is not cloned. 223 | * If no data is provided, the constructed object will be empty, but still 224 | * valid. 225 | * @extends {jspb.Message} 226 | * @constructor 227 | */ 228 | proto.pb.Unsubscribe = function(opt_data) { 229 | jspb.Message.initialize(this, opt_data, 0, -1, null, null); 230 | }; 231 | goog.inherits(proto.pb.Unsubscribe, jspb.Message); 232 | if (goog.DEBUG && !COMPILED) { 233 | /** 234 | * @public 235 | * @override 236 | */ 237 | proto.pb.Unsubscribe.displayName = 'proto.pb.Unsubscribe'; 238 | } 239 | /** 240 | * Generated by JsPbCodeGenerator. 241 | * @param {Array=} opt_data Optional initial data array, typically from a 242 | * server response, or constructed directly in Javascript. The array is used 243 | * in place and becomes part of the constructed object. It is not cloned. 244 | * If no data is provided, the constructed object will be empty, but still 245 | * valid. 246 | * @extends {jspb.Message} 247 | * @constructor 248 | */ 249 | proto.pb.TransferAsset = function(opt_data) { 250 | jspb.Message.initialize(this, opt_data, 0, -1, null, null); 251 | }; 252 | goog.inherits(proto.pb.TransferAsset, jspb.Message); 253 | if (goog.DEBUG && !COMPILED) { 254 | /** 255 | * @public 256 | * @override 257 | */ 258 | proto.pb.TransferAsset.displayName = 'proto.pb.TransferAsset'; 259 | } 260 | /** 261 | * Generated by JsPbCodeGenerator. 262 | * @param {Array=} opt_data Optional initial data array, typically from a 263 | * server response, or constructed directly in Javascript. The array is used 264 | * in place and becomes part of the constructed object. It is not cloned. 265 | * If no data is provided, the constructed object will be empty, but still 266 | * valid. 267 | * @extends {jspb.Message} 268 | * @constructor 269 | */ 270 | proto.pb.GenerateID = function(opt_data) { 271 | jspb.Message.initialize(this, opt_data, 0, -1, null, null); 272 | }; 273 | goog.inherits(proto.pb.GenerateID, jspb.Message); 274 | if (goog.DEBUG && !COMPILED) { 275 | /** 276 | * @public 277 | * @override 278 | */ 279 | proto.pb.GenerateID.displayName = 'proto.pb.GenerateID'; 280 | } 281 | /** 282 | * Generated by JsPbCodeGenerator. 283 | * @param {Array=} opt_data Optional initial data array, typically from a 284 | * server response, or constructed directly in Javascript. The array is used 285 | * in place and becomes part of the constructed object. It is not cloned. 286 | * If no data is provided, the constructed object will be empty, but still 287 | * valid. 288 | * @extends {jspb.Message} 289 | * @constructor 290 | */ 291 | proto.pb.NanoPay = function(opt_data) { 292 | jspb.Message.initialize(this, opt_data, 0, -1, null, null); 293 | }; 294 | goog.inherits(proto.pb.NanoPay, jspb.Message); 295 | if (goog.DEBUG && !COMPILED) { 296 | /** 297 | * @public 298 | * @override 299 | */ 300 | proto.pb.NanoPay.displayName = 'proto.pb.NanoPay'; 301 | } 302 | /** 303 | * Generated by JsPbCodeGenerator. 304 | * @param {Array=} opt_data Optional initial data array, typically from a 305 | * server response, or constructed directly in Javascript. The array is used 306 | * in place and becomes part of the constructed object. It is not cloned. 307 | * If no data is provided, the constructed object will be empty, but still 308 | * valid. 309 | * @extends {jspb.Message} 310 | * @constructor 311 | */ 312 | proto.pb.IssueAsset = function(opt_data) { 313 | jspb.Message.initialize(this, opt_data, 0, -1, null, null); 314 | }; 315 | goog.inherits(proto.pb.IssueAsset, jspb.Message); 316 | if (goog.DEBUG && !COMPILED) { 317 | /** 318 | * @public 319 | * @override 320 | */ 321 | proto.pb.IssueAsset.displayName = 'proto.pb.IssueAsset'; 322 | } 323 | 324 | 325 | 326 | if (jspb.Message.GENERATE_TO_OBJECT) { 327 | /** 328 | * Creates an object representation of this proto suitable for use in Soy templates. 329 | * Field names that are reserved in JavaScript and will be renamed to pb_name. 330 | * To access a reserved field use, foo.pb_, eg, foo.pb_default. 331 | * For the list of reserved names please see: 332 | * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. 333 | * @param {boolean=} opt_includeInstance Whether to include the JSPB instance 334 | * for transitional soy proto support: http://goto/soy-param-migration 335 | * @return {!Object} 336 | */ 337 | proto.pb.UnsignedTx.prototype.toObject = function(opt_includeInstance) { 338 | return proto.pb.UnsignedTx.toObject(opt_includeInstance, this); 339 | }; 340 | 341 | 342 | /** 343 | * Static version of the {@see toObject} method. 344 | * @param {boolean|undefined} includeInstance Whether to include the JSPB 345 | * instance for transitional soy proto support: 346 | * http://goto/soy-param-migration 347 | * @param {!proto.pb.UnsignedTx} msg The msg instance to transform. 348 | * @return {!Object} 349 | * @suppress {unusedLocalVariables} f is only used for nested messages 350 | */ 351 | proto.pb.UnsignedTx.toObject = function(includeInstance, msg) { 352 | var f, obj = { 353 | payload: (f = msg.getPayload()) && proto.pb.Payload.toObject(includeInstance, f), 354 | nonce: jspb.Message.getFieldWithDefault(msg, 2, 0), 355 | fee: jspb.Message.getFieldWithDefault(msg, 3, 0), 356 | attributes: msg.getAttributes_asB64() 357 | }; 358 | 359 | if (includeInstance) { 360 | obj.$jspbMessageInstance = msg; 361 | } 362 | return obj; 363 | }; 364 | } 365 | 366 | 367 | /** 368 | * Deserializes binary data (in protobuf wire format). 369 | * @param {jspb.ByteSource} bytes The bytes to deserialize. 370 | * @return {!proto.pb.UnsignedTx} 371 | */ 372 | proto.pb.UnsignedTx.deserializeBinary = function(bytes) { 373 | var reader = new jspb.BinaryReader(bytes); 374 | var msg = new proto.pb.UnsignedTx; 375 | return proto.pb.UnsignedTx.deserializeBinaryFromReader(msg, reader); 376 | }; 377 | 378 | 379 | /** 380 | * Deserializes binary data (in protobuf wire format) from the 381 | * given reader into the given message object. 382 | * @param {!proto.pb.UnsignedTx} msg The message object to deserialize into. 383 | * @param {!jspb.BinaryReader} reader The BinaryReader to use. 384 | * @return {!proto.pb.UnsignedTx} 385 | */ 386 | proto.pb.UnsignedTx.deserializeBinaryFromReader = function(msg, reader) { 387 | while (reader.nextField()) { 388 | if (reader.isEndGroup()) { 389 | break; 390 | } 391 | var field = reader.getFieldNumber(); 392 | switch (field) { 393 | case 1: 394 | var value = new proto.pb.Payload; 395 | reader.readMessage(value,proto.pb.Payload.deserializeBinaryFromReader); 396 | msg.setPayload(value); 397 | break; 398 | case 2: 399 | var value = /** @type {number} */ (reader.readUint64()); 400 | msg.setNonce(value); 401 | break; 402 | case 3: 403 | var value = /** @type {number} */ (reader.readInt64()); 404 | msg.setFee(value); 405 | break; 406 | case 4: 407 | var value = /** @type {!Uint8Array} */ (reader.readBytes()); 408 | msg.setAttributes(value); 409 | break; 410 | default: 411 | reader.skipField(); 412 | break; 413 | } 414 | } 415 | return msg; 416 | }; 417 | 418 | 419 | /** 420 | * Serializes the message to binary data (in protobuf wire format). 421 | * @return {!Uint8Array} 422 | */ 423 | proto.pb.UnsignedTx.prototype.serializeBinary = function() { 424 | var writer = new jspb.BinaryWriter(); 425 | proto.pb.UnsignedTx.serializeBinaryToWriter(this, writer); 426 | return writer.getResultBuffer(); 427 | }; 428 | 429 | 430 | /** 431 | * Serializes the given message to binary data (in protobuf wire 432 | * format), writing to the given BinaryWriter. 433 | * @param {!proto.pb.UnsignedTx} message 434 | * @param {!jspb.BinaryWriter} writer 435 | * @suppress {unusedLocalVariables} f is only used for nested messages 436 | */ 437 | proto.pb.UnsignedTx.serializeBinaryToWriter = function(message, writer) { 438 | var f = undefined; 439 | f = message.getPayload(); 440 | if (f != null) { 441 | writer.writeMessage( 442 | 1, 443 | f, 444 | proto.pb.Payload.serializeBinaryToWriter 445 | ); 446 | } 447 | f = message.getNonce(); 448 | if (f !== 0) { 449 | writer.writeUint64( 450 | 2, 451 | f 452 | ); 453 | } 454 | f = message.getFee(); 455 | if (f !== 0) { 456 | writer.writeInt64( 457 | 3, 458 | f 459 | ); 460 | } 461 | f = message.getAttributes_asU8(); 462 | if (f.length > 0) { 463 | writer.writeBytes( 464 | 4, 465 | f 466 | ); 467 | } 468 | }; 469 | 470 | 471 | /** 472 | * optional Payload payload = 1; 473 | * @return {?proto.pb.Payload} 474 | */ 475 | proto.pb.UnsignedTx.prototype.getPayload = function() { 476 | return /** @type{?proto.pb.Payload} */ ( 477 | jspb.Message.getWrapperField(this, proto.pb.Payload, 1)); 478 | }; 479 | 480 | 481 | /** @param {?proto.pb.Payload|undefined} value */ 482 | proto.pb.UnsignedTx.prototype.setPayload = function(value) { 483 | jspb.Message.setWrapperField(this, 1, value); 484 | }; 485 | 486 | 487 | /** 488 | * Clears the message field making it undefined. 489 | */ 490 | proto.pb.UnsignedTx.prototype.clearPayload = function() { 491 | this.setPayload(undefined); 492 | }; 493 | 494 | 495 | /** 496 | * Returns whether this field is set. 497 | * @return {boolean} 498 | */ 499 | proto.pb.UnsignedTx.prototype.hasPayload = function() { 500 | return jspb.Message.getField(this, 1) != null; 501 | }; 502 | 503 | 504 | /** 505 | * optional uint64 nonce = 2; 506 | * @return {number} 507 | */ 508 | proto.pb.UnsignedTx.prototype.getNonce = function() { 509 | return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 2, 0)); 510 | }; 511 | 512 | 513 | /** @param {number} value */ 514 | proto.pb.UnsignedTx.prototype.setNonce = function(value) { 515 | jspb.Message.setProto3IntField(this, 2, value); 516 | }; 517 | 518 | 519 | /** 520 | * optional int64 fee = 3; 521 | * @return {number} 522 | */ 523 | proto.pb.UnsignedTx.prototype.getFee = function() { 524 | return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 3, 0)); 525 | }; 526 | 527 | 528 | /** @param {number} value */ 529 | proto.pb.UnsignedTx.prototype.setFee = function(value) { 530 | jspb.Message.setProto3IntField(this, 3, value); 531 | }; 532 | 533 | 534 | /** 535 | * optional bytes attributes = 4; 536 | * @return {!(string|Uint8Array)} 537 | */ 538 | proto.pb.UnsignedTx.prototype.getAttributes = function() { 539 | return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 4, "")); 540 | }; 541 | 542 | 543 | /** 544 | * optional bytes attributes = 4; 545 | * This is a type-conversion wrapper around `getAttributes()` 546 | * @return {string} 547 | */ 548 | proto.pb.UnsignedTx.prototype.getAttributes_asB64 = function() { 549 | return /** @type {string} */ (jspb.Message.bytesAsB64( 550 | this.getAttributes())); 551 | }; 552 | 553 | 554 | /** 555 | * optional bytes attributes = 4; 556 | * Note that Uint8Array is not supported on all browsers. 557 | * @see http://caniuse.com/Uint8Array 558 | * This is a type-conversion wrapper around `getAttributes()` 559 | * @return {!Uint8Array} 560 | */ 561 | proto.pb.UnsignedTx.prototype.getAttributes_asU8 = function() { 562 | return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( 563 | this.getAttributes())); 564 | }; 565 | 566 | 567 | /** @param {!(string|Uint8Array)} value */ 568 | proto.pb.UnsignedTx.prototype.setAttributes = function(value) { 569 | jspb.Message.setProto3BytesField(this, 4, value); 570 | }; 571 | 572 | 573 | 574 | /** 575 | * List of repeated fields within this message type. 576 | * @private {!Array} 577 | * @const 578 | */ 579 | proto.pb.Transaction.repeatedFields_ = [2]; 580 | 581 | 582 | 583 | if (jspb.Message.GENERATE_TO_OBJECT) { 584 | /** 585 | * Creates an object representation of this proto suitable for use in Soy templates. 586 | * Field names that are reserved in JavaScript and will be renamed to pb_name. 587 | * To access a reserved field use, foo.pb_, eg, foo.pb_default. 588 | * For the list of reserved names please see: 589 | * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. 590 | * @param {boolean=} opt_includeInstance Whether to include the JSPB instance 591 | * for transitional soy proto support: http://goto/soy-param-migration 592 | * @return {!Object} 593 | */ 594 | proto.pb.Transaction.prototype.toObject = function(opt_includeInstance) { 595 | return proto.pb.Transaction.toObject(opt_includeInstance, this); 596 | }; 597 | 598 | 599 | /** 600 | * Static version of the {@see toObject} method. 601 | * @param {boolean|undefined} includeInstance Whether to include the JSPB 602 | * instance for transitional soy proto support: 603 | * http://goto/soy-param-migration 604 | * @param {!proto.pb.Transaction} msg The msg instance to transform. 605 | * @return {!Object} 606 | * @suppress {unusedLocalVariables} f is only used for nested messages 607 | */ 608 | proto.pb.Transaction.toObject = function(includeInstance, msg) { 609 | var f, obj = { 610 | unsignedTx: (f = msg.getUnsignedTx()) && proto.pb.UnsignedTx.toObject(includeInstance, f), 611 | programsList: jspb.Message.toObjectList(msg.getProgramsList(), 612 | proto.pb.Program.toObject, includeInstance) 613 | }; 614 | 615 | if (includeInstance) { 616 | obj.$jspbMessageInstance = msg; 617 | } 618 | return obj; 619 | }; 620 | } 621 | 622 | 623 | /** 624 | * Deserializes binary data (in protobuf wire format). 625 | * @param {jspb.ByteSource} bytes The bytes to deserialize. 626 | * @return {!proto.pb.Transaction} 627 | */ 628 | proto.pb.Transaction.deserializeBinary = function(bytes) { 629 | var reader = new jspb.BinaryReader(bytes); 630 | var msg = new proto.pb.Transaction; 631 | return proto.pb.Transaction.deserializeBinaryFromReader(msg, reader); 632 | }; 633 | 634 | 635 | /** 636 | * Deserializes binary data (in protobuf wire format) from the 637 | * given reader into the given message object. 638 | * @param {!proto.pb.Transaction} msg The message object to deserialize into. 639 | * @param {!jspb.BinaryReader} reader The BinaryReader to use. 640 | * @return {!proto.pb.Transaction} 641 | */ 642 | proto.pb.Transaction.deserializeBinaryFromReader = function(msg, reader) { 643 | while (reader.nextField()) { 644 | if (reader.isEndGroup()) { 645 | break; 646 | } 647 | var field = reader.getFieldNumber(); 648 | switch (field) { 649 | case 1: 650 | var value = new proto.pb.UnsignedTx; 651 | reader.readMessage(value,proto.pb.UnsignedTx.deserializeBinaryFromReader); 652 | msg.setUnsignedTx(value); 653 | break; 654 | case 2: 655 | var value = new proto.pb.Program; 656 | reader.readMessage(value,proto.pb.Program.deserializeBinaryFromReader); 657 | msg.addPrograms(value); 658 | break; 659 | default: 660 | reader.skipField(); 661 | break; 662 | } 663 | } 664 | return msg; 665 | }; 666 | 667 | 668 | /** 669 | * Serializes the message to binary data (in protobuf wire format). 670 | * @return {!Uint8Array} 671 | */ 672 | proto.pb.Transaction.prototype.serializeBinary = function() { 673 | var writer = new jspb.BinaryWriter(); 674 | proto.pb.Transaction.serializeBinaryToWriter(this, writer); 675 | return writer.getResultBuffer(); 676 | }; 677 | 678 | 679 | /** 680 | * Serializes the given message to binary data (in protobuf wire 681 | * format), writing to the given BinaryWriter. 682 | * @param {!proto.pb.Transaction} message 683 | * @param {!jspb.BinaryWriter} writer 684 | * @suppress {unusedLocalVariables} f is only used for nested messages 685 | */ 686 | proto.pb.Transaction.serializeBinaryToWriter = function(message, writer) { 687 | var f = undefined; 688 | f = message.getUnsignedTx(); 689 | if (f != null) { 690 | writer.writeMessage( 691 | 1, 692 | f, 693 | proto.pb.UnsignedTx.serializeBinaryToWriter 694 | ); 695 | } 696 | f = message.getProgramsList(); 697 | if (f.length > 0) { 698 | writer.writeRepeatedMessage( 699 | 2, 700 | f, 701 | proto.pb.Program.serializeBinaryToWriter 702 | ); 703 | } 704 | }; 705 | 706 | 707 | /** 708 | * optional UnsignedTx unsigned_tx = 1; 709 | * @return {?proto.pb.UnsignedTx} 710 | */ 711 | proto.pb.Transaction.prototype.getUnsignedTx = function() { 712 | return /** @type{?proto.pb.UnsignedTx} */ ( 713 | jspb.Message.getWrapperField(this, proto.pb.UnsignedTx, 1)); 714 | }; 715 | 716 | 717 | /** @param {?proto.pb.UnsignedTx|undefined} value */ 718 | proto.pb.Transaction.prototype.setUnsignedTx = function(value) { 719 | jspb.Message.setWrapperField(this, 1, value); 720 | }; 721 | 722 | 723 | /** 724 | * Clears the message field making it undefined. 725 | */ 726 | proto.pb.Transaction.prototype.clearUnsignedTx = function() { 727 | this.setUnsignedTx(undefined); 728 | }; 729 | 730 | 731 | /** 732 | * Returns whether this field is set. 733 | * @return {boolean} 734 | */ 735 | proto.pb.Transaction.prototype.hasUnsignedTx = function() { 736 | return jspb.Message.getField(this, 1) != null; 737 | }; 738 | 739 | 740 | /** 741 | * repeated Program programs = 2; 742 | * @return {!Array} 743 | */ 744 | proto.pb.Transaction.prototype.getProgramsList = function() { 745 | return /** @type{!Array} */ ( 746 | jspb.Message.getRepeatedWrapperField(this, proto.pb.Program, 2)); 747 | }; 748 | 749 | 750 | /** @param {!Array} value */ 751 | proto.pb.Transaction.prototype.setProgramsList = function(value) { 752 | jspb.Message.setRepeatedWrapperField(this, 2, value); 753 | }; 754 | 755 | 756 | /** 757 | * @param {!proto.pb.Program=} opt_value 758 | * @param {number=} opt_index 759 | * @return {!proto.pb.Program} 760 | */ 761 | proto.pb.Transaction.prototype.addPrograms = function(opt_value, opt_index) { 762 | return jspb.Message.addToRepeatedWrapperField(this, 2, opt_value, proto.pb.Program, opt_index); 763 | }; 764 | 765 | 766 | /** 767 | * Clears the list making it empty but non-null. 768 | */ 769 | proto.pb.Transaction.prototype.clearProgramsList = function() { 770 | this.setProgramsList([]); 771 | }; 772 | 773 | 774 | 775 | 776 | 777 | if (jspb.Message.GENERATE_TO_OBJECT) { 778 | /** 779 | * Creates an object representation of this proto suitable for use in Soy templates. 780 | * Field names that are reserved in JavaScript and will be renamed to pb_name. 781 | * To access a reserved field use, foo.pb_, eg, foo.pb_default. 782 | * For the list of reserved names please see: 783 | * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. 784 | * @param {boolean=} opt_includeInstance Whether to include the JSPB instance 785 | * for transitional soy proto support: http://goto/soy-param-migration 786 | * @return {!Object} 787 | */ 788 | proto.pb.Program.prototype.toObject = function(opt_includeInstance) { 789 | return proto.pb.Program.toObject(opt_includeInstance, this); 790 | }; 791 | 792 | 793 | /** 794 | * Static version of the {@see toObject} method. 795 | * @param {boolean|undefined} includeInstance Whether to include the JSPB 796 | * instance for transitional soy proto support: 797 | * http://goto/soy-param-migration 798 | * @param {!proto.pb.Program} msg The msg instance to transform. 799 | * @return {!Object} 800 | * @suppress {unusedLocalVariables} f is only used for nested messages 801 | */ 802 | proto.pb.Program.toObject = function(includeInstance, msg) { 803 | var f, obj = { 804 | code: msg.getCode_asB64(), 805 | parameter: msg.getParameter_asB64() 806 | }; 807 | 808 | if (includeInstance) { 809 | obj.$jspbMessageInstance = msg; 810 | } 811 | return obj; 812 | }; 813 | } 814 | 815 | 816 | /** 817 | * Deserializes binary data (in protobuf wire format). 818 | * @param {jspb.ByteSource} bytes The bytes to deserialize. 819 | * @return {!proto.pb.Program} 820 | */ 821 | proto.pb.Program.deserializeBinary = function(bytes) { 822 | var reader = new jspb.BinaryReader(bytes); 823 | var msg = new proto.pb.Program; 824 | return proto.pb.Program.deserializeBinaryFromReader(msg, reader); 825 | }; 826 | 827 | 828 | /** 829 | * Deserializes binary data (in protobuf wire format) from the 830 | * given reader into the given message object. 831 | * @param {!proto.pb.Program} msg The message object to deserialize into. 832 | * @param {!jspb.BinaryReader} reader The BinaryReader to use. 833 | * @return {!proto.pb.Program} 834 | */ 835 | proto.pb.Program.deserializeBinaryFromReader = function(msg, reader) { 836 | while (reader.nextField()) { 837 | if (reader.isEndGroup()) { 838 | break; 839 | } 840 | var field = reader.getFieldNumber(); 841 | switch (field) { 842 | case 1: 843 | var value = /** @type {!Uint8Array} */ (reader.readBytes()); 844 | msg.setCode(value); 845 | break; 846 | case 2: 847 | var value = /** @type {!Uint8Array} */ (reader.readBytes()); 848 | msg.setParameter(value); 849 | break; 850 | default: 851 | reader.skipField(); 852 | break; 853 | } 854 | } 855 | return msg; 856 | }; 857 | 858 | 859 | /** 860 | * Serializes the message to binary data (in protobuf wire format). 861 | * @return {!Uint8Array} 862 | */ 863 | proto.pb.Program.prototype.serializeBinary = function() { 864 | var writer = new jspb.BinaryWriter(); 865 | proto.pb.Program.serializeBinaryToWriter(this, writer); 866 | return writer.getResultBuffer(); 867 | }; 868 | 869 | 870 | /** 871 | * Serializes the given message to binary data (in protobuf wire 872 | * format), writing to the given BinaryWriter. 873 | * @param {!proto.pb.Program} message 874 | * @param {!jspb.BinaryWriter} writer 875 | * @suppress {unusedLocalVariables} f is only used for nested messages 876 | */ 877 | proto.pb.Program.serializeBinaryToWriter = function(message, writer) { 878 | var f = undefined; 879 | f = message.getCode_asU8(); 880 | if (f.length > 0) { 881 | writer.writeBytes( 882 | 1, 883 | f 884 | ); 885 | } 886 | f = message.getParameter_asU8(); 887 | if (f.length > 0) { 888 | writer.writeBytes( 889 | 2, 890 | f 891 | ); 892 | } 893 | }; 894 | 895 | 896 | /** 897 | * optional bytes code = 1; 898 | * @return {!(string|Uint8Array)} 899 | */ 900 | proto.pb.Program.prototype.getCode = function() { 901 | return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 1, "")); 902 | }; 903 | 904 | 905 | /** 906 | * optional bytes code = 1; 907 | * This is a type-conversion wrapper around `getCode()` 908 | * @return {string} 909 | */ 910 | proto.pb.Program.prototype.getCode_asB64 = function() { 911 | return /** @type {string} */ (jspb.Message.bytesAsB64( 912 | this.getCode())); 913 | }; 914 | 915 | 916 | /** 917 | * optional bytes code = 1; 918 | * Note that Uint8Array is not supported on all browsers. 919 | * @see http://caniuse.com/Uint8Array 920 | * This is a type-conversion wrapper around `getCode()` 921 | * @return {!Uint8Array} 922 | */ 923 | proto.pb.Program.prototype.getCode_asU8 = function() { 924 | return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( 925 | this.getCode())); 926 | }; 927 | 928 | 929 | /** @param {!(string|Uint8Array)} value */ 930 | proto.pb.Program.prototype.setCode = function(value) { 931 | jspb.Message.setProto3BytesField(this, 1, value); 932 | }; 933 | 934 | 935 | /** 936 | * optional bytes parameter = 2; 937 | * @return {!(string|Uint8Array)} 938 | */ 939 | proto.pb.Program.prototype.getParameter = function() { 940 | return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 2, "")); 941 | }; 942 | 943 | 944 | /** 945 | * optional bytes parameter = 2; 946 | * This is a type-conversion wrapper around `getParameter()` 947 | * @return {string} 948 | */ 949 | proto.pb.Program.prototype.getParameter_asB64 = function() { 950 | return /** @type {string} */ (jspb.Message.bytesAsB64( 951 | this.getParameter())); 952 | }; 953 | 954 | 955 | /** 956 | * optional bytes parameter = 2; 957 | * Note that Uint8Array is not supported on all browsers. 958 | * @see http://caniuse.com/Uint8Array 959 | * This is a type-conversion wrapper around `getParameter()` 960 | * @return {!Uint8Array} 961 | */ 962 | proto.pb.Program.prototype.getParameter_asU8 = function() { 963 | return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( 964 | this.getParameter())); 965 | }; 966 | 967 | 968 | /** @param {!(string|Uint8Array)} value */ 969 | proto.pb.Program.prototype.setParameter = function(value) { 970 | jspb.Message.setProto3BytesField(this, 2, value); 971 | }; 972 | 973 | 974 | 975 | 976 | 977 | if (jspb.Message.GENERATE_TO_OBJECT) { 978 | /** 979 | * Creates an object representation of this proto suitable for use in Soy templates. 980 | * Field names that are reserved in JavaScript and will be renamed to pb_name. 981 | * To access a reserved field use, foo.pb_, eg, foo.pb_default. 982 | * For the list of reserved names please see: 983 | * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. 984 | * @param {boolean=} opt_includeInstance Whether to include the JSPB instance 985 | * for transitional soy proto support: http://goto/soy-param-migration 986 | * @return {!Object} 987 | */ 988 | proto.pb.Payload.prototype.toObject = function(opt_includeInstance) { 989 | return proto.pb.Payload.toObject(opt_includeInstance, this); 990 | }; 991 | 992 | 993 | /** 994 | * Static version of the {@see toObject} method. 995 | * @param {boolean|undefined} includeInstance Whether to include the JSPB 996 | * instance for transitional soy proto support: 997 | * http://goto/soy-param-migration 998 | * @param {!proto.pb.Payload} msg The msg instance to transform. 999 | * @return {!Object} 1000 | * @suppress {unusedLocalVariables} f is only used for nested messages 1001 | */ 1002 | proto.pb.Payload.toObject = function(includeInstance, msg) { 1003 | var f, obj = { 1004 | type: jspb.Message.getFieldWithDefault(msg, 1, 0), 1005 | data: msg.getData_asB64() 1006 | }; 1007 | 1008 | if (includeInstance) { 1009 | obj.$jspbMessageInstance = msg; 1010 | } 1011 | return obj; 1012 | }; 1013 | } 1014 | 1015 | 1016 | /** 1017 | * Deserializes binary data (in protobuf wire format). 1018 | * @param {jspb.ByteSource} bytes The bytes to deserialize. 1019 | * @return {!proto.pb.Payload} 1020 | */ 1021 | proto.pb.Payload.deserializeBinary = function(bytes) { 1022 | var reader = new jspb.BinaryReader(bytes); 1023 | var msg = new proto.pb.Payload; 1024 | return proto.pb.Payload.deserializeBinaryFromReader(msg, reader); 1025 | }; 1026 | 1027 | 1028 | /** 1029 | * Deserializes binary data (in protobuf wire format) from the 1030 | * given reader into the given message object. 1031 | * @param {!proto.pb.Payload} msg The message object to deserialize into. 1032 | * @param {!jspb.BinaryReader} reader The BinaryReader to use. 1033 | * @return {!proto.pb.Payload} 1034 | */ 1035 | proto.pb.Payload.deserializeBinaryFromReader = function(msg, reader) { 1036 | while (reader.nextField()) { 1037 | if (reader.isEndGroup()) { 1038 | break; 1039 | } 1040 | var field = reader.getFieldNumber(); 1041 | switch (field) { 1042 | case 1: 1043 | var value = /** @type {!proto.pb.PayloadType} */ (reader.readEnum()); 1044 | msg.setType(value); 1045 | break; 1046 | case 2: 1047 | var value = /** @type {!Uint8Array} */ (reader.readBytes()); 1048 | msg.setData(value); 1049 | break; 1050 | default: 1051 | reader.skipField(); 1052 | break; 1053 | } 1054 | } 1055 | return msg; 1056 | }; 1057 | 1058 | 1059 | /** 1060 | * Serializes the message to binary data (in protobuf wire format). 1061 | * @return {!Uint8Array} 1062 | */ 1063 | proto.pb.Payload.prototype.serializeBinary = function() { 1064 | var writer = new jspb.BinaryWriter(); 1065 | proto.pb.Payload.serializeBinaryToWriter(this, writer); 1066 | return writer.getResultBuffer(); 1067 | }; 1068 | 1069 | 1070 | /** 1071 | * Serializes the given message to binary data (in protobuf wire 1072 | * format), writing to the given BinaryWriter. 1073 | * @param {!proto.pb.Payload} message 1074 | * @param {!jspb.BinaryWriter} writer 1075 | * @suppress {unusedLocalVariables} f is only used for nested messages 1076 | */ 1077 | proto.pb.Payload.serializeBinaryToWriter = function(message, writer) { 1078 | var f = undefined; 1079 | f = message.getType(); 1080 | if (f !== 0.0) { 1081 | writer.writeEnum( 1082 | 1, 1083 | f 1084 | ); 1085 | } 1086 | f = message.getData_asU8(); 1087 | if (f.length > 0) { 1088 | writer.writeBytes( 1089 | 2, 1090 | f 1091 | ); 1092 | } 1093 | }; 1094 | 1095 | 1096 | /** 1097 | * optional PayloadType type = 1; 1098 | * @return {!proto.pb.PayloadType} 1099 | */ 1100 | proto.pb.Payload.prototype.getType = function() { 1101 | return /** @type {!proto.pb.PayloadType} */ (jspb.Message.getFieldWithDefault(this, 1, 0)); 1102 | }; 1103 | 1104 | 1105 | /** @param {!proto.pb.PayloadType} value */ 1106 | proto.pb.Payload.prototype.setType = function(value) { 1107 | jspb.Message.setProto3EnumField(this, 1, value); 1108 | }; 1109 | 1110 | 1111 | /** 1112 | * optional bytes data = 2; 1113 | * @return {!(string|Uint8Array)} 1114 | */ 1115 | proto.pb.Payload.prototype.getData = function() { 1116 | return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 2, "")); 1117 | }; 1118 | 1119 | 1120 | /** 1121 | * optional bytes data = 2; 1122 | * This is a type-conversion wrapper around `getData()` 1123 | * @return {string} 1124 | */ 1125 | proto.pb.Payload.prototype.getData_asB64 = function() { 1126 | return /** @type {string} */ (jspb.Message.bytesAsB64( 1127 | this.getData())); 1128 | }; 1129 | 1130 | 1131 | /** 1132 | * optional bytes data = 2; 1133 | * Note that Uint8Array is not supported on all browsers. 1134 | * @see http://caniuse.com/Uint8Array 1135 | * This is a type-conversion wrapper around `getData()` 1136 | * @return {!Uint8Array} 1137 | */ 1138 | proto.pb.Payload.prototype.getData_asU8 = function() { 1139 | return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( 1140 | this.getData())); 1141 | }; 1142 | 1143 | 1144 | /** @param {!(string|Uint8Array)} value */ 1145 | proto.pb.Payload.prototype.setData = function(value) { 1146 | jspb.Message.setProto3BytesField(this, 2, value); 1147 | }; 1148 | 1149 | 1150 | 1151 | 1152 | 1153 | if (jspb.Message.GENERATE_TO_OBJECT) { 1154 | /** 1155 | * Creates an object representation of this proto suitable for use in Soy templates. 1156 | * Field names that are reserved in JavaScript and will be renamed to pb_name. 1157 | * To access a reserved field use, foo.pb_, eg, foo.pb_default. 1158 | * For the list of reserved names please see: 1159 | * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. 1160 | * @param {boolean=} opt_includeInstance Whether to include the JSPB instance 1161 | * for transitional soy proto support: http://goto/soy-param-migration 1162 | * @return {!Object} 1163 | */ 1164 | proto.pb.Coinbase.prototype.toObject = function(opt_includeInstance) { 1165 | return proto.pb.Coinbase.toObject(opt_includeInstance, this); 1166 | }; 1167 | 1168 | 1169 | /** 1170 | * Static version of the {@see toObject} method. 1171 | * @param {boolean|undefined} includeInstance Whether to include the JSPB 1172 | * instance for transitional soy proto support: 1173 | * http://goto/soy-param-migration 1174 | * @param {!proto.pb.Coinbase} msg The msg instance to transform. 1175 | * @return {!Object} 1176 | * @suppress {unusedLocalVariables} f is only used for nested messages 1177 | */ 1178 | proto.pb.Coinbase.toObject = function(includeInstance, msg) { 1179 | var f, obj = { 1180 | sender: msg.getSender_asB64(), 1181 | recipient: msg.getRecipient_asB64(), 1182 | amount: jspb.Message.getFieldWithDefault(msg, 3, 0) 1183 | }; 1184 | 1185 | if (includeInstance) { 1186 | obj.$jspbMessageInstance = msg; 1187 | } 1188 | return obj; 1189 | }; 1190 | } 1191 | 1192 | 1193 | /** 1194 | * Deserializes binary data (in protobuf wire format). 1195 | * @param {jspb.ByteSource} bytes The bytes to deserialize. 1196 | * @return {!proto.pb.Coinbase} 1197 | */ 1198 | proto.pb.Coinbase.deserializeBinary = function(bytes) { 1199 | var reader = new jspb.BinaryReader(bytes); 1200 | var msg = new proto.pb.Coinbase; 1201 | return proto.pb.Coinbase.deserializeBinaryFromReader(msg, reader); 1202 | }; 1203 | 1204 | 1205 | /** 1206 | * Deserializes binary data (in protobuf wire format) from the 1207 | * given reader into the given message object. 1208 | * @param {!proto.pb.Coinbase} msg The message object to deserialize into. 1209 | * @param {!jspb.BinaryReader} reader The BinaryReader to use. 1210 | * @return {!proto.pb.Coinbase} 1211 | */ 1212 | proto.pb.Coinbase.deserializeBinaryFromReader = function(msg, reader) { 1213 | while (reader.nextField()) { 1214 | if (reader.isEndGroup()) { 1215 | break; 1216 | } 1217 | var field = reader.getFieldNumber(); 1218 | switch (field) { 1219 | case 1: 1220 | var value = /** @type {!Uint8Array} */ (reader.readBytes()); 1221 | msg.setSender(value); 1222 | break; 1223 | case 2: 1224 | var value = /** @type {!Uint8Array} */ (reader.readBytes()); 1225 | msg.setRecipient(value); 1226 | break; 1227 | case 3: 1228 | var value = /** @type {number} */ (reader.readInt64()); 1229 | msg.setAmount(value); 1230 | break; 1231 | default: 1232 | reader.skipField(); 1233 | break; 1234 | } 1235 | } 1236 | return msg; 1237 | }; 1238 | 1239 | 1240 | /** 1241 | * Serializes the message to binary data (in protobuf wire format). 1242 | * @return {!Uint8Array} 1243 | */ 1244 | proto.pb.Coinbase.prototype.serializeBinary = function() { 1245 | var writer = new jspb.BinaryWriter(); 1246 | proto.pb.Coinbase.serializeBinaryToWriter(this, writer); 1247 | return writer.getResultBuffer(); 1248 | }; 1249 | 1250 | 1251 | /** 1252 | * Serializes the given message to binary data (in protobuf wire 1253 | * format), writing to the given BinaryWriter. 1254 | * @param {!proto.pb.Coinbase} message 1255 | * @param {!jspb.BinaryWriter} writer 1256 | * @suppress {unusedLocalVariables} f is only used for nested messages 1257 | */ 1258 | proto.pb.Coinbase.serializeBinaryToWriter = function(message, writer) { 1259 | var f = undefined; 1260 | f = message.getSender_asU8(); 1261 | if (f.length > 0) { 1262 | writer.writeBytes( 1263 | 1, 1264 | f 1265 | ); 1266 | } 1267 | f = message.getRecipient_asU8(); 1268 | if (f.length > 0) { 1269 | writer.writeBytes( 1270 | 2, 1271 | f 1272 | ); 1273 | } 1274 | f = message.getAmount(); 1275 | if (f !== 0) { 1276 | writer.writeInt64( 1277 | 3, 1278 | f 1279 | ); 1280 | } 1281 | }; 1282 | 1283 | 1284 | /** 1285 | * optional bytes sender = 1; 1286 | * @return {!(string|Uint8Array)} 1287 | */ 1288 | proto.pb.Coinbase.prototype.getSender = function() { 1289 | return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 1, "")); 1290 | }; 1291 | 1292 | 1293 | /** 1294 | * optional bytes sender = 1; 1295 | * This is a type-conversion wrapper around `getSender()` 1296 | * @return {string} 1297 | */ 1298 | proto.pb.Coinbase.prototype.getSender_asB64 = function() { 1299 | return /** @type {string} */ (jspb.Message.bytesAsB64( 1300 | this.getSender())); 1301 | }; 1302 | 1303 | 1304 | /** 1305 | * optional bytes sender = 1; 1306 | * Note that Uint8Array is not supported on all browsers. 1307 | * @see http://caniuse.com/Uint8Array 1308 | * This is a type-conversion wrapper around `getSender()` 1309 | * @return {!Uint8Array} 1310 | */ 1311 | proto.pb.Coinbase.prototype.getSender_asU8 = function() { 1312 | return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( 1313 | this.getSender())); 1314 | }; 1315 | 1316 | 1317 | /** @param {!(string|Uint8Array)} value */ 1318 | proto.pb.Coinbase.prototype.setSender = function(value) { 1319 | jspb.Message.setProto3BytesField(this, 1, value); 1320 | }; 1321 | 1322 | 1323 | /** 1324 | * optional bytes recipient = 2; 1325 | * @return {!(string|Uint8Array)} 1326 | */ 1327 | proto.pb.Coinbase.prototype.getRecipient = function() { 1328 | return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 2, "")); 1329 | }; 1330 | 1331 | 1332 | /** 1333 | * optional bytes recipient = 2; 1334 | * This is a type-conversion wrapper around `getRecipient()` 1335 | * @return {string} 1336 | */ 1337 | proto.pb.Coinbase.prototype.getRecipient_asB64 = function() { 1338 | return /** @type {string} */ (jspb.Message.bytesAsB64( 1339 | this.getRecipient())); 1340 | }; 1341 | 1342 | 1343 | /** 1344 | * optional bytes recipient = 2; 1345 | * Note that Uint8Array is not supported on all browsers. 1346 | * @see http://caniuse.com/Uint8Array 1347 | * This is a type-conversion wrapper around `getRecipient()` 1348 | * @return {!Uint8Array} 1349 | */ 1350 | proto.pb.Coinbase.prototype.getRecipient_asU8 = function() { 1351 | return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( 1352 | this.getRecipient())); 1353 | }; 1354 | 1355 | 1356 | /** @param {!(string|Uint8Array)} value */ 1357 | proto.pb.Coinbase.prototype.setRecipient = function(value) { 1358 | jspb.Message.setProto3BytesField(this, 2, value); 1359 | }; 1360 | 1361 | 1362 | /** 1363 | * optional int64 amount = 3; 1364 | * @return {number} 1365 | */ 1366 | proto.pb.Coinbase.prototype.getAmount = function() { 1367 | return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 3, 0)); 1368 | }; 1369 | 1370 | 1371 | /** @param {number} value */ 1372 | proto.pb.Coinbase.prototype.setAmount = function(value) { 1373 | jspb.Message.setProto3IntField(this, 3, value); 1374 | }; 1375 | 1376 | 1377 | 1378 | 1379 | 1380 | if (jspb.Message.GENERATE_TO_OBJECT) { 1381 | /** 1382 | * Creates an object representation of this proto suitable for use in Soy templates. 1383 | * Field names that are reserved in JavaScript and will be renamed to pb_name. 1384 | * To access a reserved field use, foo.pb_, eg, foo.pb_default. 1385 | * For the list of reserved names please see: 1386 | * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. 1387 | * @param {boolean=} opt_includeInstance Whether to include the JSPB instance 1388 | * for transitional soy proto support: http://goto/soy-param-migration 1389 | * @return {!Object} 1390 | */ 1391 | proto.pb.SigChainTxn.prototype.toObject = function(opt_includeInstance) { 1392 | return proto.pb.SigChainTxn.toObject(opt_includeInstance, this); 1393 | }; 1394 | 1395 | 1396 | /** 1397 | * Static version of the {@see toObject} method. 1398 | * @param {boolean|undefined} includeInstance Whether to include the JSPB 1399 | * instance for transitional soy proto support: 1400 | * http://goto/soy-param-migration 1401 | * @param {!proto.pb.SigChainTxn} msg The msg instance to transform. 1402 | * @return {!Object} 1403 | * @suppress {unusedLocalVariables} f is only used for nested messages 1404 | */ 1405 | proto.pb.SigChainTxn.toObject = function(includeInstance, msg) { 1406 | var f, obj = { 1407 | sigchain: msg.getSigchain_asB64(), 1408 | submitter: msg.getSubmitter_asB64() 1409 | }; 1410 | 1411 | if (includeInstance) { 1412 | obj.$jspbMessageInstance = msg; 1413 | } 1414 | return obj; 1415 | }; 1416 | } 1417 | 1418 | 1419 | /** 1420 | * Deserializes binary data (in protobuf wire format). 1421 | * @param {jspb.ByteSource} bytes The bytes to deserialize. 1422 | * @return {!proto.pb.SigChainTxn} 1423 | */ 1424 | proto.pb.SigChainTxn.deserializeBinary = function(bytes) { 1425 | var reader = new jspb.BinaryReader(bytes); 1426 | var msg = new proto.pb.SigChainTxn; 1427 | return proto.pb.SigChainTxn.deserializeBinaryFromReader(msg, reader); 1428 | }; 1429 | 1430 | 1431 | /** 1432 | * Deserializes binary data (in protobuf wire format) from the 1433 | * given reader into the given message object. 1434 | * @param {!proto.pb.SigChainTxn} msg The message object to deserialize into. 1435 | * @param {!jspb.BinaryReader} reader The BinaryReader to use. 1436 | * @return {!proto.pb.SigChainTxn} 1437 | */ 1438 | proto.pb.SigChainTxn.deserializeBinaryFromReader = function(msg, reader) { 1439 | while (reader.nextField()) { 1440 | if (reader.isEndGroup()) { 1441 | break; 1442 | } 1443 | var field = reader.getFieldNumber(); 1444 | switch (field) { 1445 | case 1: 1446 | var value = /** @type {!Uint8Array} */ (reader.readBytes()); 1447 | msg.setSigchain(value); 1448 | break; 1449 | case 2: 1450 | var value = /** @type {!Uint8Array} */ (reader.readBytes()); 1451 | msg.setSubmitter(value); 1452 | break; 1453 | default: 1454 | reader.skipField(); 1455 | break; 1456 | } 1457 | } 1458 | return msg; 1459 | }; 1460 | 1461 | 1462 | /** 1463 | * Serializes the message to binary data (in protobuf wire format). 1464 | * @return {!Uint8Array} 1465 | */ 1466 | proto.pb.SigChainTxn.prototype.serializeBinary = function() { 1467 | var writer = new jspb.BinaryWriter(); 1468 | proto.pb.SigChainTxn.serializeBinaryToWriter(this, writer); 1469 | return writer.getResultBuffer(); 1470 | }; 1471 | 1472 | 1473 | /** 1474 | * Serializes the given message to binary data (in protobuf wire 1475 | * format), writing to the given BinaryWriter. 1476 | * @param {!proto.pb.SigChainTxn} message 1477 | * @param {!jspb.BinaryWriter} writer 1478 | * @suppress {unusedLocalVariables} f is only used for nested messages 1479 | */ 1480 | proto.pb.SigChainTxn.serializeBinaryToWriter = function(message, writer) { 1481 | var f = undefined; 1482 | f = message.getSigchain_asU8(); 1483 | if (f.length > 0) { 1484 | writer.writeBytes( 1485 | 1, 1486 | f 1487 | ); 1488 | } 1489 | f = message.getSubmitter_asU8(); 1490 | if (f.length > 0) { 1491 | writer.writeBytes( 1492 | 2, 1493 | f 1494 | ); 1495 | } 1496 | }; 1497 | 1498 | 1499 | /** 1500 | * optional bytes sigChain = 1; 1501 | * @return {!(string|Uint8Array)} 1502 | */ 1503 | proto.pb.SigChainTxn.prototype.getSigchain = function() { 1504 | return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 1, "")); 1505 | }; 1506 | 1507 | 1508 | /** 1509 | * optional bytes sigChain = 1; 1510 | * This is a type-conversion wrapper around `getSigchain()` 1511 | * @return {string} 1512 | */ 1513 | proto.pb.SigChainTxn.prototype.getSigchain_asB64 = function() { 1514 | return /** @type {string} */ (jspb.Message.bytesAsB64( 1515 | this.getSigchain())); 1516 | }; 1517 | 1518 | 1519 | /** 1520 | * optional bytes sigChain = 1; 1521 | * Note that Uint8Array is not supported on all browsers. 1522 | * @see http://caniuse.com/Uint8Array 1523 | * This is a type-conversion wrapper around `getSigchain()` 1524 | * @return {!Uint8Array} 1525 | */ 1526 | proto.pb.SigChainTxn.prototype.getSigchain_asU8 = function() { 1527 | return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( 1528 | this.getSigchain())); 1529 | }; 1530 | 1531 | 1532 | /** @param {!(string|Uint8Array)} value */ 1533 | proto.pb.SigChainTxn.prototype.setSigchain = function(value) { 1534 | jspb.Message.setProto3BytesField(this, 1, value); 1535 | }; 1536 | 1537 | 1538 | /** 1539 | * optional bytes submitter = 2; 1540 | * @return {!(string|Uint8Array)} 1541 | */ 1542 | proto.pb.SigChainTxn.prototype.getSubmitter = function() { 1543 | return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 2, "")); 1544 | }; 1545 | 1546 | 1547 | /** 1548 | * optional bytes submitter = 2; 1549 | * This is a type-conversion wrapper around `getSubmitter()` 1550 | * @return {string} 1551 | */ 1552 | proto.pb.SigChainTxn.prototype.getSubmitter_asB64 = function() { 1553 | return /** @type {string} */ (jspb.Message.bytesAsB64( 1554 | this.getSubmitter())); 1555 | }; 1556 | 1557 | 1558 | /** 1559 | * optional bytes submitter = 2; 1560 | * Note that Uint8Array is not supported on all browsers. 1561 | * @see http://caniuse.com/Uint8Array 1562 | * This is a type-conversion wrapper around `getSubmitter()` 1563 | * @return {!Uint8Array} 1564 | */ 1565 | proto.pb.SigChainTxn.prototype.getSubmitter_asU8 = function() { 1566 | return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( 1567 | this.getSubmitter())); 1568 | }; 1569 | 1570 | 1571 | /** @param {!(string|Uint8Array)} value */ 1572 | proto.pb.SigChainTxn.prototype.setSubmitter = function(value) { 1573 | jspb.Message.setProto3BytesField(this, 2, value); 1574 | }; 1575 | 1576 | 1577 | 1578 | 1579 | 1580 | if (jspb.Message.GENERATE_TO_OBJECT) { 1581 | /** 1582 | * Creates an object representation of this proto suitable for use in Soy templates. 1583 | * Field names that are reserved in JavaScript and will be renamed to pb_name. 1584 | * To access a reserved field use, foo.pb_, eg, foo.pb_default. 1585 | * For the list of reserved names please see: 1586 | * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. 1587 | * @param {boolean=} opt_includeInstance Whether to include the JSPB instance 1588 | * for transitional soy proto support: http://goto/soy-param-migration 1589 | * @return {!Object} 1590 | */ 1591 | proto.pb.RegisterName.prototype.toObject = function(opt_includeInstance) { 1592 | return proto.pb.RegisterName.toObject(opt_includeInstance, this); 1593 | }; 1594 | 1595 | 1596 | /** 1597 | * Static version of the {@see toObject} method. 1598 | * @param {boolean|undefined} includeInstance Whether to include the JSPB 1599 | * instance for transitional soy proto support: 1600 | * http://goto/soy-param-migration 1601 | * @param {!proto.pb.RegisterName} msg The msg instance to transform. 1602 | * @return {!Object} 1603 | * @suppress {unusedLocalVariables} f is only used for nested messages 1604 | */ 1605 | proto.pb.RegisterName.toObject = function(includeInstance, msg) { 1606 | var f, obj = { 1607 | registrant: msg.getRegistrant_asB64(), 1608 | name: jspb.Message.getFieldWithDefault(msg, 2, "") 1609 | }; 1610 | 1611 | if (includeInstance) { 1612 | obj.$jspbMessageInstance = msg; 1613 | } 1614 | return obj; 1615 | }; 1616 | } 1617 | 1618 | 1619 | /** 1620 | * Deserializes binary data (in protobuf wire format). 1621 | * @param {jspb.ByteSource} bytes The bytes to deserialize. 1622 | * @return {!proto.pb.RegisterName} 1623 | */ 1624 | proto.pb.RegisterName.deserializeBinary = function(bytes) { 1625 | var reader = new jspb.BinaryReader(bytes); 1626 | var msg = new proto.pb.RegisterName; 1627 | return proto.pb.RegisterName.deserializeBinaryFromReader(msg, reader); 1628 | }; 1629 | 1630 | 1631 | /** 1632 | * Deserializes binary data (in protobuf wire format) from the 1633 | * given reader into the given message object. 1634 | * @param {!proto.pb.RegisterName} msg The message object to deserialize into. 1635 | * @param {!jspb.BinaryReader} reader The BinaryReader to use. 1636 | * @return {!proto.pb.RegisterName} 1637 | */ 1638 | proto.pb.RegisterName.deserializeBinaryFromReader = function(msg, reader) { 1639 | while (reader.nextField()) { 1640 | if (reader.isEndGroup()) { 1641 | break; 1642 | } 1643 | var field = reader.getFieldNumber(); 1644 | switch (field) { 1645 | case 1: 1646 | var value = /** @type {!Uint8Array} */ (reader.readBytes()); 1647 | msg.setRegistrant(value); 1648 | break; 1649 | case 2: 1650 | var value = /** @type {string} */ (reader.readString()); 1651 | msg.setName(value); 1652 | break; 1653 | default: 1654 | reader.skipField(); 1655 | break; 1656 | } 1657 | } 1658 | return msg; 1659 | }; 1660 | 1661 | 1662 | /** 1663 | * Serializes the message to binary data (in protobuf wire format). 1664 | * @return {!Uint8Array} 1665 | */ 1666 | proto.pb.RegisterName.prototype.serializeBinary = function() { 1667 | var writer = new jspb.BinaryWriter(); 1668 | proto.pb.RegisterName.serializeBinaryToWriter(this, writer); 1669 | return writer.getResultBuffer(); 1670 | }; 1671 | 1672 | 1673 | /** 1674 | * Serializes the given message to binary data (in protobuf wire 1675 | * format), writing to the given BinaryWriter. 1676 | * @param {!proto.pb.RegisterName} message 1677 | * @param {!jspb.BinaryWriter} writer 1678 | * @suppress {unusedLocalVariables} f is only used for nested messages 1679 | */ 1680 | proto.pb.RegisterName.serializeBinaryToWriter = function(message, writer) { 1681 | var f = undefined; 1682 | f = message.getRegistrant_asU8(); 1683 | if (f.length > 0) { 1684 | writer.writeBytes( 1685 | 1, 1686 | f 1687 | ); 1688 | } 1689 | f = message.getName(); 1690 | if (f.length > 0) { 1691 | writer.writeString( 1692 | 2, 1693 | f 1694 | ); 1695 | } 1696 | }; 1697 | 1698 | 1699 | /** 1700 | * optional bytes registrant = 1; 1701 | * @return {!(string|Uint8Array)} 1702 | */ 1703 | proto.pb.RegisterName.prototype.getRegistrant = function() { 1704 | return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 1, "")); 1705 | }; 1706 | 1707 | 1708 | /** 1709 | * optional bytes registrant = 1; 1710 | * This is a type-conversion wrapper around `getRegistrant()` 1711 | * @return {string} 1712 | */ 1713 | proto.pb.RegisterName.prototype.getRegistrant_asB64 = function() { 1714 | return /** @type {string} */ (jspb.Message.bytesAsB64( 1715 | this.getRegistrant())); 1716 | }; 1717 | 1718 | 1719 | /** 1720 | * optional bytes registrant = 1; 1721 | * Note that Uint8Array is not supported on all browsers. 1722 | * @see http://caniuse.com/Uint8Array 1723 | * This is a type-conversion wrapper around `getRegistrant()` 1724 | * @return {!Uint8Array} 1725 | */ 1726 | proto.pb.RegisterName.prototype.getRegistrant_asU8 = function() { 1727 | return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( 1728 | this.getRegistrant())); 1729 | }; 1730 | 1731 | 1732 | /** @param {!(string|Uint8Array)} value */ 1733 | proto.pb.RegisterName.prototype.setRegistrant = function(value) { 1734 | jspb.Message.setProto3BytesField(this, 1, value); 1735 | }; 1736 | 1737 | 1738 | /** 1739 | * optional string name = 2; 1740 | * @return {string} 1741 | */ 1742 | proto.pb.RegisterName.prototype.getName = function() { 1743 | return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, "")); 1744 | }; 1745 | 1746 | 1747 | /** @param {string} value */ 1748 | proto.pb.RegisterName.prototype.setName = function(value) { 1749 | jspb.Message.setProto3StringField(this, 2, value); 1750 | }; 1751 | 1752 | 1753 | 1754 | 1755 | 1756 | if (jspb.Message.GENERATE_TO_OBJECT) { 1757 | /** 1758 | * Creates an object representation of this proto suitable for use in Soy templates. 1759 | * Field names that are reserved in JavaScript and will be renamed to pb_name. 1760 | * To access a reserved field use, foo.pb_, eg, foo.pb_default. 1761 | * For the list of reserved names please see: 1762 | * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. 1763 | * @param {boolean=} opt_includeInstance Whether to include the JSPB instance 1764 | * for transitional soy proto support: http://goto/soy-param-migration 1765 | * @return {!Object} 1766 | */ 1767 | proto.pb.DeleteName.prototype.toObject = function(opt_includeInstance) { 1768 | return proto.pb.DeleteName.toObject(opt_includeInstance, this); 1769 | }; 1770 | 1771 | 1772 | /** 1773 | * Static version of the {@see toObject} method. 1774 | * @param {boolean|undefined} includeInstance Whether to include the JSPB 1775 | * instance for transitional soy proto support: 1776 | * http://goto/soy-param-migration 1777 | * @param {!proto.pb.DeleteName} msg The msg instance to transform. 1778 | * @return {!Object} 1779 | * @suppress {unusedLocalVariables} f is only used for nested messages 1780 | */ 1781 | proto.pb.DeleteName.toObject = function(includeInstance, msg) { 1782 | var f, obj = { 1783 | registrant: msg.getRegistrant_asB64(), 1784 | name: jspb.Message.getFieldWithDefault(msg, 2, "") 1785 | }; 1786 | 1787 | if (includeInstance) { 1788 | obj.$jspbMessageInstance = msg; 1789 | } 1790 | return obj; 1791 | }; 1792 | } 1793 | 1794 | 1795 | /** 1796 | * Deserializes binary data (in protobuf wire format). 1797 | * @param {jspb.ByteSource} bytes The bytes to deserialize. 1798 | * @return {!proto.pb.DeleteName} 1799 | */ 1800 | proto.pb.DeleteName.deserializeBinary = function(bytes) { 1801 | var reader = new jspb.BinaryReader(bytes); 1802 | var msg = new proto.pb.DeleteName; 1803 | return proto.pb.DeleteName.deserializeBinaryFromReader(msg, reader); 1804 | }; 1805 | 1806 | 1807 | /** 1808 | * Deserializes binary data (in protobuf wire format) from the 1809 | * given reader into the given message object. 1810 | * @param {!proto.pb.DeleteName} msg The message object to deserialize into. 1811 | * @param {!jspb.BinaryReader} reader The BinaryReader to use. 1812 | * @return {!proto.pb.DeleteName} 1813 | */ 1814 | proto.pb.DeleteName.deserializeBinaryFromReader = function(msg, reader) { 1815 | while (reader.nextField()) { 1816 | if (reader.isEndGroup()) { 1817 | break; 1818 | } 1819 | var field = reader.getFieldNumber(); 1820 | switch (field) { 1821 | case 1: 1822 | var value = /** @type {!Uint8Array} */ (reader.readBytes()); 1823 | msg.setRegistrant(value); 1824 | break; 1825 | case 2: 1826 | var value = /** @type {string} */ (reader.readString()); 1827 | msg.setName(value); 1828 | break; 1829 | default: 1830 | reader.skipField(); 1831 | break; 1832 | } 1833 | } 1834 | return msg; 1835 | }; 1836 | 1837 | 1838 | /** 1839 | * Serializes the message to binary data (in protobuf wire format). 1840 | * @return {!Uint8Array} 1841 | */ 1842 | proto.pb.DeleteName.prototype.serializeBinary = function() { 1843 | var writer = new jspb.BinaryWriter(); 1844 | proto.pb.DeleteName.serializeBinaryToWriter(this, writer); 1845 | return writer.getResultBuffer(); 1846 | }; 1847 | 1848 | 1849 | /** 1850 | * Serializes the given message to binary data (in protobuf wire 1851 | * format), writing to the given BinaryWriter. 1852 | * @param {!proto.pb.DeleteName} message 1853 | * @param {!jspb.BinaryWriter} writer 1854 | * @suppress {unusedLocalVariables} f is only used for nested messages 1855 | */ 1856 | proto.pb.DeleteName.serializeBinaryToWriter = function(message, writer) { 1857 | var f = undefined; 1858 | f = message.getRegistrant_asU8(); 1859 | if (f.length > 0) { 1860 | writer.writeBytes( 1861 | 1, 1862 | f 1863 | ); 1864 | } 1865 | f = message.getName(); 1866 | if (f.length > 0) { 1867 | writer.writeString( 1868 | 2, 1869 | f 1870 | ); 1871 | } 1872 | }; 1873 | 1874 | 1875 | /** 1876 | * optional bytes registrant = 1; 1877 | * @return {!(string|Uint8Array)} 1878 | */ 1879 | proto.pb.DeleteName.prototype.getRegistrant = function() { 1880 | return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 1, "")); 1881 | }; 1882 | 1883 | 1884 | /** 1885 | * optional bytes registrant = 1; 1886 | * This is a type-conversion wrapper around `getRegistrant()` 1887 | * @return {string} 1888 | */ 1889 | proto.pb.DeleteName.prototype.getRegistrant_asB64 = function() { 1890 | return /** @type {string} */ (jspb.Message.bytesAsB64( 1891 | this.getRegistrant())); 1892 | }; 1893 | 1894 | 1895 | /** 1896 | * optional bytes registrant = 1; 1897 | * Note that Uint8Array is not supported on all browsers. 1898 | * @see http://caniuse.com/Uint8Array 1899 | * This is a type-conversion wrapper around `getRegistrant()` 1900 | * @return {!Uint8Array} 1901 | */ 1902 | proto.pb.DeleteName.prototype.getRegistrant_asU8 = function() { 1903 | return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( 1904 | this.getRegistrant())); 1905 | }; 1906 | 1907 | 1908 | /** @param {!(string|Uint8Array)} value */ 1909 | proto.pb.DeleteName.prototype.setRegistrant = function(value) { 1910 | jspb.Message.setProto3BytesField(this, 1, value); 1911 | }; 1912 | 1913 | 1914 | /** 1915 | * optional string name = 2; 1916 | * @return {string} 1917 | */ 1918 | proto.pb.DeleteName.prototype.getName = function() { 1919 | return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, "")); 1920 | }; 1921 | 1922 | 1923 | /** @param {string} value */ 1924 | proto.pb.DeleteName.prototype.setName = function(value) { 1925 | jspb.Message.setProto3StringField(this, 2, value); 1926 | }; 1927 | 1928 | 1929 | 1930 | 1931 | 1932 | if (jspb.Message.GENERATE_TO_OBJECT) { 1933 | /** 1934 | * Creates an object representation of this proto suitable for use in Soy templates. 1935 | * Field names that are reserved in JavaScript and will be renamed to pb_name. 1936 | * To access a reserved field use, foo.pb_, eg, foo.pb_default. 1937 | * For the list of reserved names please see: 1938 | * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. 1939 | * @param {boolean=} opt_includeInstance Whether to include the JSPB instance 1940 | * for transitional soy proto support: http://goto/soy-param-migration 1941 | * @return {!Object} 1942 | */ 1943 | proto.pb.Subscribe.prototype.toObject = function(opt_includeInstance) { 1944 | return proto.pb.Subscribe.toObject(opt_includeInstance, this); 1945 | }; 1946 | 1947 | 1948 | /** 1949 | * Static version of the {@see toObject} method. 1950 | * @param {boolean|undefined} includeInstance Whether to include the JSPB 1951 | * instance for transitional soy proto support: 1952 | * http://goto/soy-param-migration 1953 | * @param {!proto.pb.Subscribe} msg The msg instance to transform. 1954 | * @return {!Object} 1955 | * @suppress {unusedLocalVariables} f is only used for nested messages 1956 | */ 1957 | proto.pb.Subscribe.toObject = function(includeInstance, msg) { 1958 | var f, obj = { 1959 | subscriber: msg.getSubscriber_asB64(), 1960 | identifier: jspb.Message.getFieldWithDefault(msg, 2, ""), 1961 | topic: jspb.Message.getFieldWithDefault(msg, 3, ""), 1962 | bucket: jspb.Message.getFieldWithDefault(msg, 4, 0), 1963 | duration: jspb.Message.getFieldWithDefault(msg, 5, 0), 1964 | meta: jspb.Message.getFieldWithDefault(msg, 6, "") 1965 | }; 1966 | 1967 | if (includeInstance) { 1968 | obj.$jspbMessageInstance = msg; 1969 | } 1970 | return obj; 1971 | }; 1972 | } 1973 | 1974 | 1975 | /** 1976 | * Deserializes binary data (in protobuf wire format). 1977 | * @param {jspb.ByteSource} bytes The bytes to deserialize. 1978 | * @return {!proto.pb.Subscribe} 1979 | */ 1980 | proto.pb.Subscribe.deserializeBinary = function(bytes) { 1981 | var reader = new jspb.BinaryReader(bytes); 1982 | var msg = new proto.pb.Subscribe; 1983 | return proto.pb.Subscribe.deserializeBinaryFromReader(msg, reader); 1984 | }; 1985 | 1986 | 1987 | /** 1988 | * Deserializes binary data (in protobuf wire format) from the 1989 | * given reader into the given message object. 1990 | * @param {!proto.pb.Subscribe} msg The message object to deserialize into. 1991 | * @param {!jspb.BinaryReader} reader The BinaryReader to use. 1992 | * @return {!proto.pb.Subscribe} 1993 | */ 1994 | proto.pb.Subscribe.deserializeBinaryFromReader = function(msg, reader) { 1995 | while (reader.nextField()) { 1996 | if (reader.isEndGroup()) { 1997 | break; 1998 | } 1999 | var field = reader.getFieldNumber(); 2000 | switch (field) { 2001 | case 1: 2002 | var value = /** @type {!Uint8Array} */ (reader.readBytes()); 2003 | msg.setSubscriber(value); 2004 | break; 2005 | case 2: 2006 | var value = /** @type {string} */ (reader.readString()); 2007 | msg.setIdentifier(value); 2008 | break; 2009 | case 3: 2010 | var value = /** @type {string} */ (reader.readString()); 2011 | msg.setTopic(value); 2012 | break; 2013 | case 4: 2014 | var value = /** @type {number} */ (reader.readUint32()); 2015 | msg.setBucket(value); 2016 | break; 2017 | case 5: 2018 | var value = /** @type {number} */ (reader.readUint32()); 2019 | msg.setDuration(value); 2020 | break; 2021 | case 6: 2022 | var value = /** @type {string} */ (reader.readString()); 2023 | msg.setMeta(value); 2024 | break; 2025 | default: 2026 | reader.skipField(); 2027 | break; 2028 | } 2029 | } 2030 | return msg; 2031 | }; 2032 | 2033 | 2034 | /** 2035 | * Serializes the message to binary data (in protobuf wire format). 2036 | * @return {!Uint8Array} 2037 | */ 2038 | proto.pb.Subscribe.prototype.serializeBinary = function() { 2039 | var writer = new jspb.BinaryWriter(); 2040 | proto.pb.Subscribe.serializeBinaryToWriter(this, writer); 2041 | return writer.getResultBuffer(); 2042 | }; 2043 | 2044 | 2045 | /** 2046 | * Serializes the given message to binary data (in protobuf wire 2047 | * format), writing to the given BinaryWriter. 2048 | * @param {!proto.pb.Subscribe} message 2049 | * @param {!jspb.BinaryWriter} writer 2050 | * @suppress {unusedLocalVariables} f is only used for nested messages 2051 | */ 2052 | proto.pb.Subscribe.serializeBinaryToWriter = function(message, writer) { 2053 | var f = undefined; 2054 | f = message.getSubscriber_asU8(); 2055 | if (f.length > 0) { 2056 | writer.writeBytes( 2057 | 1, 2058 | f 2059 | ); 2060 | } 2061 | f = message.getIdentifier(); 2062 | if (f.length > 0) { 2063 | writer.writeString( 2064 | 2, 2065 | f 2066 | ); 2067 | } 2068 | f = message.getTopic(); 2069 | if (f.length > 0) { 2070 | writer.writeString( 2071 | 3, 2072 | f 2073 | ); 2074 | } 2075 | f = message.getBucket(); 2076 | if (f !== 0) { 2077 | writer.writeUint32( 2078 | 4, 2079 | f 2080 | ); 2081 | } 2082 | f = message.getDuration(); 2083 | if (f !== 0) { 2084 | writer.writeUint32( 2085 | 5, 2086 | f 2087 | ); 2088 | } 2089 | f = message.getMeta(); 2090 | if (f.length > 0) { 2091 | writer.writeString( 2092 | 6, 2093 | f 2094 | ); 2095 | } 2096 | }; 2097 | 2098 | 2099 | /** 2100 | * optional bytes subscriber = 1; 2101 | * @return {!(string|Uint8Array)} 2102 | */ 2103 | proto.pb.Subscribe.prototype.getSubscriber = function() { 2104 | return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 1, "")); 2105 | }; 2106 | 2107 | 2108 | /** 2109 | * optional bytes subscriber = 1; 2110 | * This is a type-conversion wrapper around `getSubscriber()` 2111 | * @return {string} 2112 | */ 2113 | proto.pb.Subscribe.prototype.getSubscriber_asB64 = function() { 2114 | return /** @type {string} */ (jspb.Message.bytesAsB64( 2115 | this.getSubscriber())); 2116 | }; 2117 | 2118 | 2119 | /** 2120 | * optional bytes subscriber = 1; 2121 | * Note that Uint8Array is not supported on all browsers. 2122 | * @see http://caniuse.com/Uint8Array 2123 | * This is a type-conversion wrapper around `getSubscriber()` 2124 | * @return {!Uint8Array} 2125 | */ 2126 | proto.pb.Subscribe.prototype.getSubscriber_asU8 = function() { 2127 | return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( 2128 | this.getSubscriber())); 2129 | }; 2130 | 2131 | 2132 | /** @param {!(string|Uint8Array)} value */ 2133 | proto.pb.Subscribe.prototype.setSubscriber = function(value) { 2134 | jspb.Message.setProto3BytesField(this, 1, value); 2135 | }; 2136 | 2137 | 2138 | /** 2139 | * optional string identifier = 2; 2140 | * @return {string} 2141 | */ 2142 | proto.pb.Subscribe.prototype.getIdentifier = function() { 2143 | return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, "")); 2144 | }; 2145 | 2146 | 2147 | /** @param {string} value */ 2148 | proto.pb.Subscribe.prototype.setIdentifier = function(value) { 2149 | jspb.Message.setProto3StringField(this, 2, value); 2150 | }; 2151 | 2152 | 2153 | /** 2154 | * optional string topic = 3; 2155 | * @return {string} 2156 | */ 2157 | proto.pb.Subscribe.prototype.getTopic = function() { 2158 | return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 3, "")); 2159 | }; 2160 | 2161 | 2162 | /** @param {string} value */ 2163 | proto.pb.Subscribe.prototype.setTopic = function(value) { 2164 | jspb.Message.setProto3StringField(this, 3, value); 2165 | }; 2166 | 2167 | 2168 | /** 2169 | * optional uint32 bucket = 4; 2170 | * @return {number} 2171 | */ 2172 | proto.pb.Subscribe.prototype.getBucket = function() { 2173 | return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 4, 0)); 2174 | }; 2175 | 2176 | 2177 | /** @param {number} value */ 2178 | proto.pb.Subscribe.prototype.setBucket = function(value) { 2179 | jspb.Message.setProto3IntField(this, 4, value); 2180 | }; 2181 | 2182 | 2183 | /** 2184 | * optional uint32 duration = 5; 2185 | * @return {number} 2186 | */ 2187 | proto.pb.Subscribe.prototype.getDuration = function() { 2188 | return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 5, 0)); 2189 | }; 2190 | 2191 | 2192 | /** @param {number} value */ 2193 | proto.pb.Subscribe.prototype.setDuration = function(value) { 2194 | jspb.Message.setProto3IntField(this, 5, value); 2195 | }; 2196 | 2197 | 2198 | /** 2199 | * optional string meta = 6; 2200 | * @return {string} 2201 | */ 2202 | proto.pb.Subscribe.prototype.getMeta = function() { 2203 | return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 6, "")); 2204 | }; 2205 | 2206 | 2207 | /** @param {string} value */ 2208 | proto.pb.Subscribe.prototype.setMeta = function(value) { 2209 | jspb.Message.setProto3StringField(this, 6, value); 2210 | }; 2211 | 2212 | 2213 | 2214 | 2215 | 2216 | if (jspb.Message.GENERATE_TO_OBJECT) { 2217 | /** 2218 | * Creates an object representation of this proto suitable for use in Soy templates. 2219 | * Field names that are reserved in JavaScript and will be renamed to pb_name. 2220 | * To access a reserved field use, foo.pb_, eg, foo.pb_default. 2221 | * For the list of reserved names please see: 2222 | * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. 2223 | * @param {boolean=} opt_includeInstance Whether to include the JSPB instance 2224 | * for transitional soy proto support: http://goto/soy-param-migration 2225 | * @return {!Object} 2226 | */ 2227 | proto.pb.Unsubscribe.prototype.toObject = function(opt_includeInstance) { 2228 | return proto.pb.Unsubscribe.toObject(opt_includeInstance, this); 2229 | }; 2230 | 2231 | 2232 | /** 2233 | * Static version of the {@see toObject} method. 2234 | * @param {boolean|undefined} includeInstance Whether to include the JSPB 2235 | * instance for transitional soy proto support: 2236 | * http://goto/soy-param-migration 2237 | * @param {!proto.pb.Unsubscribe} msg The msg instance to transform. 2238 | * @return {!Object} 2239 | * @suppress {unusedLocalVariables} f is only used for nested messages 2240 | */ 2241 | proto.pb.Unsubscribe.toObject = function(includeInstance, msg) { 2242 | var f, obj = { 2243 | subscriber: msg.getSubscriber_asB64(), 2244 | identifier: jspb.Message.getFieldWithDefault(msg, 2, ""), 2245 | topic: jspb.Message.getFieldWithDefault(msg, 3, "") 2246 | }; 2247 | 2248 | if (includeInstance) { 2249 | obj.$jspbMessageInstance = msg; 2250 | } 2251 | return obj; 2252 | }; 2253 | } 2254 | 2255 | 2256 | /** 2257 | * Deserializes binary data (in protobuf wire format). 2258 | * @param {jspb.ByteSource} bytes The bytes to deserialize. 2259 | * @return {!proto.pb.Unsubscribe} 2260 | */ 2261 | proto.pb.Unsubscribe.deserializeBinary = function(bytes) { 2262 | var reader = new jspb.BinaryReader(bytes); 2263 | var msg = new proto.pb.Unsubscribe; 2264 | return proto.pb.Unsubscribe.deserializeBinaryFromReader(msg, reader); 2265 | }; 2266 | 2267 | 2268 | /** 2269 | * Deserializes binary data (in protobuf wire format) from the 2270 | * given reader into the given message object. 2271 | * @param {!proto.pb.Unsubscribe} msg The message object to deserialize into. 2272 | * @param {!jspb.BinaryReader} reader The BinaryReader to use. 2273 | * @return {!proto.pb.Unsubscribe} 2274 | */ 2275 | proto.pb.Unsubscribe.deserializeBinaryFromReader = function(msg, reader) { 2276 | while (reader.nextField()) { 2277 | if (reader.isEndGroup()) { 2278 | break; 2279 | } 2280 | var field = reader.getFieldNumber(); 2281 | switch (field) { 2282 | case 1: 2283 | var value = /** @type {!Uint8Array} */ (reader.readBytes()); 2284 | msg.setSubscriber(value); 2285 | break; 2286 | case 2: 2287 | var value = /** @type {string} */ (reader.readString()); 2288 | msg.setIdentifier(value); 2289 | break; 2290 | case 3: 2291 | var value = /** @type {string} */ (reader.readString()); 2292 | msg.setTopic(value); 2293 | break; 2294 | default: 2295 | reader.skipField(); 2296 | break; 2297 | } 2298 | } 2299 | return msg; 2300 | }; 2301 | 2302 | 2303 | /** 2304 | * Serializes the message to binary data (in protobuf wire format). 2305 | * @return {!Uint8Array} 2306 | */ 2307 | proto.pb.Unsubscribe.prototype.serializeBinary = function() { 2308 | var writer = new jspb.BinaryWriter(); 2309 | proto.pb.Unsubscribe.serializeBinaryToWriter(this, writer); 2310 | return writer.getResultBuffer(); 2311 | }; 2312 | 2313 | 2314 | /** 2315 | * Serializes the given message to binary data (in protobuf wire 2316 | * format), writing to the given BinaryWriter. 2317 | * @param {!proto.pb.Unsubscribe} message 2318 | * @param {!jspb.BinaryWriter} writer 2319 | * @suppress {unusedLocalVariables} f is only used for nested messages 2320 | */ 2321 | proto.pb.Unsubscribe.serializeBinaryToWriter = function(message, writer) { 2322 | var f = undefined; 2323 | f = message.getSubscriber_asU8(); 2324 | if (f.length > 0) { 2325 | writer.writeBytes( 2326 | 1, 2327 | f 2328 | ); 2329 | } 2330 | f = message.getIdentifier(); 2331 | if (f.length > 0) { 2332 | writer.writeString( 2333 | 2, 2334 | f 2335 | ); 2336 | } 2337 | f = message.getTopic(); 2338 | if (f.length > 0) { 2339 | writer.writeString( 2340 | 3, 2341 | f 2342 | ); 2343 | } 2344 | }; 2345 | 2346 | 2347 | /** 2348 | * optional bytes subscriber = 1; 2349 | * @return {!(string|Uint8Array)} 2350 | */ 2351 | proto.pb.Unsubscribe.prototype.getSubscriber = function() { 2352 | return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 1, "")); 2353 | }; 2354 | 2355 | 2356 | /** 2357 | * optional bytes subscriber = 1; 2358 | * This is a type-conversion wrapper around `getSubscriber()` 2359 | * @return {string} 2360 | */ 2361 | proto.pb.Unsubscribe.prototype.getSubscriber_asB64 = function() { 2362 | return /** @type {string} */ (jspb.Message.bytesAsB64( 2363 | this.getSubscriber())); 2364 | }; 2365 | 2366 | 2367 | /** 2368 | * optional bytes subscriber = 1; 2369 | * Note that Uint8Array is not supported on all browsers. 2370 | * @see http://caniuse.com/Uint8Array 2371 | * This is a type-conversion wrapper around `getSubscriber()` 2372 | * @return {!Uint8Array} 2373 | */ 2374 | proto.pb.Unsubscribe.prototype.getSubscriber_asU8 = function() { 2375 | return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( 2376 | this.getSubscriber())); 2377 | }; 2378 | 2379 | 2380 | /** @param {!(string|Uint8Array)} value */ 2381 | proto.pb.Unsubscribe.prototype.setSubscriber = function(value) { 2382 | jspb.Message.setProto3BytesField(this, 1, value); 2383 | }; 2384 | 2385 | 2386 | /** 2387 | * optional string identifier = 2; 2388 | * @return {string} 2389 | */ 2390 | proto.pb.Unsubscribe.prototype.getIdentifier = function() { 2391 | return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, "")); 2392 | }; 2393 | 2394 | 2395 | /** @param {string} value */ 2396 | proto.pb.Unsubscribe.prototype.setIdentifier = function(value) { 2397 | jspb.Message.setProto3StringField(this, 2, value); 2398 | }; 2399 | 2400 | 2401 | /** 2402 | * optional string topic = 3; 2403 | * @return {string} 2404 | */ 2405 | proto.pb.Unsubscribe.prototype.getTopic = function() { 2406 | return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 3, "")); 2407 | }; 2408 | 2409 | 2410 | /** @param {string} value */ 2411 | proto.pb.Unsubscribe.prototype.setTopic = function(value) { 2412 | jspb.Message.setProto3StringField(this, 3, value); 2413 | }; 2414 | 2415 | 2416 | 2417 | 2418 | 2419 | if (jspb.Message.GENERATE_TO_OBJECT) { 2420 | /** 2421 | * Creates an object representation of this proto suitable for use in Soy templates. 2422 | * Field names that are reserved in JavaScript and will be renamed to pb_name. 2423 | * To access a reserved field use, foo.pb_, eg, foo.pb_default. 2424 | * For the list of reserved names please see: 2425 | * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. 2426 | * @param {boolean=} opt_includeInstance Whether to include the JSPB instance 2427 | * for transitional soy proto support: http://goto/soy-param-migration 2428 | * @return {!Object} 2429 | */ 2430 | proto.pb.TransferAsset.prototype.toObject = function(opt_includeInstance) { 2431 | return proto.pb.TransferAsset.toObject(opt_includeInstance, this); 2432 | }; 2433 | 2434 | 2435 | /** 2436 | * Static version of the {@see toObject} method. 2437 | * @param {boolean|undefined} includeInstance Whether to include the JSPB 2438 | * instance for transitional soy proto support: 2439 | * http://goto/soy-param-migration 2440 | * @param {!proto.pb.TransferAsset} msg The msg instance to transform. 2441 | * @return {!Object} 2442 | * @suppress {unusedLocalVariables} f is only used for nested messages 2443 | */ 2444 | proto.pb.TransferAsset.toObject = function(includeInstance, msg) { 2445 | var f, obj = { 2446 | sender: msg.getSender_asB64(), 2447 | recipient: msg.getRecipient_asB64(), 2448 | amount: jspb.Message.getFieldWithDefault(msg, 3, 0) 2449 | }; 2450 | 2451 | if (includeInstance) { 2452 | obj.$jspbMessageInstance = msg; 2453 | } 2454 | return obj; 2455 | }; 2456 | } 2457 | 2458 | 2459 | /** 2460 | * Deserializes binary data (in protobuf wire format). 2461 | * @param {jspb.ByteSource} bytes The bytes to deserialize. 2462 | * @return {!proto.pb.TransferAsset} 2463 | */ 2464 | proto.pb.TransferAsset.deserializeBinary = function(bytes) { 2465 | var reader = new jspb.BinaryReader(bytes); 2466 | var msg = new proto.pb.TransferAsset; 2467 | return proto.pb.TransferAsset.deserializeBinaryFromReader(msg, reader); 2468 | }; 2469 | 2470 | 2471 | /** 2472 | * Deserializes binary data (in protobuf wire format) from the 2473 | * given reader into the given message object. 2474 | * @param {!proto.pb.TransferAsset} msg The message object to deserialize into. 2475 | * @param {!jspb.BinaryReader} reader The BinaryReader to use. 2476 | * @return {!proto.pb.TransferAsset} 2477 | */ 2478 | proto.pb.TransferAsset.deserializeBinaryFromReader = function(msg, reader) { 2479 | while (reader.nextField()) { 2480 | if (reader.isEndGroup()) { 2481 | break; 2482 | } 2483 | var field = reader.getFieldNumber(); 2484 | switch (field) { 2485 | case 1: 2486 | var value = /** @type {!Uint8Array} */ (reader.readBytes()); 2487 | msg.setSender(value); 2488 | break; 2489 | case 2: 2490 | var value = /** @type {!Uint8Array} */ (reader.readBytes()); 2491 | msg.setRecipient(value); 2492 | break; 2493 | case 3: 2494 | var value = /** @type {number} */ (reader.readInt64()); 2495 | msg.setAmount(value); 2496 | break; 2497 | default: 2498 | reader.skipField(); 2499 | break; 2500 | } 2501 | } 2502 | return msg; 2503 | }; 2504 | 2505 | 2506 | /** 2507 | * Serializes the message to binary data (in protobuf wire format). 2508 | * @return {!Uint8Array} 2509 | */ 2510 | proto.pb.TransferAsset.prototype.serializeBinary = function() { 2511 | var writer = new jspb.BinaryWriter(); 2512 | proto.pb.TransferAsset.serializeBinaryToWriter(this, writer); 2513 | return writer.getResultBuffer(); 2514 | }; 2515 | 2516 | 2517 | /** 2518 | * Serializes the given message to binary data (in protobuf wire 2519 | * format), writing to the given BinaryWriter. 2520 | * @param {!proto.pb.TransferAsset} message 2521 | * @param {!jspb.BinaryWriter} writer 2522 | * @suppress {unusedLocalVariables} f is only used for nested messages 2523 | */ 2524 | proto.pb.TransferAsset.serializeBinaryToWriter = function(message, writer) { 2525 | var f = undefined; 2526 | f = message.getSender_asU8(); 2527 | if (f.length > 0) { 2528 | writer.writeBytes( 2529 | 1, 2530 | f 2531 | ); 2532 | } 2533 | f = message.getRecipient_asU8(); 2534 | if (f.length > 0) { 2535 | writer.writeBytes( 2536 | 2, 2537 | f 2538 | ); 2539 | } 2540 | f = message.getAmount(); 2541 | if (f !== 0) { 2542 | writer.writeInt64( 2543 | 3, 2544 | f 2545 | ); 2546 | } 2547 | }; 2548 | 2549 | 2550 | /** 2551 | * optional bytes sender = 1; 2552 | * @return {!(string|Uint8Array)} 2553 | */ 2554 | proto.pb.TransferAsset.prototype.getSender = function() { 2555 | return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 1, "")); 2556 | }; 2557 | 2558 | 2559 | /** 2560 | * optional bytes sender = 1; 2561 | * This is a type-conversion wrapper around `getSender()` 2562 | * @return {string} 2563 | */ 2564 | proto.pb.TransferAsset.prototype.getSender_asB64 = function() { 2565 | return /** @type {string} */ (jspb.Message.bytesAsB64( 2566 | this.getSender())); 2567 | }; 2568 | 2569 | 2570 | /** 2571 | * optional bytes sender = 1; 2572 | * Note that Uint8Array is not supported on all browsers. 2573 | * @see http://caniuse.com/Uint8Array 2574 | * This is a type-conversion wrapper around `getSender()` 2575 | * @return {!Uint8Array} 2576 | */ 2577 | proto.pb.TransferAsset.prototype.getSender_asU8 = function() { 2578 | return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( 2579 | this.getSender())); 2580 | }; 2581 | 2582 | 2583 | /** @param {!(string|Uint8Array)} value */ 2584 | proto.pb.TransferAsset.prototype.setSender = function(value) { 2585 | jspb.Message.setProto3BytesField(this, 1, value); 2586 | }; 2587 | 2588 | 2589 | /** 2590 | * optional bytes recipient = 2; 2591 | * @return {!(string|Uint8Array)} 2592 | */ 2593 | proto.pb.TransferAsset.prototype.getRecipient = function() { 2594 | return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 2, "")); 2595 | }; 2596 | 2597 | 2598 | /** 2599 | * optional bytes recipient = 2; 2600 | * This is a type-conversion wrapper around `getRecipient()` 2601 | * @return {string} 2602 | */ 2603 | proto.pb.TransferAsset.prototype.getRecipient_asB64 = function() { 2604 | return /** @type {string} */ (jspb.Message.bytesAsB64( 2605 | this.getRecipient())); 2606 | }; 2607 | 2608 | 2609 | /** 2610 | * optional bytes recipient = 2; 2611 | * Note that Uint8Array is not supported on all browsers. 2612 | * @see http://caniuse.com/Uint8Array 2613 | * This is a type-conversion wrapper around `getRecipient()` 2614 | * @return {!Uint8Array} 2615 | */ 2616 | proto.pb.TransferAsset.prototype.getRecipient_asU8 = function() { 2617 | return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( 2618 | this.getRecipient())); 2619 | }; 2620 | 2621 | 2622 | /** @param {!(string|Uint8Array)} value */ 2623 | proto.pb.TransferAsset.prototype.setRecipient = function(value) { 2624 | jspb.Message.setProto3BytesField(this, 2, value); 2625 | }; 2626 | 2627 | 2628 | /** 2629 | * optional int64 amount = 3; 2630 | * @return {number} 2631 | */ 2632 | proto.pb.TransferAsset.prototype.getAmount = function() { 2633 | return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 3, 0)); 2634 | }; 2635 | 2636 | 2637 | /** @param {number} value */ 2638 | proto.pb.TransferAsset.prototype.setAmount = function(value) { 2639 | jspb.Message.setProto3IntField(this, 3, value); 2640 | }; 2641 | 2642 | 2643 | 2644 | 2645 | 2646 | if (jspb.Message.GENERATE_TO_OBJECT) { 2647 | /** 2648 | * Creates an object representation of this proto suitable for use in Soy templates. 2649 | * Field names that are reserved in JavaScript and will be renamed to pb_name. 2650 | * To access a reserved field use, foo.pb_, eg, foo.pb_default. 2651 | * For the list of reserved names please see: 2652 | * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. 2653 | * @param {boolean=} opt_includeInstance Whether to include the JSPB instance 2654 | * for transitional soy proto support: http://goto/soy-param-migration 2655 | * @return {!Object} 2656 | */ 2657 | proto.pb.GenerateID.prototype.toObject = function(opt_includeInstance) { 2658 | return proto.pb.GenerateID.toObject(opt_includeInstance, this); 2659 | }; 2660 | 2661 | 2662 | /** 2663 | * Static version of the {@see toObject} method. 2664 | * @param {boolean|undefined} includeInstance Whether to include the JSPB 2665 | * instance for transitional soy proto support: 2666 | * http://goto/soy-param-migration 2667 | * @param {!proto.pb.GenerateID} msg The msg instance to transform. 2668 | * @return {!Object} 2669 | * @suppress {unusedLocalVariables} f is only used for nested messages 2670 | */ 2671 | proto.pb.GenerateID.toObject = function(includeInstance, msg) { 2672 | var f, obj = { 2673 | publicKey: msg.getPublicKey_asB64(), 2674 | registrationFee: jspb.Message.getFieldWithDefault(msg, 2, 0) 2675 | }; 2676 | 2677 | if (includeInstance) { 2678 | obj.$jspbMessageInstance = msg; 2679 | } 2680 | return obj; 2681 | }; 2682 | } 2683 | 2684 | 2685 | /** 2686 | * Deserializes binary data (in protobuf wire format). 2687 | * @param {jspb.ByteSource} bytes The bytes to deserialize. 2688 | * @return {!proto.pb.GenerateID} 2689 | */ 2690 | proto.pb.GenerateID.deserializeBinary = function(bytes) { 2691 | var reader = new jspb.BinaryReader(bytes); 2692 | var msg = new proto.pb.GenerateID; 2693 | return proto.pb.GenerateID.deserializeBinaryFromReader(msg, reader); 2694 | }; 2695 | 2696 | 2697 | /** 2698 | * Deserializes binary data (in protobuf wire format) from the 2699 | * given reader into the given message object. 2700 | * @param {!proto.pb.GenerateID} msg The message object to deserialize into. 2701 | * @param {!jspb.BinaryReader} reader The BinaryReader to use. 2702 | * @return {!proto.pb.GenerateID} 2703 | */ 2704 | proto.pb.GenerateID.deserializeBinaryFromReader = function(msg, reader) { 2705 | while (reader.nextField()) { 2706 | if (reader.isEndGroup()) { 2707 | break; 2708 | } 2709 | var field = reader.getFieldNumber(); 2710 | switch (field) { 2711 | case 1: 2712 | var value = /** @type {!Uint8Array} */ (reader.readBytes()); 2713 | msg.setPublicKey(value); 2714 | break; 2715 | case 2: 2716 | var value = /** @type {number} */ (reader.readInt64()); 2717 | msg.setRegistrationFee(value); 2718 | break; 2719 | default: 2720 | reader.skipField(); 2721 | break; 2722 | } 2723 | } 2724 | return msg; 2725 | }; 2726 | 2727 | 2728 | /** 2729 | * Serializes the message to binary data (in protobuf wire format). 2730 | * @return {!Uint8Array} 2731 | */ 2732 | proto.pb.GenerateID.prototype.serializeBinary = function() { 2733 | var writer = new jspb.BinaryWriter(); 2734 | proto.pb.GenerateID.serializeBinaryToWriter(this, writer); 2735 | return writer.getResultBuffer(); 2736 | }; 2737 | 2738 | 2739 | /** 2740 | * Serializes the given message to binary data (in protobuf wire 2741 | * format), writing to the given BinaryWriter. 2742 | * @param {!proto.pb.GenerateID} message 2743 | * @param {!jspb.BinaryWriter} writer 2744 | * @suppress {unusedLocalVariables} f is only used for nested messages 2745 | */ 2746 | proto.pb.GenerateID.serializeBinaryToWriter = function(message, writer) { 2747 | var f = undefined; 2748 | f = message.getPublicKey_asU8(); 2749 | if (f.length > 0) { 2750 | writer.writeBytes( 2751 | 1, 2752 | f 2753 | ); 2754 | } 2755 | f = message.getRegistrationFee(); 2756 | if (f !== 0) { 2757 | writer.writeInt64( 2758 | 2, 2759 | f 2760 | ); 2761 | } 2762 | }; 2763 | 2764 | 2765 | /** 2766 | * optional bytes public_key = 1; 2767 | * @return {!(string|Uint8Array)} 2768 | */ 2769 | proto.pb.GenerateID.prototype.getPublicKey = function() { 2770 | return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 1, "")); 2771 | }; 2772 | 2773 | 2774 | /** 2775 | * optional bytes public_key = 1; 2776 | * This is a type-conversion wrapper around `getPublicKey()` 2777 | * @return {string} 2778 | */ 2779 | proto.pb.GenerateID.prototype.getPublicKey_asB64 = function() { 2780 | return /** @type {string} */ (jspb.Message.bytesAsB64( 2781 | this.getPublicKey())); 2782 | }; 2783 | 2784 | 2785 | /** 2786 | * optional bytes public_key = 1; 2787 | * Note that Uint8Array is not supported on all browsers. 2788 | * @see http://caniuse.com/Uint8Array 2789 | * This is a type-conversion wrapper around `getPublicKey()` 2790 | * @return {!Uint8Array} 2791 | */ 2792 | proto.pb.GenerateID.prototype.getPublicKey_asU8 = function() { 2793 | return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( 2794 | this.getPublicKey())); 2795 | }; 2796 | 2797 | 2798 | /** @param {!(string|Uint8Array)} value */ 2799 | proto.pb.GenerateID.prototype.setPublicKey = function(value) { 2800 | jspb.Message.setProto3BytesField(this, 1, value); 2801 | }; 2802 | 2803 | 2804 | /** 2805 | * optional int64 registration_fee = 2; 2806 | * @return {number} 2807 | */ 2808 | proto.pb.GenerateID.prototype.getRegistrationFee = function() { 2809 | return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 2, 0)); 2810 | }; 2811 | 2812 | 2813 | /** @param {number} value */ 2814 | proto.pb.GenerateID.prototype.setRegistrationFee = function(value) { 2815 | jspb.Message.setProto3IntField(this, 2, value); 2816 | }; 2817 | 2818 | 2819 | 2820 | 2821 | 2822 | if (jspb.Message.GENERATE_TO_OBJECT) { 2823 | /** 2824 | * Creates an object representation of this proto suitable for use in Soy templates. 2825 | * Field names that are reserved in JavaScript and will be renamed to pb_name. 2826 | * To access a reserved field use, foo.pb_, eg, foo.pb_default. 2827 | * For the list of reserved names please see: 2828 | * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. 2829 | * @param {boolean=} opt_includeInstance Whether to include the JSPB instance 2830 | * for transitional soy proto support: http://goto/soy-param-migration 2831 | * @return {!Object} 2832 | */ 2833 | proto.pb.NanoPay.prototype.toObject = function(opt_includeInstance) { 2834 | return proto.pb.NanoPay.toObject(opt_includeInstance, this); 2835 | }; 2836 | 2837 | 2838 | /** 2839 | * Static version of the {@see toObject} method. 2840 | * @param {boolean|undefined} includeInstance Whether to include the JSPB 2841 | * instance for transitional soy proto support: 2842 | * http://goto/soy-param-migration 2843 | * @param {!proto.pb.NanoPay} msg The msg instance to transform. 2844 | * @return {!Object} 2845 | * @suppress {unusedLocalVariables} f is only used for nested messages 2846 | */ 2847 | proto.pb.NanoPay.toObject = function(includeInstance, msg) { 2848 | var f, obj = { 2849 | sender: msg.getSender_asB64(), 2850 | recipient: msg.getRecipient_asB64(), 2851 | id: jspb.Message.getFieldWithDefault(msg, 3, 0), 2852 | amount: jspb.Message.getFieldWithDefault(msg, 4, 0), 2853 | txnExpiration: jspb.Message.getFieldWithDefault(msg, 5, 0), 2854 | nanoPayExpiration: jspb.Message.getFieldWithDefault(msg, 6, 0) 2855 | }; 2856 | 2857 | if (includeInstance) { 2858 | obj.$jspbMessageInstance = msg; 2859 | } 2860 | return obj; 2861 | }; 2862 | } 2863 | 2864 | 2865 | /** 2866 | * Deserializes binary data (in protobuf wire format). 2867 | * @param {jspb.ByteSource} bytes The bytes to deserialize. 2868 | * @return {!proto.pb.NanoPay} 2869 | */ 2870 | proto.pb.NanoPay.deserializeBinary = function(bytes) { 2871 | var reader = new jspb.BinaryReader(bytes); 2872 | var msg = new proto.pb.NanoPay; 2873 | return proto.pb.NanoPay.deserializeBinaryFromReader(msg, reader); 2874 | }; 2875 | 2876 | 2877 | /** 2878 | * Deserializes binary data (in protobuf wire format) from the 2879 | * given reader into the given message object. 2880 | * @param {!proto.pb.NanoPay} msg The message object to deserialize into. 2881 | * @param {!jspb.BinaryReader} reader The BinaryReader to use. 2882 | * @return {!proto.pb.NanoPay} 2883 | */ 2884 | proto.pb.NanoPay.deserializeBinaryFromReader = function(msg, reader) { 2885 | while (reader.nextField()) { 2886 | if (reader.isEndGroup()) { 2887 | break; 2888 | } 2889 | var field = reader.getFieldNumber(); 2890 | switch (field) { 2891 | case 1: 2892 | var value = /** @type {!Uint8Array} */ (reader.readBytes()); 2893 | msg.setSender(value); 2894 | break; 2895 | case 2: 2896 | var value = /** @type {!Uint8Array} */ (reader.readBytes()); 2897 | msg.setRecipient(value); 2898 | break; 2899 | case 3: 2900 | var value = /** @type {number} */ (reader.readUint64()); 2901 | msg.setId(value); 2902 | break; 2903 | case 4: 2904 | var value = /** @type {number} */ (reader.readInt64()); 2905 | msg.setAmount(value); 2906 | break; 2907 | case 5: 2908 | var value = /** @type {number} */ (reader.readUint32()); 2909 | msg.setTxnExpiration(value); 2910 | break; 2911 | case 6: 2912 | var value = /** @type {number} */ (reader.readUint32()); 2913 | msg.setNanoPayExpiration(value); 2914 | break; 2915 | default: 2916 | reader.skipField(); 2917 | break; 2918 | } 2919 | } 2920 | return msg; 2921 | }; 2922 | 2923 | 2924 | /** 2925 | * Serializes the message to binary data (in protobuf wire format). 2926 | * @return {!Uint8Array} 2927 | */ 2928 | proto.pb.NanoPay.prototype.serializeBinary = function() { 2929 | var writer = new jspb.BinaryWriter(); 2930 | proto.pb.NanoPay.serializeBinaryToWriter(this, writer); 2931 | return writer.getResultBuffer(); 2932 | }; 2933 | 2934 | 2935 | /** 2936 | * Serializes the given message to binary data (in protobuf wire 2937 | * format), writing to the given BinaryWriter. 2938 | * @param {!proto.pb.NanoPay} message 2939 | * @param {!jspb.BinaryWriter} writer 2940 | * @suppress {unusedLocalVariables} f is only used for nested messages 2941 | */ 2942 | proto.pb.NanoPay.serializeBinaryToWriter = function(message, writer) { 2943 | var f = undefined; 2944 | f = message.getSender_asU8(); 2945 | if (f.length > 0) { 2946 | writer.writeBytes( 2947 | 1, 2948 | f 2949 | ); 2950 | } 2951 | f = message.getRecipient_asU8(); 2952 | if (f.length > 0) { 2953 | writer.writeBytes( 2954 | 2, 2955 | f 2956 | ); 2957 | } 2958 | f = message.getId(); 2959 | if (f !== 0) { 2960 | writer.writeUint64( 2961 | 3, 2962 | f 2963 | ); 2964 | } 2965 | f = message.getAmount(); 2966 | if (f !== 0) { 2967 | writer.writeInt64( 2968 | 4, 2969 | f 2970 | ); 2971 | } 2972 | f = message.getTxnExpiration(); 2973 | if (f !== 0) { 2974 | writer.writeUint32( 2975 | 5, 2976 | f 2977 | ); 2978 | } 2979 | f = message.getNanoPayExpiration(); 2980 | if (f !== 0) { 2981 | writer.writeUint32( 2982 | 6, 2983 | f 2984 | ); 2985 | } 2986 | }; 2987 | 2988 | 2989 | /** 2990 | * optional bytes sender = 1; 2991 | * @return {!(string|Uint8Array)} 2992 | */ 2993 | proto.pb.NanoPay.prototype.getSender = function() { 2994 | return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 1, "")); 2995 | }; 2996 | 2997 | 2998 | /** 2999 | * optional bytes sender = 1; 3000 | * This is a type-conversion wrapper around `getSender()` 3001 | * @return {string} 3002 | */ 3003 | proto.pb.NanoPay.prototype.getSender_asB64 = function() { 3004 | return /** @type {string} */ (jspb.Message.bytesAsB64( 3005 | this.getSender())); 3006 | }; 3007 | 3008 | 3009 | /** 3010 | * optional bytes sender = 1; 3011 | * Note that Uint8Array is not supported on all browsers. 3012 | * @see http://caniuse.com/Uint8Array 3013 | * This is a type-conversion wrapper around `getSender()` 3014 | * @return {!Uint8Array} 3015 | */ 3016 | proto.pb.NanoPay.prototype.getSender_asU8 = function() { 3017 | return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( 3018 | this.getSender())); 3019 | }; 3020 | 3021 | 3022 | /** @param {!(string|Uint8Array)} value */ 3023 | proto.pb.NanoPay.prototype.setSender = function(value) { 3024 | jspb.Message.setProto3BytesField(this, 1, value); 3025 | }; 3026 | 3027 | 3028 | /** 3029 | * optional bytes recipient = 2; 3030 | * @return {!(string|Uint8Array)} 3031 | */ 3032 | proto.pb.NanoPay.prototype.getRecipient = function() { 3033 | return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 2, "")); 3034 | }; 3035 | 3036 | 3037 | /** 3038 | * optional bytes recipient = 2; 3039 | * This is a type-conversion wrapper around `getRecipient()` 3040 | * @return {string} 3041 | */ 3042 | proto.pb.NanoPay.prototype.getRecipient_asB64 = function() { 3043 | return /** @type {string} */ (jspb.Message.bytesAsB64( 3044 | this.getRecipient())); 3045 | }; 3046 | 3047 | 3048 | /** 3049 | * optional bytes recipient = 2; 3050 | * Note that Uint8Array is not supported on all browsers. 3051 | * @see http://caniuse.com/Uint8Array 3052 | * This is a type-conversion wrapper around `getRecipient()` 3053 | * @return {!Uint8Array} 3054 | */ 3055 | proto.pb.NanoPay.prototype.getRecipient_asU8 = function() { 3056 | return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( 3057 | this.getRecipient())); 3058 | }; 3059 | 3060 | 3061 | /** @param {!(string|Uint8Array)} value */ 3062 | proto.pb.NanoPay.prototype.setRecipient = function(value) { 3063 | jspb.Message.setProto3BytesField(this, 2, value); 3064 | }; 3065 | 3066 | 3067 | /** 3068 | * optional uint64 id = 3; 3069 | * @return {number} 3070 | */ 3071 | proto.pb.NanoPay.prototype.getId = function() { 3072 | return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 3, 0)); 3073 | }; 3074 | 3075 | 3076 | /** @param {number} value */ 3077 | proto.pb.NanoPay.prototype.setId = function(value) { 3078 | jspb.Message.setProto3IntField(this, 3, value); 3079 | }; 3080 | 3081 | 3082 | /** 3083 | * optional int64 amount = 4; 3084 | * @return {number} 3085 | */ 3086 | proto.pb.NanoPay.prototype.getAmount = function() { 3087 | return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 4, 0)); 3088 | }; 3089 | 3090 | 3091 | /** @param {number} value */ 3092 | proto.pb.NanoPay.prototype.setAmount = function(value) { 3093 | jspb.Message.setProto3IntField(this, 4, value); 3094 | }; 3095 | 3096 | 3097 | /** 3098 | * optional uint32 txn_expiration = 5; 3099 | * @return {number} 3100 | */ 3101 | proto.pb.NanoPay.prototype.getTxnExpiration = function() { 3102 | return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 5, 0)); 3103 | }; 3104 | 3105 | 3106 | /** @param {number} value */ 3107 | proto.pb.NanoPay.prototype.setTxnExpiration = function(value) { 3108 | jspb.Message.setProto3IntField(this, 5, value); 3109 | }; 3110 | 3111 | 3112 | /** 3113 | * optional uint32 nano_pay_expiration = 6; 3114 | * @return {number} 3115 | */ 3116 | proto.pb.NanoPay.prototype.getNanoPayExpiration = function() { 3117 | return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 6, 0)); 3118 | }; 3119 | 3120 | 3121 | /** @param {number} value */ 3122 | proto.pb.NanoPay.prototype.setNanoPayExpiration = function(value) { 3123 | jspb.Message.setProto3IntField(this, 6, value); 3124 | }; 3125 | 3126 | 3127 | 3128 | 3129 | 3130 | if (jspb.Message.GENERATE_TO_OBJECT) { 3131 | /** 3132 | * Creates an object representation of this proto suitable for use in Soy templates. 3133 | * Field names that are reserved in JavaScript and will be renamed to pb_name. 3134 | * To access a reserved field use, foo.pb_, eg, foo.pb_default. 3135 | * For the list of reserved names please see: 3136 | * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. 3137 | * @param {boolean=} opt_includeInstance Whether to include the JSPB instance 3138 | * for transitional soy proto support: http://goto/soy-param-migration 3139 | * @return {!Object} 3140 | */ 3141 | proto.pb.IssueAsset.prototype.toObject = function(opt_includeInstance) { 3142 | return proto.pb.IssueAsset.toObject(opt_includeInstance, this); 3143 | }; 3144 | 3145 | 3146 | /** 3147 | * Static version of the {@see toObject} method. 3148 | * @param {boolean|undefined} includeInstance Whether to include the JSPB 3149 | * instance for transitional soy proto support: 3150 | * http://goto/soy-param-migration 3151 | * @param {!proto.pb.IssueAsset} msg The msg instance to transform. 3152 | * @return {!Object} 3153 | * @suppress {unusedLocalVariables} f is only used for nested messages 3154 | */ 3155 | proto.pb.IssueAsset.toObject = function(includeInstance, msg) { 3156 | var f, obj = { 3157 | sender: msg.getSender_asB64(), 3158 | name: jspb.Message.getFieldWithDefault(msg, 2, ""), 3159 | symbol: jspb.Message.getFieldWithDefault(msg, 3, ""), 3160 | totalSupply: jspb.Message.getFieldWithDefault(msg, 4, 0), 3161 | precision: jspb.Message.getFieldWithDefault(msg, 5, 0) 3162 | }; 3163 | 3164 | if (includeInstance) { 3165 | obj.$jspbMessageInstance = msg; 3166 | } 3167 | return obj; 3168 | }; 3169 | } 3170 | 3171 | 3172 | /** 3173 | * Deserializes binary data (in protobuf wire format). 3174 | * @param {jspb.ByteSource} bytes The bytes to deserialize. 3175 | * @return {!proto.pb.IssueAsset} 3176 | */ 3177 | proto.pb.IssueAsset.deserializeBinary = function(bytes) { 3178 | var reader = new jspb.BinaryReader(bytes); 3179 | var msg = new proto.pb.IssueAsset; 3180 | return proto.pb.IssueAsset.deserializeBinaryFromReader(msg, reader); 3181 | }; 3182 | 3183 | 3184 | /** 3185 | * Deserializes binary data (in protobuf wire format) from the 3186 | * given reader into the given message object. 3187 | * @param {!proto.pb.IssueAsset} msg The message object to deserialize into. 3188 | * @param {!jspb.BinaryReader} reader The BinaryReader to use. 3189 | * @return {!proto.pb.IssueAsset} 3190 | */ 3191 | proto.pb.IssueAsset.deserializeBinaryFromReader = function(msg, reader) { 3192 | while (reader.nextField()) { 3193 | if (reader.isEndGroup()) { 3194 | break; 3195 | } 3196 | var field = reader.getFieldNumber(); 3197 | switch (field) { 3198 | case 1: 3199 | var value = /** @type {!Uint8Array} */ (reader.readBytes()); 3200 | msg.setSender(value); 3201 | break; 3202 | case 2: 3203 | var value = /** @type {string} */ (reader.readString()); 3204 | msg.setName(value); 3205 | break; 3206 | case 3: 3207 | var value = /** @type {string} */ (reader.readString()); 3208 | msg.setSymbol(value); 3209 | break; 3210 | case 4: 3211 | var value = /** @type {number} */ (reader.readInt64()); 3212 | msg.setTotalSupply(value); 3213 | break; 3214 | case 5: 3215 | var value = /** @type {number} */ (reader.readUint32()); 3216 | msg.setPrecision(value); 3217 | break; 3218 | default: 3219 | reader.skipField(); 3220 | break; 3221 | } 3222 | } 3223 | return msg; 3224 | }; 3225 | 3226 | 3227 | /** 3228 | * Serializes the message to binary data (in protobuf wire format). 3229 | * @return {!Uint8Array} 3230 | */ 3231 | proto.pb.IssueAsset.prototype.serializeBinary = function() { 3232 | var writer = new jspb.BinaryWriter(); 3233 | proto.pb.IssueAsset.serializeBinaryToWriter(this, writer); 3234 | return writer.getResultBuffer(); 3235 | }; 3236 | 3237 | 3238 | /** 3239 | * Serializes the given message to binary data (in protobuf wire 3240 | * format), writing to the given BinaryWriter. 3241 | * @param {!proto.pb.IssueAsset} message 3242 | * @param {!jspb.BinaryWriter} writer 3243 | * @suppress {unusedLocalVariables} f is only used for nested messages 3244 | */ 3245 | proto.pb.IssueAsset.serializeBinaryToWriter = function(message, writer) { 3246 | var f = undefined; 3247 | f = message.getSender_asU8(); 3248 | if (f.length > 0) { 3249 | writer.writeBytes( 3250 | 1, 3251 | f 3252 | ); 3253 | } 3254 | f = message.getName(); 3255 | if (f.length > 0) { 3256 | writer.writeString( 3257 | 2, 3258 | f 3259 | ); 3260 | } 3261 | f = message.getSymbol(); 3262 | if (f.length > 0) { 3263 | writer.writeString( 3264 | 3, 3265 | f 3266 | ); 3267 | } 3268 | f = message.getTotalSupply(); 3269 | if (f !== 0) { 3270 | writer.writeInt64( 3271 | 4, 3272 | f 3273 | ); 3274 | } 3275 | f = message.getPrecision(); 3276 | if (f !== 0) { 3277 | writer.writeUint32( 3278 | 5, 3279 | f 3280 | ); 3281 | } 3282 | }; 3283 | 3284 | 3285 | /** 3286 | * optional bytes sender = 1; 3287 | * @return {!(string|Uint8Array)} 3288 | */ 3289 | proto.pb.IssueAsset.prototype.getSender = function() { 3290 | return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 1, "")); 3291 | }; 3292 | 3293 | 3294 | /** 3295 | * optional bytes sender = 1; 3296 | * This is a type-conversion wrapper around `getSender()` 3297 | * @return {string} 3298 | */ 3299 | proto.pb.IssueAsset.prototype.getSender_asB64 = function() { 3300 | return /** @type {string} */ (jspb.Message.bytesAsB64( 3301 | this.getSender())); 3302 | }; 3303 | 3304 | 3305 | /** 3306 | * optional bytes sender = 1; 3307 | * Note that Uint8Array is not supported on all browsers. 3308 | * @see http://caniuse.com/Uint8Array 3309 | * This is a type-conversion wrapper around `getSender()` 3310 | * @return {!Uint8Array} 3311 | */ 3312 | proto.pb.IssueAsset.prototype.getSender_asU8 = function() { 3313 | return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( 3314 | this.getSender())); 3315 | }; 3316 | 3317 | 3318 | /** @param {!(string|Uint8Array)} value */ 3319 | proto.pb.IssueAsset.prototype.setSender = function(value) { 3320 | jspb.Message.setProto3BytesField(this, 1, value); 3321 | }; 3322 | 3323 | 3324 | /** 3325 | * optional string name = 2; 3326 | * @return {string} 3327 | */ 3328 | proto.pb.IssueAsset.prototype.getName = function() { 3329 | return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, "")); 3330 | }; 3331 | 3332 | 3333 | /** @param {string} value */ 3334 | proto.pb.IssueAsset.prototype.setName = function(value) { 3335 | jspb.Message.setProto3StringField(this, 2, value); 3336 | }; 3337 | 3338 | 3339 | /** 3340 | * optional string symbol = 3; 3341 | * @return {string} 3342 | */ 3343 | proto.pb.IssueAsset.prototype.getSymbol = function() { 3344 | return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 3, "")); 3345 | }; 3346 | 3347 | 3348 | /** @param {string} value */ 3349 | proto.pb.IssueAsset.prototype.setSymbol = function(value) { 3350 | jspb.Message.setProto3StringField(this, 3, value); 3351 | }; 3352 | 3353 | 3354 | /** 3355 | * optional int64 total_supply = 4; 3356 | * @return {number} 3357 | */ 3358 | proto.pb.IssueAsset.prototype.getTotalSupply = function() { 3359 | return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 4, 0)); 3360 | }; 3361 | 3362 | 3363 | /** @param {number} value */ 3364 | proto.pb.IssueAsset.prototype.setTotalSupply = function(value) { 3365 | jspb.Message.setProto3IntField(this, 4, value); 3366 | }; 3367 | 3368 | 3369 | /** 3370 | * optional uint32 precision = 5; 3371 | * @return {number} 3372 | */ 3373 | proto.pb.IssueAsset.prototype.getPrecision = function() { 3374 | return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 5, 0)); 3375 | }; 3376 | 3377 | 3378 | /** @param {number} value */ 3379 | proto.pb.IssueAsset.prototype.setPrecision = function(value) { 3380 | jspb.Message.setProto3IntField(this, 5, value); 3381 | }; 3382 | 3383 | 3384 | /** 3385 | * @enum {number} 3386 | */ 3387 | proto.pb.PayloadType = { 3388 | COINBASE_TYPE: 0, 3389 | TRANSFER_ASSET_TYPE: 1, 3390 | SIG_CHAIN_TXN_TYPE: 2, 3391 | REGISTER_NAME_TYPE: 3, 3392 | TRANSFER_NAME_TYPE: 4, 3393 | DELETE_NAME_TYPE: 5, 3394 | SUBSCRIBE_TYPE: 6, 3395 | UNSUBSCRIBE_TYPE: 7, 3396 | GENERATE_ID_TYPE: 8, 3397 | NANO_PAY_TYPE: 9, 3398 | ISSUE_ASSET_TYPE: 10 3399 | }; 3400 | 3401 | goog.object.extend(exports, proto.pb); 3402 | --------------------------------------------------------------------------------