├── .github └── settings.yml ├── .gitignore ├── LICENSE ├── README.md ├── SECURITY.md ├── binding.gyp ├── package.json ├── src ├── IndyError.js ├── index.js ├── indy.cc ├── indyBinding.js └── wrapIndyCallback.js └── test ├── anoncreds.js ├── blob.js ├── cache.js ├── crypto.js ├── did.js ├── helpers ├── initTestPool.js └── makeTestPool.js ├── index.js ├── ledger.js ├── logger.js ├── logger2.js ├── mod.js ├── pairwise.js ├── payments.js ├── pool.js └── wallet.js /.github/settings.yml: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: Apache-2.0 3 | # 4 | 5 | repository: 6 | archived: true 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /libindy.so 2 | /libindy.dylib 3 | /indy.dll 4 | 5 | # this is the libindy header files needed for the build, must be published to npm 6 | /include/ 7 | 8 | node_modules/ 9 | build/ 10 | build-pre-gyp/ 11 | Release/ 12 | prebuilds/ 13 | *.sln 14 | *.vcxproj 15 | *.vcxproj.filters 16 | *.tlog 17 | *.obj 18 | *.1sdk.pdb 19 | *.lastbuildstate 20 | npm-debug.log 21 | package-lock.json 22 | yarn.lock 23 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Hyperledger Security Policy 2 | 3 | ## Reporting a Security Bug 4 | 5 | If you think you have discovered a security issue in any of the Hyperledger 6 | projects, we'd love to hear from you. We will take all security bugs 7 | seriously and if confirmed upon investigation we will patch it within a 8 | reasonable amount of time and release a public security bulletin discussing 9 | the impact and credit the discoverer. 10 | 11 | There are two ways to report a security bug. The easiest is to email a 12 | description of the flaw and any related information (e.g. reproduction 13 | steps, version) to 14 | [security at hyperledger dot org](mailto:security@hyperledger.org). 15 | 16 | The other way is to file a confidential security bug in our 17 | [JIRA bug tracking system](https://jira.hyperledger.org). 18 | Be sure to set the “Security Level” to “Security issue”. 19 | 20 | The process by which the Hyperledger Security Team handles security bugs 21 | is documented further in our 22 | [Defect Response](https://wiki.hyperledger.org/display/HYP/Defect+Response) 23 | page on our [wiki](https://wiki.hyperledger.org). 24 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [ 3 | { 4 | "target_name": "indynodejs", 5 | "include_dirs": [ 6 | " '-L' + a.trim()).filter(a => a != '-L').join(' '))\")", 29 | "-lindy" 30 | ], 31 | }, 32 | ] 33 | ], 34 | } 35 | } 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "indy-sdk", 3 | "version": "1.11.0", 4 | "description": "Native bindings for hyperledger indy", 5 | "author": "hyperledger", 6 | "license": "Apache-2.0", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/hyperledger/indy-sdk.git" 10 | }, 11 | "bugs": { 12 | "url": "https://github.com/hyperledger/indy-sdk/issues" 13 | }, 14 | "homepage": "https://github.com/hyperledger/indy-sdk/tree/master/wrappers/nodejs#readme", 15 | "main": "src/index.js", 16 | "gypfile": true, 17 | "engines": { 18 | "node": ">=8" 19 | }, 20 | "files": [ 21 | "src", 22 | "binding.gyp", 23 | "include" 24 | ], 25 | "scripts": { 26 | "prepare": "cp -r ../../libindy/include .", 27 | "test": "standard && ava --fail-fast", 28 | "rebuild": "node-gyp rebuild" 29 | }, 30 | "dependencies": { 31 | "bindings": "^1.3.1", 32 | "nan": "^2.11.1", 33 | "node-gyp": "^4.0.0" 34 | }, 35 | "devDependencies": { 36 | "ava": "^1.4.1", 37 | "cuid": "^2.1.4", 38 | "home-dir": "^1.0.0", 39 | "standard": "^12.0.1", 40 | "tempy": "^0.3.0" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/IndyError.js: -------------------------------------------------------------------------------- 1 | var util = require('util') 2 | var capi = require('./indyBinding') 3 | 4 | var errors = { 5 | 100: 'CommonInvalidParam1', 6 | 101: 'CommonInvalidParam2', 7 | 102: 'CommonInvalidParam3', 8 | 103: 'CommonInvalidParam4', 9 | 104: 'CommonInvalidParam5', 10 | 105: 'CommonInvalidParam6', 11 | 106: 'CommonInvalidParam7', 12 | 107: 'CommonInvalidParam8', 13 | 108: 'CommonInvalidParam9', 14 | 109: 'CommonInvalidParam10', 15 | 110: 'CommonInvalidParam11', 16 | 111: 'CommonInvalidParam12', 17 | 112: 'CommonInvalidState', 18 | 113: 'CommonInvalidStructure', 19 | 114: 'CommonIOError', 20 | 200: 'WalletInvalidHandle', 21 | 201: 'WalletUnknownTypeError', 22 | 202: 'WalletTypeAlreadyRegisteredError', 23 | 203: 'WalletAlreadyExistsError', 24 | 204: 'WalletNotFoundError', 25 | 205: 'WalletIncompatiblePoolError', 26 | 206: 'WalletAlreadyOpenedError', 27 | 207: 'WalletAccessFailed', 28 | 300: 'PoolLedgerNotCreatedError', 29 | 301: 'PoolLedgerInvalidPoolHandle', 30 | 302: 'PoolLedgerTerminated', 31 | 303: 'LedgerNoConsensusError', 32 | 304: 'LedgerInvalidTransaction', 33 | 305: 'LedgerSecurityError', 34 | 306: 'PoolLedgerConfigAlreadyExistsError', 35 | 307: 'PoolLedgerTimeout', 36 | 308: 'PoolIncompatibleProtocolVersion', 37 | 309: 'LedgerNotFound', 38 | 400: 'AnoncredsRevocationRegistryFullError', 39 | 401: 'AnoncredsInvalidUserRevocId', 40 | 404: 'AnoncredsMasterSecretDuplicateNameError', 41 | 405: 'AnoncredsProofRejected', 42 | 406: 'AnoncredsCredentialRevoked', 43 | 407: 'AnoncredsCredDefAlreadyExistsError', 44 | 500: 'UnknownCryptoTypeError', 45 | 600: 'DidAlreadyExistsError', 46 | 700: 'PaymentUnknownMethodError', 47 | 701: 'PaymentIncompatibleMethodsError', 48 | 702: 'PaymentInsufficientFundsError', 49 | 703: 'PaymentSourceDoesNotExistError', 50 | 704: 'PaymentOperationNotSupportedError', 51 | 705: 'PaymentExtraFundsError', 52 | 706: 'TransactionNotAllowedError' 53 | } 54 | 55 | function IndyError (err) { 56 | Error.call(this) 57 | Error.captureStackTrace(this, this.constructor) 58 | this.name = this.constructor.name 59 | if (errors.hasOwnProperty(err)) { 60 | this.message = errors[err] 61 | this.indyCode = err 62 | this.indyName = errors[err] 63 | try { 64 | this.indyCurrentErrorJson = capi.getCurrentError() 65 | var details = JSON.parse(this.indyCurrentErrorJson) 66 | if (typeof details.message === 'string') { 67 | this.indyMessage = details.message 68 | } 69 | if (typeof details.backtrace === 'string') { 70 | this.indyBacktrace = details.backtrace 71 | } 72 | } catch (e) { 73 | } 74 | } else { 75 | this.message = (err + '') 76 | } 77 | } 78 | util.inherits(IndyError, Error) 79 | 80 | module.exports = IndyError 81 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | var capi = require('./indyBinding') 2 | var wrapIndyCallback = require('./wrapIndyCallback') 3 | var IndyError = require('./IndyError') 4 | 5 | function toJson (val) { 6 | if (val === null || val === void 0) { 7 | return null 8 | } 9 | if (typeof val === 'string') { 10 | return val 11 | } 12 | return JSON.stringify(val) 13 | } 14 | 15 | function fromJson (val) { 16 | if (typeof val === 'string' && val !== '') { 17 | try { 18 | return JSON.parse(val) 19 | } catch (e) { 20 | } 21 | } 22 | return val 23 | } 24 | 25 | var indy = {} 26 | 27 | indy.capi = capi // if you want to skip the json dance, IndyError, and promise support 28 | 29 | indy.setRuntimeConfig = function setRuntimeConfig (config) { 30 | var err = capi.setRuntimeConfig(toJson(config)) 31 | if (err !== 0) { 32 | throw new IndyError(err) 33 | } 34 | } 35 | 36 | indy.setDefaultLogger = function setDefaultLogger (pattern) { 37 | var err = capi.setDefaultLogger(pattern) 38 | if (err !== 0) { 39 | throw new IndyError(err) 40 | } 41 | } 42 | 43 | indy.setLogger = function setLogger (logFn) { 44 | var err = capi.setLogger(logFn) 45 | if (err !== 0) { 46 | throw new IndyError(err) 47 | } 48 | } 49 | 50 | indy.issuerCreateSchema = function issuerCreateSchema (issuerDid, name, version, attrNames, cb) { 51 | cb = wrapIndyCallback(cb, function (data) { 52 | return [data[0], fromJson(data[1])] 53 | }) 54 | capi.issuerCreateSchema(issuerDid, name, version, toJson(attrNames), cb) 55 | return cb.promise 56 | } 57 | 58 | indy.issuerCreateAndStoreCredentialDef = function issuerCreateAndStoreCredentialDef (wh, issuerDid, schema, tag, signatureType, config, cb) { 59 | cb = wrapIndyCallback(cb, function (data) { 60 | return [data[0], fromJson(data[1])] 61 | }) 62 | capi.issuerCreateAndStoreCredentialDef(wh, issuerDid, toJson(schema), tag, signatureType, toJson(config), cb) 63 | return cb.promise 64 | } 65 | 66 | indy.issuerRotateCredentialDefStart = function issuerRotateCredentialDefStart (wh, credDefId, config, cb) { 67 | cb = wrapIndyCallback(cb, function (data) { 68 | return fromJson(data[0]) 69 | }) 70 | capi.issuerRotateCredentialDefStart(wh, credDefId, toJson(config), cb) 71 | return cb.promise 72 | } 73 | 74 | indy.issuerRotateCredentialDefApply = function issuerRotateCredentialDefApply (wh, credDefId, cb) { 75 | cb = wrapIndyCallback(cb) 76 | capi.issuerRotateCredentialDefApply(wh, credDefId, cb) 77 | return cb.promise 78 | } 79 | 80 | indy.issuerCreateAndStoreRevocReg = function issuerCreateAndStoreRevocReg (wh, issuerDid, revocDefType, tag, credDefId, config, tailsWriterHandle, cb) { 81 | cb = wrapIndyCallback(cb, function (data) { 82 | return [data[0], fromJson(data[1]), fromJson(data[2])] 83 | }) 84 | capi.issuerCreateAndStoreRevocReg(wh, issuerDid, revocDefType, tag, credDefId, toJson(config), tailsWriterHandle, cb) 85 | return cb.promise 86 | } 87 | 88 | indy.issuerCreateCredentialOffer = function issuerCreateCredentialOffer (wh, credDefId, cb) { 89 | cb = wrapIndyCallback(cb, fromJson) 90 | capi.issuerCreateCredentialOffer(wh, credDefId, cb) 91 | return cb.promise 92 | } 93 | 94 | indy.issuerCreateCredential = function issuerCreateCredential (wh, credOffer, credReq, credValues, revRegId, blobStorageReaderHandle, cb) { 95 | cb = wrapIndyCallback(cb, function (data) { 96 | return [fromJson(data[0]), data[1], fromJson(data[2])] 97 | }) 98 | capi.issuerCreateCredential(wh, toJson(credOffer), toJson(credReq), toJson(credValues), revRegId, blobStorageReaderHandle, cb) 99 | return cb.promise 100 | } 101 | 102 | indy.issuerRevokeCredential = function issuerRevokeCredential (wh, blobStorageReaderHandle, revRegId, credRevocId, cb) { 103 | cb = wrapIndyCallback(cb, fromJson) 104 | capi.issuerRevokeCredential(wh, blobStorageReaderHandle, revRegId, credRevocId, cb) 105 | return cb.promise 106 | } 107 | 108 | indy.issuerMergeRevocationRegistryDeltas = function issuerMergeRevocationRegistryDeltas (revRegDelta, otherRevRegDelta, cb) { 109 | cb = wrapIndyCallback(cb, fromJson) 110 | capi.issuerMergeRevocationRegistryDeltas(toJson(revRegDelta), toJson(otherRevRegDelta), cb) 111 | return cb.promise 112 | } 113 | 114 | indy.proverCreateMasterSecret = function proverCreateMasterSecret (wh, masterSecretId, cb) { 115 | cb = wrapIndyCallback(cb) 116 | capi.proverCreateMasterSecret(wh, masterSecretId, cb) 117 | return cb.promise 118 | } 119 | 120 | indy.proverCreateCredentialReq = function proverCreateCredentialReq (wh, proverDid, credOffer, credDef, masterSecretId, cb) { 121 | cb = wrapIndyCallback(cb, function (data) { 122 | return [fromJson(data[0]), fromJson(data[1])] 123 | }) 124 | capi.proverCreateCredentialReq(wh, proverDid, toJson(credOffer), toJson(credDef), masterSecretId, cb) 125 | return cb.promise 126 | } 127 | 128 | indy.proverStoreCredential = function proverStoreCredential (wh, credId, credReqMetadata, cred, credDef, revRegDef, cb) { 129 | cb = wrapIndyCallback(cb) 130 | capi.proverStoreCredential(wh, credId, toJson(credReqMetadata), toJson(cred), toJson(credDef), toJson(revRegDef), cb) 131 | return cb.promise 132 | } 133 | 134 | indy.proverGetCredentials = function proverGetCredentials (wh, filter, cb) { 135 | cb = wrapIndyCallback(cb, fromJson) 136 | capi.proverGetCredentials(wh, toJson(filter), cb) 137 | return cb.promise 138 | } 139 | 140 | indy.proverGetCredential = function proverGetCredential (wh, credId, cb) { 141 | cb = wrapIndyCallback(cb, fromJson) 142 | capi.proverGetCredential(wh, credId, cb) 143 | return cb.promise 144 | } 145 | 146 | indy.proverSearchCredentials = function proverSearchCredentials (wh, query, cb) { 147 | cb = wrapIndyCallback(cb) 148 | capi.proverSearchCredentials(wh, toJson(query), cb) 149 | return cb.promise 150 | } 151 | 152 | indy.proverFetchCredentials = function proverFetchCredentials (sh, count, cb) { 153 | cb = wrapIndyCallback(cb, fromJson) 154 | capi.proverFetchCredentials(sh, count, cb) 155 | return cb.promise 156 | } 157 | 158 | indy.proverCloseCredentialsSearch = function proverCloseCredentialsSearch (sh, cb) { 159 | cb = wrapIndyCallback(cb) 160 | capi.proverCloseCredentialsSearch(sh, cb) 161 | return cb.promise 162 | } 163 | 164 | indy.proverGetCredentialsForProofReq = function proverGetCredentialsForProofReq (wh, proofRequest, cb) { 165 | cb = wrapIndyCallback(cb, fromJson) 166 | capi.proverGetCredentialsForProofReq(wh, toJson(proofRequest), cb) 167 | return cb.promise 168 | } 169 | 170 | indy.proverSearchCredentialsForProofReq = function proverSearchCredentialsForProofReq (wh, proofRequest, extraQuery, cb) { 171 | cb = wrapIndyCallback(cb) 172 | capi.proverSearchCredentialsForProofReq(wh, toJson(proofRequest), toJson(extraQuery), cb) 173 | return cb.promise 174 | } 175 | 176 | indy.proverFetchCredentialsForProofReq = function proverFetchCredentialsForProofReq (sh, itemReferent, count, cb) { 177 | cb = wrapIndyCallback(cb, fromJson) 178 | capi.proverFetchCredentialsForProofReq(sh, itemReferent, count, cb) 179 | return cb.promise 180 | } 181 | 182 | indy.proverCloseCredentialsSearchForProofReq = function proverCloseCredentialsSearchForProofReq (sh, cb) { 183 | cb = wrapIndyCallback(cb) 184 | capi.proverCloseCredentialsSearchForProofReq(sh, cb) 185 | return cb.promise 186 | } 187 | 188 | indy.proverCreateProof = function proverCreateProof (wh, proofReq, requestedCredentials, masterSecretName, schemas, credentialDefs, revStates, cb) { 189 | cb = wrapIndyCallback(cb, fromJson) 190 | capi.proverCreateProof(wh, toJson(proofReq), toJson(requestedCredentials), masterSecretName, toJson(schemas), toJson(credentialDefs), toJson(revStates), cb) 191 | return cb.promise 192 | } 193 | 194 | indy.verifierVerifyProof = function verifierVerifyProof (proofRequest, proof, schemas, credentialDefsJsons, revRegDefs, revRegs, cb) { 195 | cb = wrapIndyCallback(cb) 196 | capi.verifierVerifyProof(toJson(proofRequest), toJson(proof), toJson(schemas), toJson(credentialDefsJsons), toJson(revRegDefs), toJson(revRegs), cb) 197 | return cb.promise 198 | } 199 | 200 | indy.createRevocationState = function createRevocationState (blobStorageReaderHandle, revRegDef, revRegDelta, timestamp, credRevId, cb) { 201 | cb = wrapIndyCallback(cb, fromJson) 202 | capi.createRevocationState(blobStorageReaderHandle, toJson(revRegDef), toJson(revRegDelta), timestamp, credRevId, cb) 203 | return cb.promise 204 | } 205 | 206 | indy.updateRevocationState = function updateRevocationState (blobStorageReaderHandle, revState, revRegDef, revRegDelta, timestamp, credRevId, cb) { 207 | cb = wrapIndyCallback(cb, fromJson) 208 | capi.updateRevocationState(blobStorageReaderHandle, toJson(revState), toJson(revRegDef), toJson(revRegDelta), timestamp, credRevId, cb) 209 | return cb.promise 210 | } 211 | 212 | indy.generateNonce = function generateNonce (cb) { 213 | cb = wrapIndyCallback(cb) 214 | capi.generateNonce(cb) 215 | return cb.promise 216 | } 217 | 218 | indy.openBlobStorageReader = function openBlobStorageReader (type, config, cb) { 219 | cb = wrapIndyCallback(cb) 220 | capi.openBlobStorageReader(type, toJson(config), cb) 221 | return cb.promise 222 | } 223 | 224 | indy.openBlobStorageWriter = function openBlobStorageWriter (type, config, cb) { 225 | cb = wrapIndyCallback(cb) 226 | capi.openBlobStorageWriter(type, toJson(config), cb) 227 | return cb.promise 228 | } 229 | 230 | indy.createKey = function createKey (wh, key, cb) { 231 | cb = wrapIndyCallback(cb) 232 | capi.createKey(wh, toJson(key), cb) 233 | return cb.promise 234 | } 235 | 236 | indy.setKeyMetadata = function setKeyMetadata (wh, verkey, metadata, cb) { 237 | cb = wrapIndyCallback(cb) 238 | capi.setKeyMetadata(wh, verkey, metadata, cb) 239 | return cb.promise 240 | } 241 | 242 | indy.getKeyMetadata = function getKeyMetadata (wh, verkey, cb) { 243 | cb = wrapIndyCallback(cb) 244 | capi.getKeyMetadata(wh, verkey, cb) 245 | return cb.promise 246 | } 247 | 248 | indy.cryptoSign = function cryptoSign (wh, signerVk, messageRaw, cb) { 249 | cb = wrapIndyCallback(cb) 250 | capi.cryptoSign(wh, signerVk, messageRaw, cb) 251 | return cb.promise 252 | } 253 | 254 | indy.cryptoVerify = function cryptoVerify (signerVk, messageRaw, signatureRaw, cb) { 255 | cb = wrapIndyCallback(cb) 256 | capi.cryptoVerify(signerVk, messageRaw, signatureRaw, cb) 257 | return cb.promise 258 | } 259 | 260 | indy.cryptoAuthCrypt = function cryptoAuthCrypt (wh, senderVk, recipientVk, messageRaw, cb) { 261 | cb = wrapIndyCallback(cb) 262 | capi.cryptoAuthCrypt(wh, senderVk, recipientVk, messageRaw, cb) 263 | return cb.promise 264 | } 265 | 266 | indy.cryptoAuthDecrypt = function cryptoAuthDecrypt (wh, recipientVk, encryptedMsgRaw, cb) { 267 | cb = wrapIndyCallback(cb) 268 | capi.cryptoAuthDecrypt(wh, recipientVk, encryptedMsgRaw, cb) 269 | return cb.promise 270 | } 271 | 272 | indy.cryptoAnonCrypt = function cryptoAnonCrypt (recipientVk, messageRaw, cb) { 273 | cb = wrapIndyCallback(cb) 274 | capi.cryptoAnonCrypt(recipientVk, messageRaw, cb) 275 | return cb.promise 276 | } 277 | 278 | indy.cryptoAnonDecrypt = function cryptoAnonDecrypt (wh, recipientVk, encryptedMsg, cb) { 279 | cb = wrapIndyCallback(cb) 280 | capi.cryptoAnonDecrypt(wh, recipientVk, encryptedMsg, cb) 281 | return cb.promise 282 | } 283 | 284 | indy.packMessage = function packMessage (wh, message, receiverKeys, sender, cb) { 285 | cb = wrapIndyCallback(cb) 286 | capi.packMessage(wh, message, toJson(receiverKeys), sender, cb) 287 | return cb.promise 288 | } 289 | 290 | indy.unpackMessage = function unpackMessage (wh, jwe, cb) { 291 | cb = wrapIndyCallback(cb) 292 | capi.unpackMessage(wh, jwe, cb) 293 | return cb.promise 294 | } 295 | 296 | indy.createAndStoreMyDid = function createAndStoreMyDid (wh, did, cb) { 297 | cb = wrapIndyCallback(cb) 298 | capi.createAndStoreMyDid(wh, toJson(did), cb) 299 | return cb.promise 300 | } 301 | 302 | indy.replaceKeysStart = function replaceKeysStart (wh, did, identity, cb) { 303 | cb = wrapIndyCallback(cb) 304 | capi.replaceKeysStart(wh, did, toJson(identity), cb) 305 | return cb.promise 306 | } 307 | 308 | indy.replaceKeysApply = function replaceKeysApply (wh, did, cb) { 309 | cb = wrapIndyCallback(cb) 310 | capi.replaceKeysApply(wh, did, cb) 311 | return cb.promise 312 | } 313 | 314 | indy.storeTheirDid = function storeTheirDid (wh, identity, cb) { 315 | cb = wrapIndyCallback(cb) 316 | capi.storeTheirDid(wh, toJson(identity), cb) 317 | return cb.promise 318 | } 319 | 320 | indy.keyForDid = function keyForDid (poolHandle, wh, did, cb) { 321 | cb = wrapIndyCallback(cb) 322 | capi.keyForDid(poolHandle, wh, did, cb) 323 | return cb.promise 324 | } 325 | 326 | indy.keyForLocalDid = function keyForLocalDid (wh, did, cb) { 327 | cb = wrapIndyCallback(cb) 328 | capi.keyForLocalDid(wh, did, cb) 329 | return cb.promise 330 | } 331 | 332 | indy.setEndpointForDid = function setEndpointForDid (wh, did, address, transportKey, cb) { 333 | cb = wrapIndyCallback(cb) 334 | capi.setEndpointForDid(wh, did, address, transportKey, cb) 335 | return cb.promise 336 | } 337 | 338 | indy.getEndpointForDid = function getEndpointForDid (wh, poolHandle, did, cb) { 339 | cb = wrapIndyCallback(cb) 340 | capi.getEndpointForDid(wh, poolHandle, did, cb) 341 | return cb.promise 342 | } 343 | 344 | indy.setDidMetadata = function setDidMetadata (wh, did, metadata, cb) { 345 | cb = wrapIndyCallback(cb) 346 | capi.setDidMetadata(wh, did, metadata, cb) 347 | return cb.promise 348 | } 349 | 350 | indy.getDidMetadata = function getDidMetadata (wh, did, cb) { 351 | cb = wrapIndyCallback(cb) 352 | capi.getDidMetadata(wh, did, cb) 353 | return cb.promise 354 | } 355 | 356 | indy.getMyDidWithMeta = function getMyDidWithMeta (wh, myDid, cb) { 357 | cb = wrapIndyCallback(cb, fromJson) 358 | capi.getMyDidWithMeta(wh, myDid, cb) 359 | return cb.promise 360 | } 361 | 362 | indy.listMyDidsWithMeta = function listMyDidsWithMeta (wh, cb) { 363 | cb = wrapIndyCallback(cb, fromJson) 364 | capi.listMyDidsWithMeta(wh, cb) 365 | return cb.promise 366 | } 367 | 368 | indy.abbreviateVerkey = function abbreviateVerkey (did, fullVerkey, cb) { 369 | cb = wrapIndyCallback(cb) 370 | capi.abbreviateVerkey(did, fullVerkey, cb) 371 | return cb.promise 372 | } 373 | 374 | indy.signAndSubmitRequest = function signAndSubmitRequest (poolHandle, wh, submitterDid, request, cb) { 375 | cb = wrapIndyCallback(cb, fromJson) 376 | capi.signAndSubmitRequest(poolHandle, wh, submitterDid, toJson(request), cb) 377 | return cb.promise 378 | } 379 | 380 | indy.submitRequest = function submitRequest (poolHandle, request, cb) { 381 | cb = wrapIndyCallback(cb, fromJson) 382 | capi.submitRequest(poolHandle, toJson(request), cb) 383 | return cb.promise 384 | } 385 | 386 | indy.submitAction = function submitAction (poolHandle, request, nodes, timeout, cb) { 387 | cb = wrapIndyCallback(cb, fromJson) 388 | capi.submitAction(poolHandle, toJson(request), toJson(nodes), timeout == null ? -1 : timeout, cb) 389 | return cb.promise 390 | } 391 | 392 | indy.signRequest = function signRequest (wh, submitterDid, request, cb) { 393 | cb = wrapIndyCallback(cb, fromJson) 394 | capi.signRequest(wh, submitterDid, toJson(request), cb) 395 | return cb.promise 396 | } 397 | 398 | indy.multiSignRequest = function multiSignRequest (wh, submitterDid, request, cb) { 399 | cb = wrapIndyCallback(cb, fromJson) 400 | capi.multiSignRequest(wh, submitterDid, toJson(request), cb) 401 | return cb.promise 402 | } 403 | 404 | indy.buildGetDdoRequest = function buildGetDdoRequest (submitterDid, targetDid, cb) { 405 | cb = wrapIndyCallback(cb, fromJson) 406 | capi.buildGetDdoRequest(submitterDid, targetDid, cb) 407 | return cb.promise 408 | } 409 | 410 | indy.buildNymRequest = function buildNymRequest (submitterDid, targetDid, verkey, alias, role, cb) { 411 | cb = wrapIndyCallback(cb, fromJson) 412 | capi.buildNymRequest(submitterDid, targetDid, verkey, alias, role, cb) 413 | return cb.promise 414 | } 415 | 416 | indy.buildAttribRequest = function buildAttribRequest (submitterDid, targetDid, hash, raw, enc, cb) { 417 | cb = wrapIndyCallback(cb, fromJson) 418 | capi.buildAttribRequest(submitterDid, targetDid, hash, toJson(raw), enc, cb) 419 | return cb.promise 420 | } 421 | 422 | indy.buildGetAttribRequest = function buildGetAttribRequest (submitterDid, targetDid, hash, raw, enc, cb) { 423 | cb = wrapIndyCallback(cb, fromJson) 424 | capi.buildGetAttribRequest(submitterDid, targetDid, hash, raw, enc, cb) 425 | return cb.promise 426 | } 427 | 428 | indy.buildGetNymRequest = function buildGetNymRequest (submitterDid, targetDid, cb) { 429 | cb = wrapIndyCallback(cb, fromJson) 430 | capi.buildGetNymRequest(submitterDid, targetDid, cb) 431 | return cb.promise 432 | } 433 | 434 | indy.buildSchemaRequest = function buildSchemaRequest (submitterDid, data, cb) { 435 | cb = wrapIndyCallback(cb, fromJson) 436 | capi.buildSchemaRequest(submitterDid, toJson(data), cb) 437 | return cb.promise 438 | } 439 | 440 | indy.buildGetSchemaRequest = function buildGetSchemaRequest (submitterDid, id, cb) { 441 | cb = wrapIndyCallback(cb, fromJson) 442 | capi.buildGetSchemaRequest(submitterDid, id, cb) 443 | return cb.promise 444 | } 445 | 446 | indy.parseGetSchemaResponse = function parseGetSchemaResponse (getSchemaResponse, cb) { 447 | cb = wrapIndyCallback(cb, function (data) { 448 | return [data[0], fromJson(data[1])] 449 | }) 450 | capi.parseGetSchemaResponse(toJson(getSchemaResponse), cb) 451 | return cb.promise 452 | } 453 | 454 | indy.buildCredDefRequest = function buildCredDefRequest (submitterDid, data, cb) { 455 | cb = wrapIndyCallback(cb, fromJson) 456 | capi.buildCredDefRequest(submitterDid, toJson(data), cb) 457 | return cb.promise 458 | } 459 | 460 | indy.buildGetCredDefRequest = function buildGetCredDefRequest (submitterDid, id, cb) { 461 | cb = wrapIndyCallback(cb, fromJson) 462 | capi.buildGetCredDefRequest(submitterDid, id, cb) 463 | return cb.promise 464 | } 465 | 466 | indy.parseGetCredDefResponse = function parseGetCredDefResponse (getCredDefResponse, cb) { 467 | cb = wrapIndyCallback(cb, function (data) { 468 | return [data[0], fromJson(data[1])] 469 | }) 470 | capi.parseGetCredDefResponse(toJson(getCredDefResponse), cb) 471 | return cb.promise 472 | } 473 | 474 | indy.buildNodeRequest = function buildNodeRequest (submitterDid, targetDid, data, cb) { 475 | cb = wrapIndyCallback(cb, fromJson) 476 | capi.buildNodeRequest(submitterDid, targetDid, toJson(data), cb) 477 | return cb.promise 478 | } 479 | 480 | indy.buildGetValidatorInfoRequest = function buildGetValidatorInfoRequest (submitterDid, cb) { 481 | cb = wrapIndyCallback(cb, fromJson) 482 | capi.buildGetValidatorInfoRequest(submitterDid, cb) 483 | return cb.promise 484 | } 485 | 486 | indy.buildGetTxnRequest = function buildGetTxnRequest (submitterDid, ledgerType, seqNo, cb) { 487 | cb = wrapIndyCallback(cb, fromJson) 488 | capi.buildGetTxnRequest(submitterDid, ledgerType, seqNo, cb) 489 | return cb.promise 490 | } 491 | 492 | indy.buildPoolConfigRequest = function buildPoolConfigRequest (submitterDid, writes, force, cb) { 493 | cb = wrapIndyCallback(cb, fromJson) 494 | capi.buildPoolConfigRequest(submitterDid, writes, force, cb) 495 | return cb.promise 496 | } 497 | 498 | indy.buildPoolRestartRequest = function buildPoolRestartRequest (submitterDid, action, datetime, cb) { 499 | cb = wrapIndyCallback(cb, fromJson) 500 | capi.buildPoolRestartRequest(submitterDid, action, datetime, cb) 501 | return cb.promise 502 | } 503 | 504 | indy.buildPoolUpgradeRequest = function buildPoolUpgradeRequest (submitterDid, name, version, action, sha256, timeout, schedule, justification, reinstall, force, package_, cb) { 505 | cb = wrapIndyCallback(cb, fromJson) 506 | capi.buildPoolUpgradeRequest(submitterDid, name, version, action, sha256, timeout, schedule, justification, reinstall, force, package_, cb) 507 | return cb.promise 508 | } 509 | 510 | indy.buildRevocRegDefRequest = function buildRevocRegDefRequest (submitterDid, data, cb) { 511 | cb = wrapIndyCallback(cb, fromJson) 512 | capi.buildRevocRegDefRequest(submitterDid, toJson(data), cb) 513 | return cb.promise 514 | } 515 | 516 | indy.buildGetRevocRegDefRequest = function buildGetRevocRegDefRequest (submitterDid, id, cb) { 517 | cb = wrapIndyCallback(cb, fromJson) 518 | capi.buildGetRevocRegDefRequest(submitterDid, id, cb) 519 | return cb.promise 520 | } 521 | 522 | indy.parseGetRevocRegDefResponse = function parseGetRevocRegDefResponse (getRevocRefDefResponse, cb) { 523 | cb = wrapIndyCallback(cb, function (data) { 524 | return [data[0], fromJson(data[1])] 525 | }) 526 | capi.parseGetRevocRegDefResponse(toJson(getRevocRefDefResponse), cb) 527 | return cb.promise 528 | } 529 | 530 | indy.buildRevocRegEntryRequest = function buildRevocRegEntryRequest (submitterDid, revocRegDefId, revDefType, value, cb) { 531 | cb = wrapIndyCallback(cb, fromJson) 532 | capi.buildRevocRegEntryRequest(submitterDid, revocRegDefId, revDefType, toJson(value), cb) 533 | return cb.promise 534 | } 535 | 536 | indy.buildGetRevocRegRequest = function buildGetRevocRegRequest (submitterDid, revocRegDefId, timestamp, cb) { 537 | cb = wrapIndyCallback(cb, fromJson) 538 | capi.buildGetRevocRegRequest(submitterDid, revocRegDefId, timestamp, cb) 539 | return cb.promise 540 | } 541 | 542 | indy.parseGetRevocRegResponse = function parseGetRevocRegResponse (getRevocRegResponse, cb) { 543 | cb = wrapIndyCallback(cb, function (data) { 544 | return [data[0], fromJson(data[1]), data[2]] 545 | }) 546 | capi.parseGetRevocRegResponse(toJson(getRevocRegResponse), cb) 547 | return cb.promise 548 | } 549 | 550 | indy.buildGetRevocRegDeltaRequest = function buildGetRevocRegDeltaRequest (submitterDid, revocRegDefId, from, to, cb) { 551 | cb = wrapIndyCallback(cb, fromJson) 552 | capi.buildGetRevocRegDeltaRequest(submitterDid, revocRegDefId, from, to, cb) 553 | return cb.promise 554 | } 555 | 556 | indy.parseGetRevocRegDeltaResponse = function parseGetRevocRegDeltaResponse (getRevocRegDeltaResponse, cb) { 557 | cb = wrapIndyCallback(cb, function (data) { 558 | return [data[0], fromJson(data[1]), data[2]] 559 | }) 560 | capi.parseGetRevocRegDeltaResponse(toJson(getRevocRegDeltaResponse), cb) 561 | return cb.promise 562 | } 563 | 564 | indy.buildAuthRuleRequest = function buildAuthRuleRequest (submitterDid, txnType, action, field, oldValue, newValue, constraint, cb) { 565 | cb = wrapIndyCallback(cb, fromJson) 566 | capi.buildAuthRuleRequest(submitterDid, txnType, action, field, oldValue, newValue, toJson(constraint), cb) 567 | return cb.promise 568 | } 569 | 570 | indy.buildAuthRulesRequest = function buildAuthRulesRequest (submitterDid, data, cb) { 571 | cb = wrapIndyCallback(cb, fromJson) 572 | capi.buildAuthRulesRequest(submitterDid, toJson(data), cb) 573 | return cb.promise 574 | } 575 | 576 | indy.buildGetAuthRuleRequest = function buildGetAuthRuleRequest (submitterDid, txnType, action, field, oldValue, newValue, cb) { 577 | cb = wrapIndyCallback(cb, fromJson) 578 | capi.buildGetAuthRuleRequest(submitterDid, txnType, action, field, oldValue, newValue, cb) 579 | return cb.promise 580 | } 581 | 582 | indy.buildTxnAuthorAgreementRequest = function buildTxnAuthorAgreementRequest (submitterDid, text, version, cb) { 583 | cb = wrapIndyCallback(cb, fromJson) 584 | capi.buildTxnAuthorAgreementRequest(submitterDid, text, version, cb) 585 | return cb.promise 586 | } 587 | 588 | indy.buildGetTxnAuthorAgreementRequest = function buildGetTxnAuthorAgreementRequest (submitterDid, data, cb) { 589 | cb = wrapIndyCallback(cb, fromJson) 590 | capi.buildGetTxnAuthorAgreementRequest(submitterDid, toJson(data), cb) 591 | return cb.promise 592 | } 593 | 594 | indy.buildAcceptanceMechanismsRequest = function buildAcceptanceMechanismsRequest (submitterDid, aml, version, amlContext, cb) { 595 | cb = wrapIndyCallback(cb, fromJson) 596 | capi.buildAcceptanceMechanismsRequest(submitterDid, toJson(aml), version, amlContext, cb) 597 | return cb.promise 598 | } 599 | 600 | indy.buildGetAcceptanceMechanismsRequest = function buildGetAcceptanceMechanismsRequest (submitterDid, timestamp, version, cb) { 601 | cb = wrapIndyCallback(cb, fromJson) 602 | capi.buildGetAcceptanceMechanismsRequest(submitterDid, timestamp == null ? -1 : timestamp, version, cb) 603 | return cb.promise 604 | } 605 | 606 | indy.appendTxnAuthorAgreementAcceptanceToRequest = function appendTxnAuthorAgreementAcceptanceToRequest (request, text, version, taaDigest, accMechType, timeOfAcceptance, cb) { 607 | cb = wrapIndyCallback(cb, fromJson) 608 | capi.appendTxnAuthorAgreementAcceptanceToRequest(toJson(request), text, version, taaDigest, accMechType, timeOfAcceptance, cb) 609 | return cb.promise 610 | } 611 | 612 | indy.appendRequestEndorser = function appendRequestEndorser (request, endorserDid, cb) { 613 | cb = wrapIndyCallback(cb, fromJson) 614 | capi.appendRequestEndorser(toJson(request), endorserDid, cb) 615 | return cb.promise 616 | } 617 | 618 | indy.getResponseMetadata = function getResponseMetadata (response, cb) { 619 | cb = wrapIndyCallback(cb, fromJson) 620 | capi.getResponseMetadata(toJson(response), cb) 621 | return cb.promise 622 | } 623 | 624 | indy.addWalletRecord = function addWalletRecord (wh, type, id, value, tags, cb) { 625 | cb = wrapIndyCallback(cb) 626 | capi.addWalletRecord(wh, type, id, value, toJson(tags), cb) 627 | return cb.promise 628 | } 629 | 630 | indy.updateWalletRecordValue = function updateWalletRecordValue (wh, type, id, value, cb) { 631 | cb = wrapIndyCallback(cb) 632 | capi.updateWalletRecordValue(wh, type, id, value, cb) 633 | return cb.promise 634 | } 635 | 636 | indy.updateWalletRecordTags = function updateWalletRecordTags (wh, type, id, tags, cb) { 637 | cb = wrapIndyCallback(cb) 638 | capi.updateWalletRecordTags(wh, type, id, toJson(tags), cb) 639 | return cb.promise 640 | } 641 | 642 | indy.addWalletRecordTags = function addWalletRecordTags (wh, type, id, tags, cb) { 643 | cb = wrapIndyCallback(cb) 644 | capi.addWalletRecordTags(wh, type, id, toJson(tags), cb) 645 | return cb.promise 646 | } 647 | 648 | indy.deleteWalletRecordTags = function deleteWalletRecordTags (wh, type, id, tagNames, cb) { 649 | cb = wrapIndyCallback(cb) 650 | capi.deleteWalletRecordTags(wh, type, id, toJson(tagNames), cb) 651 | return cb.promise 652 | } 653 | 654 | indy.deleteWalletRecord = function deleteWalletRecord (wh, type, id, cb) { 655 | cb = wrapIndyCallback(cb) 656 | capi.deleteWalletRecord(wh, type, id, cb) 657 | return cb.promise 658 | } 659 | 660 | indy.getWalletRecord = function getWalletRecord (wh, type, id, options, cb) { 661 | cb = wrapIndyCallback(cb, fromJson) 662 | capi.getWalletRecord(wh, type, id, toJson(options), cb) 663 | return cb.promise 664 | } 665 | 666 | indy.openWalletSearch = function openWalletSearch (wh, type, query, options, cb) { 667 | cb = wrapIndyCallback(cb) 668 | capi.openWalletSearch(wh, type, toJson(query), toJson(options), cb) 669 | return cb.promise 670 | } 671 | 672 | indy.fetchWalletSearchNextRecords = function fetchWalletSearchNextRecords (wh, walletSearchHandle, count, cb) { 673 | cb = wrapIndyCallback(cb, fromJson) 674 | capi.fetchWalletSearchNextRecords(wh, walletSearchHandle, count, cb) 675 | return cb.promise 676 | } 677 | 678 | indy.closeWalletSearch = function closeWalletSearch (walletSearchHandle, cb) { 679 | cb = wrapIndyCallback(cb) 680 | capi.closeWalletSearch(walletSearchHandle, cb) 681 | return cb.promise 682 | } 683 | 684 | indy.getSchema = function getSchema (poolHandle, wh, submitterDid, id, options, cb) { 685 | cb = wrapIndyCallback(cb, function (data) { 686 | return fromJson(data) 687 | }) 688 | capi.getSchema(poolHandle, wh, submitterDid, id, toJson(options), cb) 689 | return cb.promise 690 | } 691 | 692 | indy.getCredDef = function getCredDef (poolHandle, wh, submitterDid, id, options, cb) { 693 | cb = wrapIndyCallback(cb, function (data) { 694 | return fromJson(data) 695 | }) 696 | capi.getCredDef(poolHandle, wh, submitterDid, id, toJson(options), cb) 697 | return cb.promise 698 | } 699 | 700 | indy.purgeSchemaCache = function purgeSchemaCache (wh, options, cb) { 701 | cb = wrapIndyCallback(cb) 702 | capi.purgeSchemaCache(wh, toJson(options), cb) 703 | return cb.promise 704 | } 705 | 706 | indy.purgeCredDefCache = function purgeCredDefCache (wh, options, cb) { 707 | cb = wrapIndyCallback(cb) 708 | capi.purgeCredDefCache(wh, toJson(options), cb) 709 | return cb.promise 710 | } 711 | 712 | indy.isPairwiseExists = function isPairwiseExists (wh, theirDid, cb) { 713 | cb = wrapIndyCallback(cb) 714 | capi.isPairwiseExists(wh, theirDid, cb) 715 | return cb.promise 716 | } 717 | 718 | indy.createPairwise = function createPairwise (wh, theirDid, myDid, metadata, cb) { 719 | cb = wrapIndyCallback(cb) 720 | capi.createPairwise(wh, theirDid, myDid, metadata, cb) 721 | return cb.promise 722 | } 723 | 724 | indy.listPairwise = function listPairwise (wh, cb) { 725 | cb = wrapIndyCallback(cb, function (data) { 726 | return fromJson(data).map(fromJson) 727 | }) 728 | capi.listPairwise(wh, cb) 729 | return cb.promise 730 | } 731 | 732 | indy.getPairwise = function getPairwise (wh, theirDid, cb) { 733 | cb = wrapIndyCallback(cb, fromJson) 734 | capi.getPairwise(wh, theirDid, cb) 735 | return cb.promise 736 | } 737 | 738 | indy.setPairwiseMetadata = function setPairwiseMetadata (wh, theirDid, metadata, cb) { 739 | cb = wrapIndyCallback(cb) 740 | capi.setPairwiseMetadata(wh, theirDid, metadata, cb) 741 | return cb.promise 742 | } 743 | 744 | indy.createPaymentAddress = function createPaymentAddress (wh, paymentMethod, config, cb) { 745 | cb = wrapIndyCallback(cb) 746 | capi.createPaymentAddress(wh, paymentMethod, toJson(config), cb) 747 | return cb.promise 748 | } 749 | 750 | indy.listPaymentAddresses = function listPaymentAddresses (wh, cb) { 751 | cb = wrapIndyCallback(cb, fromJson) 752 | capi.listPaymentAddresses(wh, cb) 753 | return cb.promise 754 | } 755 | 756 | indy.addRequestFees = function addRequestFees (wh, submitterDid, req, inputs, outputs, extra, cb) { 757 | cb = wrapIndyCallback(cb, function (data) { 758 | return [fromJson(data[0]), data[1]] 759 | }) 760 | capi.addRequestFees(wh, submitterDid, toJson(req), toJson(inputs), toJson(outputs), extra, cb) 761 | return cb.promise 762 | } 763 | 764 | indy.parseResponseWithFees = function parseResponseWithFees (paymentMethod, resp, cb) { 765 | cb = wrapIndyCallback(cb, fromJson) 766 | capi.parseResponseWithFees(paymentMethod, toJson(resp), cb) 767 | return cb.promise 768 | } 769 | 770 | indy.buildGetPaymentSourcesRequest = function buildGetPaymentSourcesRequest (wh, submitterDid, paymentAddress, cb) { 771 | cb = wrapIndyCallback(cb, function (data) { 772 | return [fromJson(data[0]), data[1]] 773 | }) 774 | capi.buildGetPaymentSourcesRequest(wh, submitterDid, paymentAddress, cb) 775 | return cb.promise 776 | } 777 | 778 | indy.buildGetPaymentSourcesWithFromRequest = function buildGetPaymentSourcesWithFromRequest (wh, submitterDid, paymentAddress, from, cb) { 779 | cb = wrapIndyCallback(cb, function (data) { 780 | return [fromJson(data[0]), data[1]] 781 | }) 782 | capi.buildGetPaymentSourcesWithFromRequest(wh, submitterDid, paymentAddress, from, cb) 783 | return cb.promise 784 | } 785 | 786 | indy.parseGetPaymentSourcesResponse = function parseGetPaymentSourcesResponse (paymentMethod, resp, cb) { 787 | cb = wrapIndyCallback(cb, fromJson) 788 | capi.parseGetPaymentSourcesResponse(paymentMethod, toJson(resp), cb) 789 | return cb.promise 790 | } 791 | 792 | indy.parseGetPaymentSourcesWithFromResponse = function parseGetPaymentSourcesWithFromResponse (paymentMethod, resp, cb) { 793 | cb = wrapIndyCallback(cb, function (data) { 794 | return [fromJson(data[0]), data[1]] 795 | }) 796 | capi.parseGetPaymentSourcesWithFromResponse(paymentMethod, toJson(resp), cb) 797 | return cb.promise 798 | } 799 | 800 | indy.buildPaymentReq = function buildPaymentReq (wh, submitterDid, inputs, outputs, extra, cb) { 801 | cb = wrapIndyCallback(cb, function (data) { 802 | return [fromJson(data[0]), data[1]] 803 | }) 804 | capi.buildPaymentReq(wh, submitterDid, toJson(inputs), toJson(outputs), extra, cb) 805 | return cb.promise 806 | } 807 | 808 | indy.parsePaymentResponse = function parsePaymentResponse (paymentMethod, resp, cb) { 809 | cb = wrapIndyCallback(cb, fromJson) 810 | capi.parsePaymentResponse(paymentMethod, toJson(resp), cb) 811 | return cb.promise 812 | } 813 | 814 | indy.preparePaymentExtraWithAcceptanceData = function preparePaymentExtraWithAcceptanceData (extra, text, version, taaDigest, accMechType, timeOfAcceptance, cb) { 815 | cb = wrapIndyCallback(cb, fromJson) 816 | capi.preparePaymentExtraWithAcceptanceData(toJson(extra), text, version, taaDigest, accMechType, timeOfAcceptance, cb) 817 | return cb.promise 818 | } 819 | 820 | indy.buildMintReq = function buildMintReq (wh, submitterDid, outputs, extra, cb) { 821 | cb = wrapIndyCallback(cb, function (data) { 822 | return [fromJson(data[0]), data[1]] 823 | }) 824 | capi.buildMintReq(wh, submitterDid, toJson(outputs), extra, cb) 825 | return cb.promise 826 | } 827 | 828 | indy.buildSetTxnFeesReq = function buildSetTxnFeesReq (wh, submitterDid, paymentMethod, fees, cb) { 829 | cb = wrapIndyCallback(cb, fromJson) 830 | capi.buildSetTxnFeesReq(wh, submitterDid, paymentMethod, toJson(fees), cb) 831 | return cb.promise 832 | } 833 | 834 | indy.buildGetTxnFeesReq = function buildGetTxnFeesReq (wh, submitterDid, paymentMethod, cb) { 835 | cb = wrapIndyCallback(cb, fromJson) 836 | capi.buildGetTxnFeesReq(wh, submitterDid, paymentMethod, cb) 837 | return cb.promise 838 | } 839 | 840 | indy.parseGetTxnFeesResponse = function parseGetTxnFeesResponse (paymentMethod, resp, cb) { 841 | cb = wrapIndyCallback(cb, fromJson) 842 | capi.parseGetTxnFeesResponse(paymentMethod, toJson(resp), cb) 843 | return cb.promise 844 | } 845 | 846 | indy.buildVerifyPaymentReq = function buildVerifyPaymentReq (wh, submitterDid, receipt, cb) { 847 | cb = wrapIndyCallback(cb, function (data) { 848 | return [fromJson(data[0]), data[1]] 849 | }) 850 | capi.buildVerifyPaymentReq(wh, submitterDid, receipt, cb) 851 | return cb.promise 852 | } 853 | 854 | indy.parseVerifyPaymentResponse = function parseVerifyPaymentResponse (paymentMethod, resp, cb) { 855 | cb = wrapIndyCallback(cb, fromJson) 856 | capi.parseVerifyPaymentResponse(paymentMethod, toJson(resp), cb) 857 | return cb.promise 858 | } 859 | 860 | indy.getRequestInfo = function getRequestInfo (getAuthRuleResponse, requesterInfo, fees, cb) { 861 | cb = wrapIndyCallback(cb, function (data) { 862 | return fromJson(data) 863 | }) 864 | capi.getRequestInfo(toJson(getAuthRuleResponse), toJson(requesterInfo), toJson(fees), cb) 865 | return cb.promise 866 | } 867 | 868 | indy.signWithAddress = function signWithAddress (wh, address, message, cb) { 869 | cb = wrapIndyCallback(cb) 870 | capi.signWithAddress(wh, address, message, cb) 871 | return cb.promise 872 | } 873 | 874 | indy.verifyWithAddress = function verifyWithAddress (address, message, signature, cb) { 875 | cb = wrapIndyCallback(cb) 876 | capi.verifyWithAddress(address, message, signature, cb) 877 | return cb.promise 878 | } 879 | 880 | indy.createPoolLedgerConfig = function createPoolLedgerConfig (configName, config, cb) { 881 | cb = wrapIndyCallback(cb) 882 | capi.createPoolLedgerConfig(configName, toJson(config), cb) 883 | return cb.promise 884 | } 885 | 886 | indy.openPoolLedger = function openPoolLedger (configName, config, cb) { 887 | cb = wrapIndyCallback(cb) 888 | capi.openPoolLedger(configName, toJson(config), cb) 889 | return cb.promise 890 | } 891 | 892 | indy.refreshPoolLedger = function refreshPoolLedger (handle, cb) { 893 | cb = wrapIndyCallback(cb) 894 | capi.refreshPoolLedger(handle, cb) 895 | return cb.promise 896 | } 897 | 898 | indy.listPools = function listPools (cb) { 899 | cb = wrapIndyCallback(cb, fromJson) 900 | capi.listPools(cb) 901 | return cb.promise 902 | } 903 | 904 | indy.closePoolLedger = function closePoolLedger (handle, cb) { 905 | cb = wrapIndyCallback(cb) 906 | capi.closePoolLedger(handle, cb) 907 | return cb.promise 908 | } 909 | 910 | indy.deletePoolLedgerConfig = function deletePoolLedgerConfig (configName, cb) { 911 | cb = wrapIndyCallback(cb) 912 | capi.deletePoolLedgerConfig(configName, cb) 913 | return cb.promise 914 | } 915 | 916 | indy.setProtocolVersion = function setProtocolVersion (protocolVersion, cb) { 917 | cb = wrapIndyCallback(cb) 918 | capi.setProtocolVersion(protocolVersion, cb) 919 | return cb.promise 920 | } 921 | 922 | indy.createWallet = function createWallet (config, credentials, cb) { 923 | cb = wrapIndyCallback(cb) 924 | capi.createWallet(toJson(config), toJson(credentials), cb) 925 | return cb.promise 926 | } 927 | 928 | indy.openWallet = function openWallet (config, credentials, cb) { 929 | cb = wrapIndyCallback(cb) 930 | capi.openWallet(toJson(config), toJson(credentials), cb) 931 | return cb.promise 932 | } 933 | 934 | indy.exportWallet = function exportWallet (wh, exportConfig, cb) { 935 | cb = wrapIndyCallback(cb) 936 | capi.exportWallet(wh, toJson(exportConfig), cb) 937 | return cb.promise 938 | } 939 | 940 | indy.importWallet = function importWallet (config, credentials, importConfig, cb) { 941 | cb = wrapIndyCallback(cb) 942 | capi.importWallet(toJson(config), toJson(credentials), toJson(importConfig), cb) 943 | return cb.promise 944 | } 945 | 946 | indy.closeWallet = function closeWallet (wh, cb) { 947 | cb = wrapIndyCallback(cb) 948 | capi.closeWallet(wh, cb) 949 | return cb.promise 950 | } 951 | 952 | indy.deleteWallet = function deleteWallet (config, credentials, cb) { 953 | cb = wrapIndyCallback(cb) 954 | capi.deleteWallet(toJson(config), toJson(credentials), cb) 955 | return cb.promise 956 | } 957 | 958 | indy.generateWalletKey = function generateWalletKey (config, cb) { 959 | cb = wrapIndyCallback(cb) 960 | capi.generateWalletKey(toJson(config), cb) 961 | return cb.promise 962 | } 963 | 964 | module.exports = indy 965 | -------------------------------------------------------------------------------- /src/indyBinding.js: -------------------------------------------------------------------------------- 1 | module.exports = require('bindings')('indynodejs') 2 | -------------------------------------------------------------------------------- /src/wrapIndyCallback.js: -------------------------------------------------------------------------------- 1 | var IndyError = require('./IndyError') 2 | 3 | function wrapIndyCallback (cb, mapResponse) { 4 | var promise 5 | if (!cb) { 6 | promise = new Promise(function (resolve, reject) { 7 | cb = function cb (err, data) { 8 | if (err) reject(err) 9 | else resolve(data) 10 | } 11 | }) 12 | } 13 | function callback (err, data) { 14 | if (err) { 15 | cb(new IndyError(err)) 16 | return 17 | } 18 | if (mapResponse) { 19 | data = mapResponse(data) 20 | } 21 | cb(null, data) 22 | } 23 | callback.promise = promise 24 | return callback 25 | } 26 | 27 | module.exports = wrapIndyCallback 28 | -------------------------------------------------------------------------------- /test/anoncreds.js: -------------------------------------------------------------------------------- 1 | var test = require('ava') 2 | var indy = require('../') 3 | var cuid = require('cuid') 4 | var initTestPool = require('./helpers/initTestPool') 5 | var tempy = require('tempy') 6 | 7 | test('anoncreds', async function (t) { 8 | var pool = await initTestPool() 9 | var walletConfig = { 'id': 'wallet-' + cuid() } 10 | var walletCredentials = { 'key': 'key' } 11 | await indy.createWallet(walletConfig, walletCredentials) 12 | var wh = await indy.openWallet(walletConfig, walletCredentials) 13 | var issuerDid = 'NcYxiDXkpYi6ov5FcYDi1e' 14 | var proverDid = 'VsKV7grR1BUE29mG2Fm2kX' 15 | 16 | // Issuer create a credential schema 17 | var [schemaId, schema] = await indy.issuerCreateSchema(issuerDid, 'gvt', '1.0', ['age', 'height', 'name']) 18 | t.not(typeof schema, 'string') 19 | 20 | var [credDefId, credDef] = await indy.issuerCreateAndStoreCredentialDef(wh, issuerDid, schema, 'tag1', 'CL', { 21 | support_revocation: true 22 | }) 23 | t.not(typeof credDef, 'string') 24 | 25 | // Issuer create Revocation Registry 26 | var tailsWriterConfig = { 27 | 'base_dir': tempy.directory(), 28 | 'uri_pattern': '' 29 | } 30 | var tailsWriterHandle = await indy.openBlobStorageWriter('default', tailsWriterConfig) 31 | var [revocRegId, revocRegDef, revocRegEntry] = await indy.issuerCreateAndStoreRevocReg(wh, issuerDid, null, 'tag1', credDefId, { 32 | max_cred_num: 5 33 | }, tailsWriterHandle) 34 | t.not(typeof revocRegDef, 'string') 35 | t.not(typeof revocRegEntry, 'string') 36 | 37 | // Prover create Master Secret 38 | var masterSecretName = 'master_secret' 39 | await indy.proverCreateMasterSecret(wh, masterSecretName) 40 | 41 | // Issuer create credential Offer 42 | var credOffer = await indy.issuerCreateCredentialOffer(wh, credDefId) 43 | 44 | // Prover create credential Request 45 | var [credReq, credReqMetadata] = await indy.proverCreateCredentialReq(wh, proverDid, credOffer, credDef, 'master_secret') 46 | t.not(typeof credReq, 'string') 47 | t.not(typeof credReqMetadata, 'string') 48 | 49 | // Issuer open Tails reader 50 | var blobReaderHandle = await indy.openBlobStorageReader('default', tailsWriterConfig) 51 | 52 | // Issuer create credential for credential Request 53 | // note that encoding is not standardized by Indy except that 32-bit integers are encoded as themselves. IS-786 54 | var [cred, revId, revDelta] = await indy.issuerCreateCredential(wh, credOffer, credReq, { 55 | name: { 'raw': 'Alex', 'encoded': '1139481716457488690172217916278103335' }, 56 | height: { 'raw': '175', 'encoded': '175' }, 57 | age: { 'raw': '28', 'encoded': '28' } 58 | }, revocRegId, blobReaderHandle) 59 | t.not(typeof cred, 'string') 60 | 61 | // Prover process and store credential 62 | var outCredId = await indy.proverStoreCredential(wh, 'cred_1_id', credReqMetadata, cred, credDef, revocRegDef) 63 | t.is(typeof outCredId, 'string') 64 | 65 | // Prover get Credential 66 | var credential = await indy.proverGetCredential(wh, outCredId) 67 | t.not(typeof credential, 'string') 68 | t.is(credential.schema_id, schemaId) 69 | t.is(credential.cred_def_id, credDefId) 70 | 71 | // Prover searches Credentials 72 | var [sh, totalCount] = await indy.proverSearchCredentials(wh, { schema_id: schemaId }) 73 | t.truthy(totalCount > 0) 74 | 75 | var credentials = await indy.proverFetchCredentials(sh, totalCount) 76 | t.truthy(Array.isArray(credentials)) 77 | t.truthy(credentials.length > 0) 78 | t.is(credentials[0].schema_id, schemaId) 79 | 80 | await indy.proverCloseCredentialsSearch(sh) 81 | 82 | var nonce = await indy.generateNonce() 83 | 84 | // Prover gets credentials for Proof Request 85 | var proofReq = { 86 | 'nonce': nonce, 87 | 'name': 'proof_req_1', 88 | 'version': '0.1', 89 | 'requested_attributes': { 90 | 'attr1_referent': { 'name': 'name' } 91 | }, 92 | 'requested_predicates': { 93 | 'predicate1_referent': { 'name': 'age', 'p_type': '>=', 'p_value': 18 } 94 | }, 95 | 'non_revoked': { 'from': 80, 'to': 100 } 96 | } 97 | var credentialsForProof = await indy.proverGetCredentialsForProofReq(wh, proofReq) 98 | 99 | credentials = await indy.proverGetCredentials(wh) 100 | t.truthy(Array.isArray(credentials)) 101 | t.truthy(credentials.length > 0) 102 | 103 | credentials = await indy.proverGetCredentials(wh, { schema_id: schemaId }) 104 | t.truthy(Array.isArray(credentials)) 105 | t.truthy(credentials.length > 0) 106 | t.is(credentials[0].schema_id, schemaId) 107 | 108 | // Prover searches Credentials for Proof Request 109 | sh = await indy.proverSearchCredentialsForProofReq(wh, proofReq, null) 110 | 111 | credentials = await indy.proverFetchCredentialsForProofReq(sh, 'attr1_referent', 100) 112 | t.truthy(Array.isArray(credentials)) 113 | t.truthy(credentials.length > 0) 114 | t.is(credentials[0]['cred_info'].schema_id, schemaId) 115 | 116 | credentials = await indy.proverFetchCredentialsForProofReq(sh, 'predicate1_referent', 100) 117 | t.truthy(Array.isArray(credentials)) 118 | t.truthy(credentials.length > 0) 119 | t.is(credentials[0]['cred_info'].schema_id, schemaId) 120 | 121 | await indy.proverCloseCredentialsSearchForProofReq(sh) 122 | 123 | // Prover gets credentials for Proof Request 124 | var timestamp = 100 125 | var revState = await indy.createRevocationState(blobReaderHandle, revocRegDef, revDelta, timestamp, revId) 126 | t.is(revState.timestamp, 100) 127 | 128 | timestamp = 101 129 | revState = await indy.updateRevocationState(blobReaderHandle, revState, revocRegDef, revDelta, timestamp, revId) 130 | t.is(revState.timestamp, 101) 131 | 132 | // Prover create Proof for Proof Request 133 | var referent = credentialsForProof['attrs']['attr1_referent'][0]['cred_info']['referent'] 134 | var requestedCredentials = { 135 | 'self_attested_attributes': {}, 136 | 'requested_attributes': { 'attr1_referent': { 'cred_id': referent, 'revealed': true, 'timestamp': timestamp } }, 137 | 'requested_predicates': { 'predicate1_referent': { 'cred_id': referent, 'timestamp': timestamp } } 138 | } 139 | 140 | var schemas = {} 141 | schemas[schemaId] = schema 142 | 143 | var credentialDefs = {} 144 | credentialDefs[credDefId] = credDef 145 | 146 | var revocStates = {} 147 | revocStates[revocRegId] = {} 148 | revocStates[revocRegId][timestamp] = revState 149 | 150 | var proof = await indy.proverCreateProof(wh, proofReq, requestedCredentials, masterSecretName, schemas, credentialDefs, revocStates) 151 | 152 | // Verify the proof 153 | t.is(proof['requested_proof']['revealed_attrs']['attr1_referent']['raw'], 'Alex') 154 | 155 | var revocRefDefs = {} 156 | revocRefDefs[revocRegId] = revocRegDef 157 | 158 | var revocRegs = {} 159 | revocRegs[revocRegId] = {} 160 | revocRegs[revocRegId][timestamp] = revDelta 161 | 162 | var isValid = await indy.verifierVerifyProof(proofReq, proof, schemas, credentialDefs, revocRefDefs, revocRegs) 163 | t.is(isValid, true) 164 | 165 | // Revoke the credential 166 | var revocedDelta = await indy.issuerRevokeCredential(wh, blobReaderHandle, revocRegId, revId) 167 | 168 | await indy.issuerMergeRevocationRegistryDeltas(revDelta, revocedDelta) 169 | 170 | // Rotate credential definition 171 | var tempCredDef = await indy.issuerRotateCredentialDefStart(wh, credDefId, null) 172 | t.not(cred, tempCredDef) 173 | 174 | await indy.issuerRotateCredentialDefApply(wh, credDefId) 175 | 176 | await indy.closeWallet(wh) 177 | await indy.deleteWallet(walletConfig, walletCredentials) 178 | pool.cleanup() 179 | }) 180 | -------------------------------------------------------------------------------- /test/blob.js: -------------------------------------------------------------------------------- 1 | var test = require('ava') 2 | var indy = require('../') 3 | var tempy = require('tempy') 4 | 5 | test('blob_storage', async function (t) { 6 | var config = { 7 | 'base_dir': tempy.directory(), 8 | 'uri_pattern': '' 9 | } 10 | 11 | var wh = await indy.openBlobStorageWriter('default', config) 12 | t.is(typeof wh, 'number') 13 | t.truthy(wh >= 0) 14 | 15 | var rh = await indy.openBlobStorageReader('default', config) 16 | t.is(typeof rh, 'number') 17 | t.truthy(rh >= 0) 18 | 19 | var error = await t.throwsAsync(indy.openBlobStorageWriter('foo', config)) 20 | t.is(error.indyName, 'CommonInvalidStructure') 21 | 22 | error = await t.throwsAsync(indy.openBlobStorageWriter('default', null)) 23 | t.is(error.indyName, 'CommonInvalidParam3') 24 | 25 | error = await t.throwsAsync(indy.openBlobStorageReader('foo', config)) 26 | t.is(error.indyName, 'CommonInvalidStructure') 27 | }) 28 | -------------------------------------------------------------------------------- /test/cache.js: -------------------------------------------------------------------------------- 1 | var test = require('ava') 2 | var indy = require('../') 3 | var cuid = require('cuid') 4 | var initTestPool = require('./helpers/initTestPool') 5 | 6 | function sleep (ms) { 7 | return new Promise(function (resolve) { 8 | setTimeout(resolve, ms) 9 | }) 10 | } 11 | 12 | test('cache', async function (t) { 13 | var pool = await initTestPool() 14 | var walletConfig = { 'id': 'wallet-' + cuid() } 15 | var walletCredentials = { 'key': 'key' } 16 | await indy.createWallet(walletConfig, walletCredentials) 17 | var wh = await indy.openWallet(walletConfig, walletCredentials) 18 | var [trusteeDid] = await indy.createAndStoreMyDid(wh, { seed: '000000000000000000000000Trustee1' }) 19 | var [myDid, myVerkey] = await indy.createAndStoreMyDid(wh, { }) 20 | var schemaName = 'schema-' + cuid() 21 | var [schemaId, schema] = await indy.issuerCreateSchema(myDid, schemaName, '1.0', ['name', 'age']) 22 | 23 | // Nym 24 | var nreq = await indy.buildNymRequest(trusteeDid, myDid, myVerkey, null, 'TRUSTEE') 25 | var nres = await indy.signAndSubmitRequest(pool.handle, wh, trusteeDid, nreq) 26 | t.is(nres.result.txn.data.verkey, myVerkey) 27 | 28 | var defaultGetCacheOptions = { 29 | 'noCache': false, 30 | 'noUpdate': false, 31 | 'noStore': false, 32 | 'minFresh': -1 33 | } 34 | 35 | var defaultPurgeCacheOptions = { 36 | 'maxAge': -1 37 | } 38 | 39 | // Schema 40 | var req = await indy.buildSchemaRequest(myDid, schema) 41 | req = await indy.signRequest(wh, myDid, req) 42 | await indy.submitRequest(pool.handle, req) 43 | 44 | await sleep(5 * 1000) 45 | 46 | var schemaRes = await indy.getSchema(pool.handle, wh, myDid, schemaId, defaultGetCacheOptions) 47 | t.is(schemaRes.name, schema.name) 48 | schema = schemaRes 49 | 50 | await indy.purgeSchemaCache(wh, defaultPurgeCacheOptions) 51 | 52 | // Cred Def 53 | var [credDefId, credDef] = await indy.issuerCreateAndStoreCredentialDef(wh, myDid, schema, 'TAG', 'CL', { support_revocation: false }) 54 | req = await indy.buildCredDefRequest(myDid, credDef) 55 | await indy.signAndSubmitRequest(pool.handle, wh, myDid, req) 56 | 57 | await sleep(5 * 1000) 58 | 59 | var credDefRes = await indy.getCredDef(pool.handle, wh, myDid, credDefId, defaultGetCacheOptions) 60 | t.is(credDefRes.id, credDef.id) 61 | 62 | await indy.purgeCredDefCache(wh, defaultPurgeCacheOptions) 63 | 64 | // cleanup 65 | await indy.closeWallet(wh) 66 | await indy.deleteWallet(walletConfig, walletCredentials) 67 | pool.cleanup() 68 | }) 69 | -------------------------------------------------------------------------------- /test/crypto.js: -------------------------------------------------------------------------------- 1 | var test = require('ava') 2 | var indy = require('../') 3 | var cuid = require('cuid') 4 | var initTestPool = require('./helpers/initTestPool') 5 | 6 | test('crypto', async function (t) { 7 | var pool = await initTestPool() 8 | var walletConfig = { 'id': 'wallet-' + cuid() } 9 | var walletCredentials = { 'key': 'key' } 10 | await indy.createWallet(walletConfig, walletCredentials) 11 | var wh = await indy.openWallet(walletConfig, walletCredentials) 12 | 13 | // Create Key 14 | var error = await t.throwsAsync(indy.createKey(-1, {})) 15 | t.is(error.indyName, 'WalletInvalidHandle') 16 | 17 | var verkey = await indy.createKey(wh, {}) 18 | t.is(typeof verkey, 'string') 19 | 20 | var seed1 = '00000000000000000000000000000My1' 21 | verkey = await indy.createKey(wh, { 'seed': seed1 }) 22 | t.is(typeof verkey, 'string') 23 | 24 | // Sign + Verify 25 | var message = Buffer.from('{"reqId":1496822211362017764}', 'utf8') 26 | var signature = await indy.cryptoSign(wh, verkey, message) 27 | t.true(Buffer.isBuffer(signature)) 28 | t.is(signature.toString('base64'), 'qdcI4QdrbgnBosrWokLu0z/RDMQI0zcbeF7MkzVoZz08+e1/Zy7c3wpfSzX10vGXvykwHgkQTvydztKRfYVtCw==') 29 | t.true(await indy.cryptoVerify(verkey, message, signature)) 30 | t.false(await indy.cryptoVerify(verkey, Buffer.from('wat?', 'utf8'), signature)) 31 | 32 | // Metadata 33 | await indy.setKeyMetadata(wh, verkey, 'foobar') 34 | var metadata = await indy.getKeyMetadata(wh, verkey) 35 | t.is(metadata, 'foobar') 36 | 37 | // Auth 38 | var [, stewardVerkey] = await indy.createAndStoreMyDid(wh, { seed: '000000000000000000000000Steward1' }) 39 | var [, trusteeVerkey] = await indy.createAndStoreMyDid(wh, { seed: '000000000000000000000000Trustee1' }) 40 | 41 | var encrypted = await indy.cryptoAuthCrypt(wh, stewardVerkey, trusteeVerkey, message) 42 | t.true(Buffer.isBuffer(encrypted)) 43 | 44 | var decrypted = await indy.cryptoAuthDecrypt(wh, trusteeVerkey, encrypted) 45 | t.is(decrypted[0], stewardVerkey) 46 | t.true(Buffer.isBuffer(decrypted[1])) 47 | t.is(decrypted[1].toString('utf8'), message.toString('utf8')) 48 | 49 | // Anon 50 | encrypted = await indy.cryptoAnonCrypt(trusteeVerkey, message) 51 | t.true(Buffer.isBuffer(encrypted)) 52 | 53 | decrypted = await indy.cryptoAnonDecrypt(wh, trusteeVerkey, encrypted) 54 | t.true(Buffer.isBuffer(decrypted)) 55 | t.is(decrypted.toString('utf8'), message.toString('utf8')) 56 | 57 | // Pack Auth Crypt 58 | var [, senderVerkey] = await indy.createAndStoreMyDid(wh, {}) 59 | var receiverKeys = [trusteeVerkey, stewardVerkey] 60 | 61 | var packedMessage = await indy.packMessage(wh, message, receiverKeys, senderVerkey) 62 | t.true(Buffer.isBuffer(packedMessage)) 63 | 64 | var unpackedMessage = await indy.unpackMessage(wh, packedMessage) 65 | t.true(Buffer.isBuffer(unpackedMessage)) 66 | 67 | unpackedMessage = JSON.parse(unpackedMessage.toString('utf8')) 68 | t.is(unpackedMessage['message'], message.toString('utf8')) 69 | t.is(unpackedMessage['sender_verkey'], senderVerkey) 70 | t.is(unpackedMessage['recipient_verkey'], trusteeVerkey) 71 | 72 | // Pack Anon Crypt 73 | packedMessage = await indy.packMessage(wh, message, receiverKeys, null) 74 | t.true(Buffer.isBuffer(packedMessage)) 75 | 76 | unpackedMessage = await indy.unpackMessage(wh, packedMessage) 77 | t.true(Buffer.isBuffer(unpackedMessage)) 78 | 79 | unpackedMessage = JSON.parse(unpackedMessage.toString('utf8')) 80 | t.is(unpackedMessage['message'], message.toString('utf8')) 81 | t.is(unpackedMessage['sender_verkey'], undefined) 82 | t.is(unpackedMessage['recipient_verkey'], trusteeVerkey) 83 | 84 | await indy.closeWallet(wh) 85 | await indy.deleteWallet(walletConfig, walletCredentials) 86 | pool.cleanup() 87 | }) 88 | -------------------------------------------------------------------------------- /test/did.js: -------------------------------------------------------------------------------- 1 | var test = require('ava') 2 | var indy = require('../') 3 | var cuid = require('cuid') 4 | var initTestPool = require('./helpers/initTestPool') 5 | 6 | test('did', async function (t) { 7 | var pool = await initTestPool() 8 | var walletConfig = { 'id': 'wallet-' + cuid() } 9 | var walletCredentials = { 'key': 'key' } 10 | await indy.createWallet(walletConfig, walletCredentials) 11 | var wh = await indy.openWallet(walletConfig, walletCredentials) 12 | 13 | // List, create, and get 14 | t.deepEqual(await indy.listMyDidsWithMeta(wh), []) 15 | var [did, verkey] = await indy.createAndStoreMyDid(wh, { seed: '000000000000000000000000Steward1' }) 16 | t.deepEqual(await indy.listMyDidsWithMeta(wh), [ 17 | { did: did, metadata: null, verkey: verkey, tempVerkey: null } 18 | ]) 19 | t.is(await indy.keyForLocalDid(wh, did), verkey) 20 | t.is(await indy.keyForDid(pool.handle, wh, did), verkey) 21 | 22 | // Abbreviate 23 | var abbr = await indy.abbreviateVerkey(did, verkey) 24 | t.not(abbr, verkey) 25 | 26 | // Replace 27 | var verkey2 = await indy.replaceKeysStart(wh, did, {}) 28 | t.is(typeof verkey2, 'string') 29 | t.not(verkey2, verkey) 30 | t.is(await indy.keyForLocalDid(wh, did), verkey, 'the verkey should not be replaced yet') 31 | await indy.replaceKeysApply(wh, did) 32 | t.is(await indy.keyForLocalDid(wh, did), verkey2, 'the verkey should be changed now') 33 | verkey = verkey2 34 | 35 | // Store 36 | await indy.storeTheirDid(wh, { did: 'VsKV7grR1BUE29mG2Fm2kX', verkey: 'GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa' }) 37 | 38 | // Endpoint 39 | var endpoint = '127.0.0.1:9700' 40 | await indy.setEndpointForDid(wh, did, endpoint, verkey) 41 | var data = await indy.getEndpointForDid(wh, -1, did) 42 | t.is(data[0], endpoint) 43 | t.is(data[1], verkey) 44 | 45 | // Metadata 46 | var metadata = 'Hi!' 47 | await indy.setDidMetadata(wh, did, metadata) 48 | data = await indy.getDidMetadata(wh, did) 49 | t.is(data, metadata) 50 | data = await indy.getMyDidWithMeta(wh, did) 51 | t.deepEqual(data, { 52 | did: did, 53 | metadata: metadata, 54 | verkey: verkey, 55 | tempVerkey: null 56 | }) 57 | t.deepEqual(await indy.listMyDidsWithMeta(wh), [data]) 58 | 59 | await indy.closeWallet(wh) 60 | await indy.deleteWallet(walletConfig, walletCredentials) 61 | pool.cleanup() 62 | }) 63 | -------------------------------------------------------------------------------- /test/helpers/initTestPool.js: -------------------------------------------------------------------------------- 1 | var indy = require('../../') 2 | var makeTestPool = require('./makeTestPool') 3 | 4 | module.exports = async function () { 5 | await indy.setProtocolVersion(2) 6 | 7 | var pool = await makeTestPool() 8 | await indy.createPoolLedgerConfig(pool.name, { 9 | 'genesis_txn': pool.file 10 | }) 11 | var poolH = await indy.openPoolLedger(pool.name) 12 | 13 | return { 14 | name: pool.name, 15 | file: pool.file, 16 | handle: poolH, 17 | cleanup: async function () { 18 | await indy.closePoolLedger(poolH) 19 | await indy.deletePoolLedgerConfig(pool.name) 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/helpers/makeTestPool.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs') 2 | var path = require('path') 3 | var tempy = require('tempy') 4 | 5 | module.exports = function () { 6 | var poolIp = process.env.TEST_POOL_IP || '127.0.0.1' 7 | 8 | var genesisTxn = [ 9 | { 'reqSignature': {}, 'txn': { 'data': { 'data': { 'alias': 'Node1', 'blskey': '4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba', 'blskey_pop': 'RahHYiCvoNCtPTrVtP7nMC5eTYrsUA8WjXbdhNc8debh1agE9bGiJxWBXYNFbnJXoXhWFMvyqhqhRoq737YQemH5ik9oL7R4NTTCz2LEZhkgLJzB3QRQqJyBNyv7acbdHrAT8nQ9UkLbaVL9NBpnWXBTw4LEMePaSHEw66RzPNdAX1', 'client_ip': poolIp, 'client_port': 9702, 'node_ip': poolIp, 'node_port': 9701, 'services': ['VALIDATOR'] }, 'dest': 'Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv' }, 'metadata': { 'from': 'Th7MpTaRZVRYnPiabds81Y' }, 'type': '0' }, 'txnMetadata': { 'seqNo': 1, 'txnId': 'fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62' }, 'ver': '1' }, 10 | { 'reqSignature': {}, 'txn': { 'data': { 'data': { 'alias': 'Node2', 'blskey': '37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk', 'blskey_pop': 'Qr658mWZ2YC8JXGXwMDQTzuZCWF7NK9EwxphGmcBvCh6ybUuLxbG65nsX4JvD4SPNtkJ2w9ug1yLTj6fgmuDg41TgECXjLCij3RMsV8CwewBVgVN67wsA45DFWvqvLtu4rjNnE9JbdFTc1Z4WCPA3Xan44K1HoHAq9EVeaRYs8zoF5', 'client_ip': poolIp, 'client_port': 9704, 'node_ip': poolIp, 'node_port': 9703, 'services': ['VALIDATOR'] }, 'dest': '8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb' }, 'metadata': { 'from': 'EbP4aYNeTHL6q385GuVpRV' }, 'type': '0' }, 'txnMetadata': { 'seqNo': 2, 'txnId': '1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc' }, 'ver': '1' }, 11 | { 'reqSignature': {}, 'txn': { 'data': { 'data': { 'alias': 'Node3', 'blskey': '3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5', 'blskey_pop': 'QwDeb2CkNSx6r8QC8vGQK3GRv7Yndn84TGNijX8YXHPiagXajyfTjoR87rXUu4G4QLk2cF8NNyqWiYMus1623dELWwx57rLCFqGh7N4ZRbGDRP4fnVcaKg1BcUxQ866Ven4gw8y4N56S5HzxXNBZtLYmhGHvDtk6PFkFwCvxYrNYjh', 'client_ip': poolIp, 'client_port': 9706, 'node_ip': poolIp, 'node_port': 9705, 'services': ['VALIDATOR'] }, 'dest': 'DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya' }, 'metadata': { 'from': '4cU41vWW82ArfxJxHkzXPG' }, 'type': '0' }, 'txnMetadata': { 'seqNo': 3, 'txnId': '7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4' }, 'ver': '1' }, 12 | { 'reqSignature': {}, 'txn': { 'data': { 'data': { 'alias': 'Node4', 'blskey': '2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw', 'blskey_pop': 'RPLagxaR5xdimFzwmzYnz4ZhWtYQEj8iR5ZU53T2gitPCyCHQneUn2Huc4oeLd2B2HzkGnjAff4hWTJT6C7qHYB1Mv2wU5iHHGFWkhnTX9WsEAbunJCV2qcaXScKj4tTfvdDKfLiVuU2av6hbsMztirRze7LvYBkRHV3tGwyCptsrP', 'client_ip': poolIp, 'client_port': 9708, 'node_ip': poolIp, 'node_port': 9707, 'services': ['VALIDATOR'] }, 'dest': '4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA' }, 'metadata': { 'from': 'TWwCRQRZ2ZHMJFn9TzLp7W' }, 'type': '0' }, 'txnMetadata': { 'seqNo': 4, 'txnId': 'aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008' }, 'ver': '1' } 13 | ] 14 | 15 | var txnData = genesisTxn.map(function (line) { 16 | return JSON.stringify(line) 17 | }).join('\n') 18 | 19 | return new Promise(function (resolve, reject) { 20 | var file = tempy.file() 21 | 22 | fs.writeFile(file, txnData, 'utf8', function (err) { 23 | if (err) return reject(err) 24 | 25 | resolve({ 26 | name: 'pool' + path.basename(file), 27 | file: file 28 | }) 29 | }) 30 | }) 31 | } 32 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | var test = require('ava') 2 | var indy = require('../') 3 | 4 | var did = 'VsKV7grR1BUE29mG2Fm2kX' 5 | var verkey = 'GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa' 6 | var abbrVerkey = '~HYwqs2vrTc8Tn4uBV7NBTe' 7 | 8 | test.before('test getCurrentError before any errors', function (t) { 9 | t.is(indy.capi.getCurrentError(), null) 10 | }) 11 | 12 | test('wrapper essentials', async function (t) { 13 | t.is(await indy.abbreviateVerkey(did, verkey), abbrVerkey) 14 | 15 | var err = await t.throwsAsync(indy.abbreviateVerkey()) 16 | t.is(err.message, 'CommonInvalidParam3') 17 | t.is(err.indyCode, 102) 18 | t.is(err.indyName, 'CommonInvalidParam3') 19 | t.is(err.indyMessage, 'Error: Invalid parameter 3\n Caused by: Invalid pointer has been passed\n') 20 | t.is(err.indyBacktrace, '') 21 | t.is(typeof err.indyCurrentErrorJson, 'string') 22 | t.is(err.indyCurrentErrorJson[0], '{') 23 | 24 | err = t.throws(function () { 25 | indy.abbreviateVerkey(1, verkey) 26 | }, Error) 27 | t.is(err.message, 'abbreviateVerkey expects String or null for did') 28 | 29 | err = t.throws(function () { 30 | indy.abbreviateVerkey(did, [1, 2, 3]) 31 | }, Error) 32 | t.is(err.message, 'abbreviateVerkey expects String or null for fullVerkey') 33 | 34 | err = await t.throwsAsync(indy.abbreviateVerkey(null, verkey)) 35 | t.is(err.indyName, 'CommonInvalidParam3') 36 | err = await t.throwsAsync(indy.abbreviateVerkey(void 0, verkey)) 37 | t.is(err.indyName, 'CommonInvalidParam3') 38 | 39 | err = await t.throwsAsync(indy.abbreviateVerkey(did, null)) 40 | t.is(err.indyName, 'CommonInvalidParam4') 41 | 42 | err = await t.throwsAsync(indy.abbreviateVerkey('?', verkey)) 43 | t.is(err + '', 'IndyError: CommonInvalidStructure') 44 | t.is(err.indyCode, 113) 45 | t.is(err.indyName, 'CommonInvalidStructure') 46 | }) 47 | 48 | test.cb('wrapper capi', function (t) { 49 | indy.capi.abbreviateVerkey(did, verkey, function (err, data) { 50 | t.falsy(err) 51 | t.is(data, abbrVerkey) 52 | 53 | indy.capi.abbreviateVerkey('?', verkey, function (err) { 54 | t.is(err, 113) 55 | 56 | try { 57 | indy.capi.abbreviateVerkey(t.fail) 58 | t.fail('should fail b/c not enough arguments were given') 59 | } catch (err) { 60 | t.is(err + '', 'Error: abbreviateVerkey expects 3 arguments') 61 | } 62 | try { 63 | indy.capi.abbreviateVerkey('a', 'b', t.fail, 'c') 64 | t.fail('should fail b/c too many arguments were given') 65 | } catch (err) { 66 | t.is(err + '', 'Error: abbreviateVerkey expects 3 arguments') 67 | } 68 | t.end() 69 | }) 70 | }) 71 | }) 72 | 73 | test.cb('wrapper callbacks', function (t) { 74 | indy.abbreviateVerkey(did, verkey, function (err, data) { 75 | t.falsy(err) 76 | t.is(data, abbrVerkey) 77 | 78 | indy.abbreviateVerkey('?', verkey, function (err) { 79 | t.is(err + '', 'IndyError: CommonInvalidStructure') 80 | t.is(err.indyCode, 113) 81 | t.is(err.indyName, 'CommonInvalidStructure') 82 | t.end() 83 | }) 84 | }) 85 | }) 86 | -------------------------------------------------------------------------------- /test/ledger.js: -------------------------------------------------------------------------------- 1 | var test = require('ava') 2 | var indy = require('../') 3 | var cuid = require('cuid') 4 | var initTestPool = require('./helpers/initTestPool') 5 | var tempy = require('tempy') 6 | 7 | function sleep (ms) { 8 | return new Promise(function (resolve) { 9 | setTimeout(resolve, ms) 10 | }) 11 | } 12 | 13 | async function waitUntilApplied (ph, req, cond) { 14 | for (let i = 0; i < 3; i++) { 15 | let res = await indy.submitRequest(ph, req) 16 | 17 | if (cond(res)) { 18 | return res 19 | } 20 | 21 | await sleep(5 * 1000) 22 | } 23 | } 24 | 25 | test('ledger', async function (t) { 26 | var pool = await initTestPool() 27 | var walletConfig = { 'id': 'wallet-' + cuid() } 28 | var walletCredentials = { 'key': 'key' } 29 | await indy.createWallet(walletConfig, walletCredentials) 30 | var wh = await indy.openWallet(walletConfig, walletCredentials) 31 | var [trusteeDid] = await indy.createAndStoreMyDid(wh, { seed: '000000000000000000000000Trustee1' }) 32 | var [myDid, myVerkey] = await indy.createAndStoreMyDid(wh, { }) 33 | var schemaName = 'schema-' + cuid() 34 | var [schemaId, schema] = await indy.issuerCreateSchema(myDid, schemaName, '1.0', ['name', 'age']) 35 | 36 | // Nym 37 | var req = await indy.buildNymRequest(trusteeDid, myDid, myVerkey, null, 'TRUSTEE') 38 | var res = await indy.signAndSubmitRequest(pool.handle, wh, trusteeDid, req) 39 | t.is(res.result.txn.data.verkey, myVerkey) 40 | 41 | var resMetadata = await indy.getResponseMetadata(res) 42 | t.true(resMetadata.hasOwnProperty('seqNo')) 43 | t.true(resMetadata.hasOwnProperty('txnTime')) 44 | t.false(resMetadata.hasOwnProperty('lastTxnTime')) 45 | t.false(resMetadata.hasOwnProperty('lastSeqNo')) 46 | 47 | req = await indy.buildGetNymRequest(trusteeDid, myDid) 48 | t.is(req.identifier, trusteeDid) 49 | t.is(req.operation.dest, myDid) 50 | 51 | // Schema 52 | req = await indy.buildSchemaRequest(myDid, schema) 53 | req = await indy.signRequest(wh, myDid, req) 54 | res = await indy.submitRequest(pool.handle, req) 55 | 56 | req = await indy.buildGetSchemaRequest(myDid, schemaId) 57 | res = await waitUntilApplied(pool.handle, req, res => res['result']['seqNo'] != null) 58 | var data = await indy.parseGetSchemaResponse(res) 59 | t.is(data[0], schemaId) 60 | t.is(data[1].name, schema.name) 61 | req = await indy.buildGetTxnRequest(myDid, null, data[1].seqNo) 62 | res = await waitUntilApplied(pool.handle, req, res => res['result']['data']['txnMetadata']['seqNo'] != null) 63 | t.is(res.result.data.txn.data.data.name, schema.name) 64 | schema = data[1] 65 | 66 | // Node 67 | req = await indy.buildNodeRequest(myDid, myDid, { 68 | node_ip: '10.0.0.100', 69 | node_port: 9710, 70 | client_ip: '10.0.0.100', 71 | client_port: 9709, 72 | alias: 'Node5', 73 | services: ['VALIDATOR'], 74 | blskey: 'CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW' 75 | }) 76 | res = await indy.submitRequest(pool.handle, req) 77 | t.is(res.op, 'REQNACK') 78 | 79 | // Attrib 80 | req = await indy.buildAttribRequest(myDid, myDid, null, { endpoint: { ha: '127.0.0.1:5555' } }, null) 81 | res = await indy.signAndSubmitRequest(pool.handle, wh, myDid, req) 82 | 83 | req = await indy.buildGetAttribRequest(myDid, myDid, 'endpoint', null, null) 84 | res = await waitUntilApplied(pool.handle, req, data => data['result']['data'] != null) 85 | t.deepEqual(JSON.parse(res.result.data), { endpoint: { ha: '127.0.0.1:5555' } }) 86 | 87 | // Pool 88 | req = await indy.buildPoolConfigRequest(myDid, false, false) 89 | t.false(req.operation.writes) 90 | 91 | req = await indy.buildPoolRestartRequest(myDid, 'start', '0') 92 | t.is(req.operation.action, 'start') 93 | 94 | req = await indy.buildPoolUpgradeRequest(myDid, 'some upgrade action', '2.0.0', 'cancel', 'abc12345', -1, null, null, false, false, null) 95 | t.is(req.operation.name, 'some upgrade action') 96 | 97 | // DDO 98 | req = await indy.buildGetDdoRequest(myDid, trusteeDid) 99 | t.is(req.operation.dest, trusteeDid) 100 | 101 | // Cred Def 102 | var [credDefId, credDef] = await indy.issuerCreateAndStoreCredentialDef(wh, myDid, schema, 'TAG', 'CL', { support_revocation: true }) 103 | req = await indy.buildCredDefRequest(myDid, credDef) 104 | res = await indy.signAndSubmitRequest(pool.handle, wh, myDid, req) 105 | 106 | req = await indy.buildGetCredDefRequest(myDid, credDefId) 107 | res = await waitUntilApplied(pool.handle, req, res => res['result']['seqNo'] != null) 108 | res = await indy.parseGetCredDefResponse(res) 109 | t.is(res[0], credDefId) 110 | t.is(res[1].id, credDef.id) 111 | 112 | // Revoc Reg Def 113 | var writerH = await indy.openBlobStorageWriter('default', { 114 | 'base_dir': tempy.directory(), 115 | 'uri_pattern': '' 116 | }) 117 | var [revRegDefId, revRegDef, revRegEntry] = await indy.issuerCreateAndStoreRevocReg(wh, myDid, null, 'tag1', credDefId, { max_cred_num: 5 }, writerH) 118 | 119 | req = await indy.buildRevocRegDefRequest(myDid, revRegDef) 120 | res = await indy.signAndSubmitRequest(pool.handle, wh, myDid, req) 121 | t.is(res.result.txn.data.id, revRegDefId) 122 | 123 | req = await indy.buildGetRevocRegDefRequest(myDid, revRegDefId) 124 | res = await waitUntilApplied(pool.handle, req, res => res['result']['seqNo'] != null) 125 | res = await indy.parseGetRevocRegDefResponse(res) 126 | t.is(res[0], revRegDefId) 127 | t.is(res[1].id, revRegDef.id) 128 | 129 | // Revoc Reg Entry 130 | req = await indy.buildRevocRegEntryRequest(myDid, revRegDefId, 'CL_ACCUM', revRegEntry) 131 | res = await indy.signAndSubmitRequest(pool.handle, wh, myDid, req) 132 | 133 | var nowSeconds = Math.floor(Date.now() / 1000) 134 | req = await indy.buildGetRevocRegRequest(myDid, revRegDefId, nowSeconds + 100) 135 | res = await waitUntilApplied(pool.handle, req, res => res['result']['seqNo'] != null) 136 | res = await indy.parseGetRevocRegResponse(res) 137 | t.is(res[0], revRegDefId) 138 | t.is(typeof res[1], 'object') 139 | t.is(typeof res[2], 'number') 140 | 141 | // RevocRegDelta 142 | req = await indy.buildGetRevocRegDeltaRequest(myDid, revRegDefId, nowSeconds, nowSeconds + 100) 143 | res = await waitUntilApplied(pool.handle, req, res => res['result']['seqNo'] != null) 144 | res = await indy.parseGetRevocRegDeltaResponse(res) 145 | t.is(res[0], revRegDefId) 146 | t.is(typeof res[1], 'object') 147 | t.is(typeof res[2], 'number') 148 | 149 | // Submit Action 150 | req = await indy.buildGetValidatorInfoRequest(myDid) 151 | req = await indy.signRequest(wh, myDid, req) 152 | res = await indy.submitAction(pool.handle, req, null, null) 153 | 154 | // Auth Rule 155 | req = await indy.buildGetAuthRuleRequest(trusteeDid, 'NYM', 'ADD', 'role', null, '101') 156 | res = await indy.submitRequest(pool.handle, req) 157 | var defaultConstraint = res['result']['data'][0]['constraint'] 158 | 159 | var constraint = { 160 | 'sig_count': 1, 161 | 'metadata': {}, 162 | 'role': '0', 163 | 'constraint_id': 'ROLE', 164 | 'need_to_be_owner': false, 165 | 'off_ledger_signature': false 166 | } 167 | req = await indy.buildAuthRuleRequest(trusteeDid, 'NYM', 'ADD', 'role', null, '101', constraint) 168 | res = await indy.signAndSubmitRequest(pool.handle, wh, trusteeDid, req) 169 | t.is(res.op, 'REPLY') 170 | 171 | await sleep(1000) 172 | 173 | req = await indy.buildGetAuthRuleRequest(trusteeDid, 'NYM', 'ADD', 'role', null, '101') 174 | res = await indy.submitRequest(pool.handle, req) 175 | t.deepEqual(res['result']['data'][0]['constraint'], constraint) 176 | 177 | var expectedAuthRule = { 178 | 'auth_type': '1', 179 | 'auth_action': 'ADD', 180 | 'field': 'role', 181 | 'new_value': '101', 182 | 'constraint': constraint 183 | } 184 | 185 | var authRulesData = [expectedAuthRule] 186 | req = await indy.buildAuthRulesRequest(trusteeDid, authRulesData) 187 | res = await indy.signAndSubmitRequest(pool.handle, wh, trusteeDid, req) 188 | t.is(res.op, 'REPLY') 189 | 190 | // author agreement 191 | req = await indy.buildTxnAuthorAgreementRequest(trusteeDid, 'indy agreement', '1.0.0') 192 | t.deepEqual(req['operation'], { 'type': '4', 'text': 'indy agreement', 'version': '1.0.0' }) 193 | 194 | req = await indy.buildGetTxnAuthorAgreementRequest(null, { 'version': '1.0.0' }) 195 | t.deepEqual(req['operation'], { 'type': '6', 'version': '1.0.0' }) 196 | 197 | // acceptance mechanism 198 | var aml = { 'acceptance mechanism label 1': 'some acceptance mechanism description 1' } 199 | req = await indy.buildAcceptanceMechanismsRequest(trusteeDid, aml, '1.0.0', null) 200 | t.deepEqual(req['operation'], { 'type': '5', 'aml': aml, 'version': '1.0.0' }) 201 | 202 | req = await indy.buildGetAcceptanceMechanismsRequest(null, 123379200, null) 203 | t.deepEqual(req['operation'], { 'type': '7', 'timestamp': 123379200 }) 204 | 205 | // author agreement acceptance data 206 | req = await indy.appendTxnAuthorAgreementAcceptanceToRequest(req, 'indy agreement', '1.0.0', null, 'acceptance mechanism label 1', 123379200) 207 | var expectedMeta = { 208 | 'mechanism': 'acceptance mechanism label 1', 209 | 'taaDigest': '7213b9aabf8677edf6b17d20a9fbfaddb059ea4cb122d163bdf658ea67196120', 210 | 'time': 123379200 211 | } 212 | t.deepEqual(req['taaAcceptance'], expectedMeta) 213 | 214 | // set back 215 | req = await indy.buildAuthRuleRequest(trusteeDid, 'NYM', 'ADD', 'role', null, '101', defaultConstraint) 216 | res = await indy.signAndSubmitRequest(pool.handle, wh, trusteeDid, req) 217 | t.is(res.op, 'REPLY') 218 | 219 | // endorser 220 | req = await indy.buildSchemaRequest(myDid, schema) 221 | req = await indy.appendRequestEndorser(req, trusteeDid) 222 | t.is(req['endorser'], trusteeDid) 223 | 224 | await indy.closeWallet(wh) 225 | await indy.deleteWallet(walletConfig, walletCredentials) 226 | pool.cleanup() 227 | }) 228 | -------------------------------------------------------------------------------- /test/logger.js: -------------------------------------------------------------------------------- 1 | // NOTE: there are 2 test files for logger so ava can run them in separate nodejs processes 2 | // why? setLogger and setDefaultLogger cannot be both called in the same process 3 | var test = require('ava') 4 | var indy = require('../') 5 | var IndyError = require('../src/IndyError') 6 | 7 | test('setDefaultLogger', function (t) { 8 | t.notThrows(function () { 9 | indy.setDefaultLogger('trace') 10 | }) 11 | 12 | var err = t.throws(function () { 13 | indy.setDefaultLogger('foo') 14 | }, IndyError) 15 | t.is(err.indyName, 'CommonInvalidState') 16 | }) 17 | -------------------------------------------------------------------------------- /test/logger2.js: -------------------------------------------------------------------------------- 1 | // NOTE: there are 2 test files for logger so ava can run them in separate nodejs processes 2 | // why? setLogger and setDefaultLogger cannot be both called in the same process 3 | var test = require('ava') 4 | var indy = require('../') 5 | var IndyError = require('../src/IndyError') 6 | 7 | test('setLogger', async function (t) { 8 | var nEntries = 0 9 | function logFn (level, target, message, modulePath, file, line) { 10 | nEntries++ 11 | t.is(typeof level, 'number') 12 | t.is(typeof target, 'string') 13 | t.is(typeof message, 'string') 14 | t.is(typeof modulePath, 'string') 15 | t.is(typeof file, 'string') 16 | t.is(typeof line, 'number') 17 | } 18 | t.notThrows(function () { 19 | indy.setLogger(logFn) 20 | }) 21 | 22 | t.is(nEntries, 0) 23 | await indy.abbreviateVerkey('VsKV7grR1BUE29mG2Fm2kX', 'GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa') 24 | t.true(nEntries > 0) 25 | 26 | var err = t.throws(function () { 27 | indy.setLogger(function () {}) 28 | }, IndyError) 29 | t.is(err.indyName, 'CommonInvalidState') 30 | }) 31 | -------------------------------------------------------------------------------- /test/mod.js: -------------------------------------------------------------------------------- 1 | var test = require('ava') 2 | var indy = require('../') 3 | 4 | test('setRuntimeConfig', async function (t) { 5 | t.notThrows(function () { 6 | indy.setRuntimeConfig({ crypto_thread_pool_size: 4 }) 7 | }) 8 | t.throws(function () { 9 | indy.setRuntimeConfig({ crypto_thread_pool_size: 'bad-value' }) 10 | }) 11 | t.notThrows(function () { 12 | indy.setRuntimeConfig({ crypto_thread_pool_size: 1 }) 13 | }) 14 | }) 15 | -------------------------------------------------------------------------------- /test/pairwise.js: -------------------------------------------------------------------------------- 1 | var test = require('ava') 2 | var indy = require('../') 3 | var cuid = require('cuid') 4 | var initTestPool = require('./helpers/initTestPool') 5 | 6 | test('pairwise', async function (t) { 7 | var pool = await initTestPool() 8 | var walletConfig = { 'id': 'wallet-' + cuid() } 9 | var walletCredentials = { 'key': 'key' } 10 | await indy.createWallet(walletConfig, walletCredentials) 11 | var wh = await indy.openWallet(walletConfig, walletCredentials) 12 | 13 | var [theirDid, theirVerkey] = await indy.createAndStoreMyDid(wh, {}) 14 | var [myDid] = await indy.createAndStoreMyDid(wh, {}) 15 | await indy.storeTheirDid(wh, { did: theirDid, verkey: theirVerkey }) 16 | 17 | t.deepEqual(await indy.listPairwise(wh), []) 18 | 19 | t.false(await indy.isPairwiseExists(wh, theirDid)) 20 | 21 | await indy.createPairwise(wh, theirDid, myDid, 'wat') 22 | 23 | t.true(await indy.isPairwiseExists(wh, theirDid)) 24 | 25 | t.deepEqual(await indy.listPairwise(wh), [ 26 | { my_did: myDid, their_did: theirDid, metadata: 'wat' } 27 | ]) 28 | 29 | t.deepEqual(await indy.getPairwise(wh, theirDid), { 30 | my_did: myDid, 31 | metadata: 'wat' 32 | }) 33 | 34 | await indy.setPairwiseMetadata(wh, theirDid, 'hello new metadata') 35 | 36 | t.deepEqual(await indy.getPairwise(wh, theirDid), { 37 | my_did: myDid, 38 | metadata: 'hello new metadata' 39 | }) 40 | 41 | await indy.closeWallet(wh) 42 | await indy.deleteWallet(walletConfig, walletCredentials) 43 | pool.cleanup() 44 | }) 45 | -------------------------------------------------------------------------------- /test/payments.js: -------------------------------------------------------------------------------- 1 | var test = require('ava') 2 | var indy = require('../') 3 | var cuid = require('cuid') 4 | var initTestPool = require('./helpers/initTestPool') 5 | 6 | test('payments', async function (t) { 7 | var pool = await initTestPool() 8 | 9 | var walletConfig = { 'id': 'wallet-' + cuid() } 10 | var walletCredentials = { 'key': 'key' } 11 | await indy.createWallet(walletConfig, walletCredentials) 12 | 13 | var wh = await indy.openWallet(walletConfig, walletCredentials) 14 | 15 | var [trusteeDid] = await indy.createAndStoreMyDid(wh, { seed: '000000000000000000000000Trustee1' }) 16 | 17 | var paymentMethod = 'null' 18 | var paymentAddress = 'pay:null:test' 19 | var inputs = ['pay:null:1'] 20 | var outputs = [{ 'recipient': 'pay:null:1', 'amount': 1 }] 21 | var from = 1 22 | 23 | var err = await t.throwsAsync(indy.createPaymentAddress(wh, paymentMethod, {})) 24 | t.is(err.indyName, 'PaymentUnknownMethodError') 25 | 26 | t.deepEqual(await indy.listPaymentAddresses(wh), []) 27 | 28 | err = await t.throwsAsync(indy.addRequestFees(wh, trusteeDid, {}, inputs, outputs, null)) 29 | t.is(err.indyName, 'PaymentUnknownMethodError') 30 | 31 | err = await t.throwsAsync(indy.parseResponseWithFees(paymentMethod, {})) 32 | t.is(err.indyName, 'PaymentUnknownMethodError') 33 | 34 | err = await t.throwsAsync(indy.buildGetPaymentSourcesRequest(wh, trusteeDid, paymentAddress)) 35 | t.is(err.indyName, 'PaymentUnknownMethodError') 36 | 37 | err = await t.throwsAsync(indy.buildGetPaymentSourcesWithFromRequest(wh, trusteeDid, paymentAddress, from)) 38 | t.is(err.indyName, 'PaymentUnknownMethodError') 39 | 40 | err = await t.throwsAsync(indy.parseGetPaymentSourcesWithFromResponse(paymentMethod, {})) 41 | t.is(err.indyName, 'PaymentUnknownMethodError') 42 | 43 | err = await t.throwsAsync(indy.buildPaymentReq(wh, trusteeDid, inputs, outputs, null)) 44 | t.is(err.indyName, 'PaymentUnknownMethodError') 45 | 46 | err = await t.throwsAsync(indy.parsePaymentResponse(paymentMethod, {})) 47 | t.is(err.indyName, 'PaymentUnknownMethodError') 48 | 49 | var extra = await indy.preparePaymentExtraWithAcceptanceData(null, 'indy agreement', '1.0.0', null, 'acceptance mechanism label 1', 123379200) 50 | var expectedExtra = { 51 | 'mechanism': 'acceptance mechanism label 1', 52 | 'taaDigest': '7213b9aabf8677edf6b17d20a9fbfaddb059ea4cb122d163bdf658ea67196120', 53 | 'time': 123379200 54 | } 55 | t.deepEqual(extra['taaAcceptance'], expectedExtra) 56 | 57 | err = await t.throwsAsync(indy.buildMintReq(wh, trusteeDid, outputs, null)) 58 | 59 | t.is(err.indyName, 'PaymentUnknownMethodError') 60 | 61 | var fees = { 'txnType1': 1, 'txnType2': 2 } 62 | 63 | err = await t.throwsAsync(indy.buildSetTxnFeesReq(wh, trusteeDid, paymentMethod, fees)) 64 | t.is(err.indyName, 'PaymentUnknownMethodError') 65 | 66 | err = await t.throwsAsync(indy.buildGetTxnFeesReq(wh, trusteeDid, paymentMethod)) 67 | t.is(err.indyName, 'PaymentUnknownMethodError') 68 | 69 | err = await t.throwsAsync(indy.parseGetTxnFeesResponse(paymentMethod, {})) 70 | t.is(err.indyName, 'PaymentUnknownMethodError') 71 | 72 | var receipt = 'pay:null:0_PqVjwJC42sxCTJp' 73 | 74 | err = await t.throwsAsync(indy.buildVerifyPaymentReq(wh, trusteeDid, receipt)) 75 | t.is(err.indyName, 'PaymentUnknownMethodError') 76 | 77 | err = await t.throwsAsync(indy.parseVerifyPaymentResponse(paymentMethod, {})) 78 | t.is(err.indyName, 'PaymentUnknownMethodError') 79 | 80 | var message = Buffer.from('123456789', 'utf8') 81 | err = await t.throwsAsync(indy.signWithAddress(wh, paymentAddress, message)) 82 | t.is(err.indyName, 'PaymentUnknownMethodError') 83 | 84 | var signature = Buffer.from('987654321', 'utf8') 85 | err = await t.throwsAsync(indy.verifyWithAddress(paymentAddress, message, signature)) 86 | t.is(err.indyName, 'PaymentUnknownMethodError') 87 | 88 | var getAuthRuleResp = { 'result': { 'data': [ { 'new_value': '0', 'constraint': { 'need_to_be_owner': false, 'sig_count': 1, 'metadata': { 'fees': '1' }, 'role': '0', 'constraint_id': 'ROLE' }, 'field': 'role', 'auth_type': '1', 'auth_action': 'ADD' } ], 'identifier': 'LibindyDid111111111111', 'auth_action': 'ADD', 'new_value': '0', 'reqId': 15616, 'auth_type': '1', 'type': '121', 'field': 'role' }, 'op': 'REPLY' } 89 | var requesterInfo = { 'role': '0', 'need_to_be_owner': false, 'sig_count': 1 } 90 | fees = { '1': 100 } 91 | 92 | var requestInfo = await indy.getRequestInfo(getAuthRuleResp, requesterInfo, fees) 93 | var expectedRequestInfo = { 94 | 'price': 100, 95 | 'requirements': [{ 96 | 'role': '0', 97 | 'need_to_be_owner': false, 98 | 'sig_count': 1 99 | }] 100 | } 101 | t.deepEqual(expectedRequestInfo, requestInfo) 102 | 103 | await indy.closeWallet(wh) 104 | await indy.deleteWallet(walletConfig, walletCredentials) 105 | 106 | pool.cleanup() 107 | }) 108 | -------------------------------------------------------------------------------- /test/pool.js: -------------------------------------------------------------------------------- 1 | var test = require('ava') 2 | var indy = require('../') 3 | var makeTestPool = require('./helpers/makeTestPool') 4 | 5 | test('pool', async function (t) { 6 | var err = await t.throwsAsync(indy.createPoolLedgerConfig('', '')) 7 | t.is(err.indyName, 'CommonInvalidParam2') 8 | 9 | err = await t.throwsAsync(indy.createPoolLedgerConfig('not_a_real_pool', { 10 | 'genesis_txn': '/not/a/real/file.txn' 11 | })) 12 | t.is(err.indyName, 'CommonIOError') 13 | 14 | var pool = await makeTestPool() 15 | 16 | t.is((await indy.listPools()).map(p => p.pool).indexOf(pool.name), -1) 17 | 18 | t.is(await indy.createPoolLedgerConfig(pool.name, { 19 | 'genesis_txn': pool.file 20 | }), null) 21 | 22 | await indy.setProtocolVersion(1) 23 | 24 | err = await t.throwsAsync(indy.openPoolLedger(pool.name, null)) 25 | t.is(err.indyName, 'PoolIncompatibleProtocolVersion') 26 | 27 | await indy.setProtocolVersion(2) 28 | 29 | var poolH = await indy.openPoolLedger(pool.name, null) 30 | t.truthy(poolH >= 0) 31 | 32 | err = await t.throwsAsync(indy.refreshPoolLedger(-1)) 33 | t.is(err.indyName, 'PoolLedgerInvalidPoolHandle') 34 | await indy.refreshPoolLedger(poolH) 35 | 36 | t.truthy((await indy.listPools()).map(p => p.pool).indexOf(pool.name) >= 0) 37 | 38 | err = await t.throwsAsync(indy.deletePoolLedgerConfig(pool.name)) 39 | t.is(err.indyName, 'CommonInvalidState') 40 | 41 | await indy.closePoolLedger(poolH) 42 | 43 | await indy.deletePoolLedgerConfig(pool.name) 44 | }) 45 | -------------------------------------------------------------------------------- /test/wallet.js: -------------------------------------------------------------------------------- 1 | var test = require('ava') 2 | var indy = require('../') 3 | var cuid = require('cuid') 4 | var path = require('path') 5 | var fs = require('fs') 6 | var initTestPool = require('./helpers/initTestPool') 7 | var indyHomeDir = require('home-dir')('.indy_client') 8 | 9 | test('wallet', async function (t) { 10 | var pool = await initTestPool() 11 | 12 | var walletConfig = { 'id': 'wallet-' + cuid() } 13 | var walletCredentials = { 'key': 'key' } 14 | await indy.createWallet(walletConfig, walletCredentials) 15 | 16 | var err = await t.throwsAsync(indy.createWallet(walletConfig, walletCredentials)) 17 | t.is(err.indyName, 'WalletAlreadyExistsError') 18 | 19 | var handle = await indy.openWallet(walletConfig, walletCredentials) 20 | t.truthy(handle >= 0) 21 | 22 | // err = await t.throwsAsync(indy.openWallet(walletConfig, walletCredentials)) 23 | // t.is(err.indyName, 'WalletAlreadyOpenedError') 24 | 25 | err = await t.throwsAsync(indy.closeWallet(-1)) 26 | t.is(err.indyName, 'WalletInvalidHandle') 27 | 28 | var [did] = await indy.createAndStoreMyDid(handle, {}) 29 | var didBeforeExport = await indy.getMyDidWithMeta(handle, did) 30 | 31 | var exportPath = path.join(indyHomeDir, 'export_wallet-' + cuid()) 32 | var exportConfig = { 33 | 'key': 'export_key', 34 | 'path': exportPath 35 | } 36 | await indy.exportWallet(handle, exportConfig) 37 | 38 | t.is(fs.existsSync(exportPath), true) 39 | 40 | await indy.closeWallet(handle) 41 | 42 | await indy.deleteWallet(walletConfig, walletCredentials) 43 | 44 | await indy.importWallet(walletConfig, walletCredentials, exportConfig) 45 | 46 | handle = await indy.openWallet(walletConfig, walletCredentials) 47 | t.truthy(handle >= 0) 48 | 49 | var didAfterImport = await indy.getMyDidWithMeta(handle, did) 50 | 51 | t.deepEqual(didBeforeExport, didAfterImport) 52 | 53 | await indy.closeWallet(handle) 54 | await indy.deleteWallet(walletConfig, walletCredentials) 55 | 56 | var key = await indy.generateWalletKey({}) 57 | walletCredentials = { 'key': key, 'key_derivation_method': 'RAW' } 58 | await indy.createWallet(walletConfig, walletCredentials) 59 | await indy.deleteWallet(walletConfig, walletCredentials) 60 | 61 | pool.cleanup() 62 | }) 63 | --------------------------------------------------------------------------------