diff --git a/package-lock.json b/package-lock.json index 39d4ee841..c2ec79454 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@tbd54566975/dwn-sdk-js", - "version": "0.4.6", + "version": "0.4.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@tbd54566975/dwn-sdk-js", - "version": "0.4.6", + "version": "0.4.7", "license": "Apache-2.0", "dependencies": { "@ipld/dag-cbor": "9.0.3", @@ -49,7 +49,7 @@ "@types/randombytes": "2.0.0", "@types/readable-stream": "4.0.10", "@types/secp256k1": "4.0.3", - "@types/sinon": "10.0.11", + "@types/sinon": "^17.0.3", "@types/uuid": "^9.0.1", "@types/varint": "6.0.0", "@typescript-eslint/eslint-plugin": "^7.9.0", @@ -81,8 +81,7 @@ "playwright": "^1.44.0", "rimraf": "^3.0.2", "search-index": "3.4.0", - "sinon": "13.0.1", - "ts-sinon": "^2.0.2", + "sinon": "18.0.1", "typescript": "^5.1.6", "util": "0.12.4" }, @@ -587,38 +586,47 @@ } }, "node_modules/@sinonjs/commons": { - "version": "1.8.6", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.6.tgz", - "integrity": "sha512-Ky+XkAkqPZSm3NLBeUng77EBQl3cmeJhITaGHdYH8kjVB+aun3S4XBRti2zt17mtt0mIUDiNxYeoJm6drVvBJQ==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.1.tgz", + "integrity": "sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==", "dev": true, "dependencies": { "type-detect": "4.0.8" } }, "node_modules/@sinonjs/fake-timers": { - "version": "9.1.2", - "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-9.1.2.tgz", - "integrity": "sha512-BPS4ynJW/o92PUR4wgriz2Ud5gpST5vz6GQfMixEDK0Z8ZCUv2M7SkBLykH56T++Xs+8ln9zTGbOvNGIe02/jw==", + "version": "11.2.2", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-11.2.2.tgz", + "integrity": "sha512-G2piCSxQ7oWOxwGSAyFHfPIsyeJGXYtc6mFbnFA+kRXkiEnTl8c/8jul2S329iFBnDI9HGoeWWAZvuvOkZccgw==", "dev": true, "dependencies": { - "@sinonjs/commons": "^1.7.0" + "@sinonjs/commons": "^3.0.0" } }, "node_modules/@sinonjs/samsam": { - "version": "6.1.3", - "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-6.1.3.tgz", - "integrity": "sha512-nhOb2dWPeb1sd3IQXL/dVPnKHDOAFfvichtBf4xV00/rU1QbPCQqKMbvIheIjqwVjh7qIgf2AHTHi391yMOMpQ==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-8.0.0.tgz", + "integrity": "sha512-Bp8KUVlLp8ibJZrnvq2foVhP0IVX2CIprMJPK0vqGqgrDa0OHVKeZyBykqskkrdxV6yKBPmGasO8LVjAKR3Gew==", "dev": true, "dependencies": { - "@sinonjs/commons": "^1.6.0", + "@sinonjs/commons": "^2.0.0", "lodash.get": "^4.4.2", "type-detect": "^4.0.8" } }, + "node_modules/@sinonjs/samsam/node_modules/@sinonjs/commons": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-2.0.0.tgz", + "integrity": "sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==", + "dev": true, + "dependencies": { + "type-detect": "4.0.8" + } + }, "node_modules/@sinonjs/text-encoding": { - "version": "0.7.2", - "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.2.tgz", - "integrity": "sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==", + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.3.tgz", + "integrity": "sha512-DE427ROAphMQzU4ENbliGYrBSYPXF+TtLg9S8vzeA+OF4ZKzoDdzfL8sxuMUGS/lgRhM6j1URSk9ghf7Xo1tyA==", "dev": true }, "node_modules/@socket.io/component-emitter": { @@ -749,24 +757,14 @@ } }, "node_modules/@types/sinon": { - "version": "10.0.11", - "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-10.0.11.tgz", - "integrity": "sha512-dmZsHlBsKUtBpHriNjlK0ndlvEh8dcb9uV9Afsbt89QIyydpC7NcR+nWlAhASfy3GHnxTl4FX/aKE7XZUt/B4g==", + "version": "17.0.3", + "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-17.0.3.tgz", + "integrity": "sha512-j3uovdn8ewky9kRBG19bOwaZbexJu/XjtkHyjvUgt4xfPFz18dcORIMqnYh66Fx3Powhcr85NT5+er3+oViapw==", "dev": true, "dependencies": { "@types/sinonjs__fake-timers": "*" } }, - "node_modules/@types/sinon-chai": { - "version": "3.2.9", - "resolved": "https://registry.npmjs.org/@types/sinon-chai/-/sinon-chai-3.2.9.tgz", - "integrity": "sha512-/19t63pFYU0ikrdbXKBWj9PCdnKyTd0Qkz0X91Ta081cYsq90OxYdcWwK/dwEoDa6dtXgj2HJfmzgq+QZTHdmQ==", - "dev": true, - "dependencies": { - "@types/chai": "*", - "@types/sinon": "*" - } - }, "node_modules/@types/sinonjs__fake-timers": { "version": "8.1.2", "resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.2.tgz", @@ -1744,9 +1742,9 @@ "dev": true }, "node_modules/body-parser": { - "version": "1.20.2", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", - "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==", + "version": "1.20.3", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.3.tgz", + "integrity": "sha512-7rAxByjUMqQ3/bHJy7D6OGXvx/MMc4IqBn/X0fcM1QUcAItpZrBEYhWGem+tzXH90c+G01ypMcYJBO9Y30203g==", "dev": true, "dependencies": { "bytes": "3.1.2", @@ -1757,7 +1755,7 @@ "http-errors": "2.0.0", "iconv-lite": "0.4.24", "on-finished": "2.4.1", - "qs": "6.11.0", + "qs": "6.13.0", "raw-body": "2.5.2", "type-is": "~1.6.18", "unpipe": "1.0.0" @@ -2044,13 +2042,19 @@ } }, "node_modules/call-bind": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", - "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", + "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", "dev": true, "dependencies": { - "function-bind": "^1.1.1", - "get-intrinsic": "^1.0.2" + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "set-function-length": "^1.2.1" + }, + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -2575,6 +2579,23 @@ "node": ">=10" } }, + "node_modules/define-data-property": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", + "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", + "dev": true, + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "gopd": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/define-properties": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.0.tgz", @@ -2902,6 +2923,27 @@ "resolved": "https://registry.npmjs.org/err-code/-/err-code-3.0.1.tgz", "integrity": "sha512-GiaH0KJUewYok+eeY05IIgjtAe4Yltygk9Wqp1V5yVWLdhf0hYZchRjNIT9bb0mSwRcIusT3cx7PJUf3zEIfUA==" }, + "node_modules/es-define-property": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", + "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", + "dev": true, + "dependencies": { + "get-intrinsic": "^1.2.4" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "dev": true, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/es6-object-assign": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/es6-object-assign/-/es6-object-assign-1.1.0.tgz", @@ -3477,10 +3519,13 @@ } }, "node_modules/function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", - "dev": true + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } }, "node_modules/get-caller-file": { "version": "2.0.5", @@ -3501,15 +3546,19 @@ } }, "node_modules/get-intrinsic": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz", - "integrity": "sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", + "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", "dev": true, "dependencies": { - "function-bind": "^1.1.1", - "has": "^1.0.3", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", "has-proto": "^1.0.1", - "has-symbols": "^1.0.3" + "has-symbols": "^1.0.3", + "hasown": "^2.0.0" + }, + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -3725,12 +3774,12 @@ } }, "node_modules/has-property-descriptors": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.0.tgz", - "integrity": "sha512-62DVLZGoiEBDHQyqG4w9xCuZ7eJEwNmJRWw2VY84Oedb7WFcA27fiEVe8oUQx9hAUJ4ekurquucTGwsyO1XGdQ==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", + "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", "dev": true, "dependencies": { - "get-intrinsic": "^1.1.1" + "es-define-property": "^1.0.0" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -3833,6 +3882,18 @@ "minimalistic-assert": "^1.0.1" } }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "dev": true, + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/he": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", @@ -4403,12 +4464,6 @@ "node": ">=8" } }, - "node_modules/isarray": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==", - "dev": true - }, "node_modules/isbinaryfile": { "version": "4.0.10", "resolved": "https://registry.npmjs.org/isbinaryfile/-/isbinaryfile-4.0.10.tgz", @@ -4665,9 +4720,9 @@ } }, "node_modules/just-extend": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.2.1.tgz", - "integrity": "sha512-g3UB796vUFIY90VIv/WX3L2c8CS2MdWUww3CNrYmqza1Fg0DURc2K/O4YrnklBdQarSJ/y8JnJYDGc+1iumQjg==", + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-6.2.0.tgz", + "integrity": "sha512-cYofQu2Xpom82S6qD778jBDpwvvy39s1l/hrYij2u9AMdQcGRpaBu6kY4mVhuno5kJVi1DAz4aiphA2WI1/OAw==", "dev": true }, "node_modules/karma": { @@ -5616,43 +5671,16 @@ "dev": true }, "node_modules/nise": { - "version": "5.1.4", - "resolved": "https://registry.npmjs.org/nise/-/nise-5.1.4.tgz", - "integrity": "sha512-8+Ib8rRJ4L0o3kfmyVCL7gzrohyDe0cMFTBa2d364yIrEGMEoetznKJx899YxjybU6bL9SQkYPSBBs1gyYs8Xg==", - "dev": true, - "dependencies": { - "@sinonjs/commons": "^2.0.0", - "@sinonjs/fake-timers": "^10.0.2", - "@sinonjs/text-encoding": "^0.7.1", - "just-extend": "^4.0.2", - "path-to-regexp": "^1.7.0" - } - }, - "node_modules/nise/node_modules/@sinonjs/commons": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-2.0.0.tgz", - "integrity": "sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==", - "dev": true, - "dependencies": { - "type-detect": "4.0.8" - } - }, - "node_modules/nise/node_modules/@sinonjs/fake-timers": { - "version": "10.3.0", - "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-10.3.0.tgz", - "integrity": "sha512-V4BG07kuYSUkTCSBHG8G8TNhM+F19jXFWnQtzj+we8DrkpSBCee9Z3Ms8yiGer/dlmhe35/Xdgyo3/0rQKg7YA==", - "dev": true, - "dependencies": { - "@sinonjs/commons": "^3.0.0" - } - }, - "node_modules/nise/node_modules/@sinonjs/fake-timers/node_modules/@sinonjs/commons": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.0.tgz", - "integrity": "sha512-jXBtWAF4vmdNmZgD5FoKsVLv3rPgDnLgPbU84LIJ3otV44vJlDRokVng5v8NFJdCf/da9legHcKaRuZs4L7faA==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/nise/-/nise-6.0.1.tgz", + "integrity": "sha512-DAyWGPQEuJVlL2eqKw6gdZKT+E/jo/ZrjEUDAslJLluCz81nWy+KSYybNp3KFm887Yvp7hv12jSM82ld8BmLxg==", "dev": true, "dependencies": { - "type-detect": "4.0.8" + "@sinonjs/commons": "^3.0.0", + "@sinonjs/fake-timers": "^11.2.2", + "@sinonjs/text-encoding": "^0.7.2", + "just-extend": "^6.2.0", + "path-to-regexp": "^8.1.0" } }, "node_modules/no-case": { @@ -5801,10 +5829,13 @@ } }, "node_modules/object-inspect": { - "version": "1.12.3", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz", - "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==", + "version": "1.13.2", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", + "integrity": "sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g==", "dev": true, + "engines": { + "node": ">= 0.4" + }, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -6034,12 +6065,12 @@ "dev": true }, "node_modules/path-to-regexp": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", - "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.1.0.tgz", + "integrity": "sha512-Bqn3vc8CMHty6zuD+tG23s6v2kwxslHEhTj4eYaVKGIEB+YX/2wd0/rgXLFD9G9id9KCtbVy/3ZgmvZjpa0UdQ==", "dev": true, - "dependencies": { - "isarray": "0.0.1" + "engines": { + "node": ">=16" } }, "node_modules/path-type": { @@ -6246,12 +6277,12 @@ } }, "node_modules/qs": { - "version": "6.11.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", - "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz", + "integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==", "dev": true, "dependencies": { - "side-channel": "^1.0.4" + "side-channel": "^1.0.6" }, "engines": { "node": ">=0.6" @@ -6680,6 +6711,23 @@ "randombytes": "^2.1.0" } }, + "node_modules/set-function-length": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", + "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", + "dev": true, + "dependencies": { + "define-data-property": "^1.1.4", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/setimmediate": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", @@ -6727,14 +6775,18 @@ } }, "node_modules/side-channel": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", - "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", + "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==", "dev": true, "dependencies": { - "call-bind": "^1.0.0", - "get-intrinsic": "^1.0.2", - "object-inspect": "^1.9.0" + "call-bind": "^1.0.7", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.4", + "object-inspect": "^1.13.1" + }, + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -6747,23 +6799,32 @@ "dev": true }, "node_modules/sinon": { - "version": "13.0.1", - "resolved": "https://registry.npmjs.org/sinon/-/sinon-13.0.1.tgz", - "integrity": "sha512-8yx2wIvkBjIq/MGY1D9h1LMraYW+z1X0mb648KZnKSdvLasvDu7maa0dFaNYdTDczFgbjNw2tOmWdTk9saVfwQ==", + "version": "18.0.1", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-18.0.1.tgz", + "integrity": "sha512-a2N2TDY1uGviajJ6r4D1CyRAkzE9NNVlYOV1wX5xQDuAk0ONgzgRl0EjCQuRCPxOwp13ghsMwt9Gdldujs39qw==", "dev": true, "dependencies": { - "@sinonjs/commons": "^1.8.3", - "@sinonjs/fake-timers": "^9.0.0", - "@sinonjs/samsam": "^6.1.1", - "diff": "^5.0.0", - "nise": "^5.1.1", - "supports-color": "^7.2.0" + "@sinonjs/commons": "^3.0.1", + "@sinonjs/fake-timers": "11.2.2", + "@sinonjs/samsam": "^8.0.0", + "diff": "^5.2.0", + "nise": "^6.0.0", + "supports-color": "^7" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/sinon" } }, + "node_modules/sinon/node_modules/diff": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-5.2.0.tgz", + "integrity": "sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A==", + "dev": true, + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/sisteransi": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", @@ -7146,93 +7207,6 @@ "typescript": ">=4.2.0" } }, - "node_modules/ts-sinon": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/ts-sinon/-/ts-sinon-2.0.2.tgz", - "integrity": "sha512-Eh6rXPQruACHPn+/e5HsIMaHZa17tGP/scGjUeW5eJ/Levn8hBV6zSP/6QkEDUP7wLkTyY0yeYikjpTzgC9Gew==", - "dev": true, - "dependencies": { - "@types/node": "^14.6.1", - "@types/sinon": "^9.0.5", - "@types/sinon-chai": "^3.2.4", - "sinon": "^9.0.3" - } - }, - "node_modules/ts-sinon/node_modules/@sinonjs/fake-timers": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-6.0.1.tgz", - "integrity": "sha512-MZPUxrmFubI36XS1DI3qmI0YdN1gks62JtFZvxR67ljjSNCeK6U08Zx4msEWOXuofgqUt6zPHSi1H9fbjR/NRA==", - "dev": true, - "dependencies": { - "@sinonjs/commons": "^1.7.0" - } - }, - "node_modules/ts-sinon/node_modules/@sinonjs/samsam": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-5.3.1.tgz", - "integrity": "sha512-1Hc0b1TtyfBu8ixF/tpfSHTVWKwCBLY4QJbkgnE7HcwyvT2xArDxb4K7dMgqRm3szI+LJbzmW/s4xxEhv6hwDg==", - "dev": true, - "dependencies": { - "@sinonjs/commons": "^1.6.0", - "lodash.get": "^4.4.2", - "type-detect": "^4.0.8" - } - }, - "node_modules/ts-sinon/node_modules/@types/node": { - "version": "14.18.53", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.53.tgz", - "integrity": "sha512-soGmOpVBUq+gaBMwom1M+krC/NNbWlosh4AtGA03SyWNDiqSKtwp7OulO1M6+mg8YkHMvJ/y0AkCeO8d1hNb7A==", - "dev": true - }, - "node_modules/ts-sinon/node_modules/@types/sinon": { - "version": "9.0.11", - "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-9.0.11.tgz", - "integrity": "sha512-PwP4UY33SeeVKodNE37ZlOsR9cReypbMJOhZ7BVE0lB+Hix3efCOxiJWiE5Ia+yL9Cn2Ch72EjFTRze8RZsNtg==", - "dev": true, - "dependencies": { - "@types/sinonjs__fake-timers": "*" - } - }, - "node_modules/ts-sinon/node_modules/diff": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", - "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", - "dev": true, - "engines": { - "node": ">=0.3.1" - } - }, - "node_modules/ts-sinon/node_modules/nise": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/nise/-/nise-4.1.0.tgz", - "integrity": "sha512-eQMEmGN/8arp0xsvGoQ+B1qvSkR73B1nWSCh7nOt5neMCtwcQVYQGdzQMhcNscktTsWB54xnlSQFzOAPJD8nXA==", - "dev": true, - "dependencies": { - "@sinonjs/commons": "^1.7.0", - "@sinonjs/fake-timers": "^6.0.0", - "@sinonjs/text-encoding": "^0.7.1", - "just-extend": "^4.0.2", - "path-to-regexp": "^1.7.0" - } - }, - "node_modules/ts-sinon/node_modules/sinon": { - "version": "9.2.4", - "resolved": "https://registry.npmjs.org/sinon/-/sinon-9.2.4.tgz", - "integrity": "sha512-zljcULZQsJxVra28qIAL6ow1Z9tpattkCTEJR4RBP3TGc00FcttsP5pK284Nas5WjMZU5Yzy3kAIp3B3KRf5Yg==", - "dev": true, - "dependencies": { - "@sinonjs/commons": "^1.8.1", - "@sinonjs/fake-timers": "^6.0.1", - "@sinonjs/samsam": "^5.3.1", - "diff": "^4.0.2", - "nise": "^4.0.4", - "supports-color": "^7.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/sinon" - } - }, "node_modules/tsconfig-paths-webpack-plugin": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/tsconfig-paths-webpack-plugin/-/tsconfig-paths-webpack-plugin-4.1.0.tgz", diff --git a/package.json b/package.json index 5d01a0cba..43ba8d8af 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tbd54566975/dwn-sdk-js", - "version": "0.4.6", + "version": "0.4.7", "description": "A reference implementation of https://identity.foundation/decentralized-web-node/spec/", "repository": { "type": "git", @@ -101,7 +101,7 @@ "@types/randombytes": "2.0.0", "@types/readable-stream": "4.0.10", "@types/secp256k1": "4.0.3", - "@types/sinon": "10.0.11", + "@types/sinon": "^17.0.3", "@types/uuid": "^9.0.1", "@types/varint": "6.0.0", "@typescript-eslint/eslint-plugin": "^7.9.0", @@ -133,8 +133,7 @@ "playwright": "^1.44.0", "rimraf": "^3.0.2", "search-index": "3.4.0", - "sinon": "13.0.1", - "ts-sinon": "^2.0.2", + "sinon": "18.0.1", "typescript": "^5.1.6", "util": "0.12.4" }, diff --git a/tests/core/protocol-authorization.spec.ts b/tests/core/protocol-authorization.spec.ts index 71dc134df..202190250 100644 --- a/tests/core/protocol-authorization.spec.ts +++ b/tests/core/protocol-authorization.spec.ts @@ -1,12 +1,16 @@ -import type { MessageStore } from '../../src/index.js'; - import { DwnErrorCode } from '../../src/core/dwn-error.js'; import { expect } from 'chai'; +import { MessageStoreLevel } from '../../src/index.js'; import { ProtocolAuthorization } from '../../src/core/protocol-authorization.js'; -import { stubInterface } from 'ts-sinon'; import { TestDataGenerator } from '../utils/test-data-generator.js'; +import sinon from 'sinon'; + describe('ProtocolAuthorization', () => { + beforeEach(() => { + sinon.restore(); + }); + describe('authorizeWrite()', () => { it('should throw if message references non-existent parent', async () => { const alice = await TestDataGenerator.generateDidKeyPersona(); @@ -17,7 +21,7 @@ describe('ProtocolAuthorization', () => { }); // stub the message store - const messageStoreStub = stubInterface(); + const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); messageStoreStub.query.resolves({ messages: [] }); // simulate parent not in message store await expect(ProtocolAuthorization.authorizeWrite(alice.did, recordsWrite, messageStoreStub)).to.be.rejectedWith( @@ -38,7 +42,7 @@ describe('ProtocolAuthorization', () => { } } as any; - const messageStoreStub = stubInterface(); + const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); expect(ProtocolAuthorization['getActionsSeekingARuleMatch'](alice.did, deliberatelyCraftedInvalidMessage, messageStoreStub)).to.be.empty; }); }); diff --git a/tests/dwn.spec.ts b/tests/dwn.spec.ts index d308c20ae..bd48f856a 100644 --- a/tests/dwn.spec.ts +++ b/tests/dwn.spec.ts @@ -6,10 +6,10 @@ import type { DataStore, EventLog, MessageStore, ResumableTaskStore } from '../s import chaiAsPromised from 'chai-as-promised'; import sinon from 'sinon'; import chai, { expect } from 'chai'; +import { DataStoreLevel, EventEmitterStream, EventLogLevel, MessageStoreLevel, ResumableTaskStoreLevel } from '../src/index.js'; import { Dwn } from '../src/dwn.js'; import { Message } from '../src/core/message.js'; -import { stubInterface } from 'ts-sinon'; import { TestDataGenerator } from './utils/test-data-generator.js'; import { TestEventStream } from './test-event-stream.js'; import { TestStores } from './test-stores.js'; @@ -50,6 +50,7 @@ export function testDwnClass(): void { }); after(async () => { + sinon.restore(); await dwn.close(); }); @@ -133,11 +134,11 @@ export function testDwnClass(): void { } }; - const messageStoreStub = stubInterface(); - const dataStoreStub = stubInterface(); - const resumableTaskStoreStub = stubInterface(); - const eventLogStub = stubInterface(); - const eventStreamStub = stubInterface(); + const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); + const dataStoreStub = sinon.createStubInstance(DataStoreLevel); + const resumableTaskStoreStub = sinon.createStubInstance(ResumableTaskStoreLevel); + const eventLogStub = sinon.createStubInstance(EventLogLevel); + const eventStreamStub = sinon.createStubInstance(EventEmitterStream); const dwnWithConfig = await Dwn.create({ tenantGate : blockAllTenantGate, @@ -166,12 +167,11 @@ export function testDwnClass(): void { return { isActiveTenant: false, detail: customMessage }; } }; - - const messageStoreStub = stubInterface(); - const dataStoreStub = stubInterface(); - const resumableTaskStoreStub = stubInterface(); - const eventLogStub = stubInterface(); - const eventStreamStub = stubInterface(); + const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); + const dataStoreStub = sinon.createStubInstance(DataStoreLevel); + const resumableTaskStoreStub = sinon.createStubInstance(ResumableTaskStoreLevel); + const eventLogStub = sinon.createStubInstance(EventLogLevel); + const eventStreamStub = sinon.createStubInstance(EventEmitterStream); const dwnWithConfig = await Dwn.create({ tenantGate : blockAllTenantGate, diff --git a/tests/handlers/records-delete.spec.ts b/tests/handlers/records-delete.spec.ts index 36c2bacb1..306ab7bd2 100644 --- a/tests/handlers/records-delete.spec.ts +++ b/tests/handlers/records-delete.spec.ts @@ -1,6 +1,6 @@ import type { DidResolver } from '@web5/dids'; import type { EventStream } from '../../src/types/subscriptions.js'; -import type { ResumableTaskManager } from '../../src/core/resumable-task-manager.js'; +import { ResumableTaskManager } from '../../src/core/resumable-task-manager.js'; import type { DataStore, EventLog, @@ -25,13 +25,12 @@ import { DwnMethodName } from '../../src/enums/dwn-interface-method.js'; import { Message } from '../../src/core/message.js'; import { normalizeSchemaUrl } from '../../src/utils/url.js'; import { RecordsDeleteHandler } from '../../src/handlers/records-delete.js'; -import { stubInterface } from 'ts-sinon'; import { TestDataGenerator } from '../utils/test-data-generator.js'; import { TestEventStream } from '../test-event-stream.js'; import { TestStores } from '../test-stores.js'; import { TestStubGenerator } from '../utils/test-stub-generator.js'; import { Time } from '../../src/utils/time.js'; -import { DataStream, Dwn, Encoder, Jws, RecordsDelete, RecordsRead, RecordsWrite } from '../../src/index.js'; +import { DataStream, Dwn, Encoder, Jws, MessageStoreLevel, RecordsDelete, RecordsRead, RecordsWrite } from '../../src/index.js'; import { DidKey, UniversalResolver } from '@web5/dids'; chai.use(chaiAsPromised); @@ -46,6 +45,14 @@ export function testRecordsDeleteHandler(): void { let eventStream: EventStream; let dwn: Dwn; + beforeEach(() => { + sinon.restore(); + }); + + after(() => { + sinon.restore(); + }); + describe('functional tests', () => { // important to follow the `before` and `after` pattern to initialize and clean the stores in tests @@ -64,8 +71,6 @@ export function testRecordsDeleteHandler(): void { }); beforeEach(async () => { - sinon.restore(); // wipe all previous stubs/spies/mocks/fakes - // clean up before each test rather than after so that a test does not depend on other tests to do the clean up await messageStore.clear(); await dataStore.clear(); @@ -764,10 +769,12 @@ export function testRecordsDeleteHandler(): void { // intentionally not supplying the public key so a different public key is generated to simulate invalid signature const mismatchingPersona = await TestDataGenerator.generatePersona({ did: author.did, keyId: author.keyId }); const didResolver = TestStubGenerator.createDidResolverStub(mismatchingPersona); - const messageStore = stubInterface(); - const resumableTaskManager = stubInterface(); - const recordsDeleteHandler = new RecordsDeleteHandler(didResolver, messageStore, resumableTaskManager); + // setting up a stub method resolver & message store + const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); + const resumableTaskManagerStub = sinon.createStubInstance(ResumableTaskManager); + + const recordsDeleteHandler = new RecordsDeleteHandler(didResolver, messageStoreStub, resumableTaskManagerStub); const reply = await recordsDeleteHandler.handle({ tenant, message }); expect(reply.status.code).to.equal(401); }); @@ -777,10 +784,10 @@ export function testRecordsDeleteHandler(): void { const tenant = author.did; // setting up a stub method resolver & message store - const messageStore = stubInterface(); - const resumableTaskManager = stubInterface(); + const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); + const resumableTaskManagerStub = sinon.createStubInstance(ResumableTaskManager); - const recordsDeleteHandler = new RecordsDeleteHandler(didResolver, messageStore, resumableTaskManager); + const recordsDeleteHandler = new RecordsDeleteHandler(didResolver, messageStoreStub, resumableTaskManagerStub); // stub the `parse()` function to throw an error sinon.stub(RecordsDelete, 'parse').throws('anyError'); diff --git a/tests/handlers/records-query.spec.ts b/tests/handlers/records-query.spec.ts index a7bd14bfa..3f5ab9767 100644 --- a/tests/handlers/records-query.spec.ts +++ b/tests/handlers/records-query.spec.ts @@ -23,18 +23,22 @@ import { Message } from '../../src/core/message.js'; import { RecordsQuery } from '../../src/interfaces/records-query.js'; import { RecordsQueryHandler } from '../../src/handlers/records-query.js'; import { RecordsWriteHandler } from '../../src/handlers/records-write.js'; -import { stubInterface } from 'ts-sinon'; import { TestDataGenerator } from '../utils/test-data-generator.js'; import { TestEventStream } from '../test-event-stream.js'; import { TestStores } from '../test-stores.js'; import { TestStubGenerator } from '../utils/test-stub-generator.js'; +import { DataStoreLevel, Dwn, MessageStoreLevel, RecordsWrite, Time } from '../../src/index.js'; import { DidKey, UniversalResolver } from '@web5/dids'; -import { Dwn, RecordsWrite, Time } from '../../src/index.js'; chai.use(chaiAsPromised); export function testRecordsQueryHandler(): void { describe('RecordsQueryHandler.handle()', () => { + + beforeEach(() => { + sinon.restore(); // wipe all previous stubs/spies/mocks/fakes + }); + describe('functional tests', () => { let didResolver: DidResolver; let messageStore: MessageStore; @@ -60,8 +64,6 @@ export function testRecordsQueryHandler(): void { }); beforeEach(async () => { - sinon.restore(); // wipe all previous stubs/spies/mocks/fakes - // clean up before each test rather than after so that a test does not depend on other tests to do the clean up await messageStore.clear(); await dataStore.clear(); @@ -3005,10 +3007,10 @@ export function testRecordsQueryHandler(): void { // intentionally not supplying the public key so a different public key is generated to simulate invalid signature const mismatchingPersona = await TestDataGenerator.generatePersona({ did: author!.did, keyId: author!.keyId }); const didResolver = TestStubGenerator.createDidResolverStub(mismatchingPersona); - const messageStore = stubInterface(); - const dataStore = stubInterface(); + const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); + const dataStoreStub = sinon.createStubInstance(DataStoreLevel); - const recordsQueryHandler = new RecordsQueryHandler(didResolver, messageStore, dataStore); + const recordsQueryHandler = new RecordsQueryHandler(didResolver, messageStoreStub, dataStoreStub); const reply = await recordsQueryHandler.handle({ tenant, message }); expect(reply.status.code).to.equal(401); @@ -3020,9 +3022,9 @@ export function testRecordsQueryHandler(): void { // setting up a stub method resolver & message store const didResolver = TestStubGenerator.createDidResolverStub(author!); - const messageStore = stubInterface(); - const dataStore = stubInterface(); - const recordsQueryHandler = new RecordsQueryHandler(didResolver, messageStore, dataStore); + const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); + const dataStoreStub = sinon.createStubInstance(DataStoreLevel); + const recordsQueryHandler = new RecordsQueryHandler(didResolver, messageStoreStub, dataStoreStub); // stub the `parse()` function to throw an error sinon.stub(RecordsQuery, 'parse').throws('anyError'); diff --git a/tests/handlers/records-read.spec.ts b/tests/handlers/records-read.spec.ts index 7bddd5f98..74cf790fe 100644 --- a/tests/handlers/records-read.spec.ts +++ b/tests/handlers/records-read.spec.ts @@ -4,7 +4,7 @@ import type { EncryptionInput } from '../../src/interfaces/records-write.js'; import type { EventStream } from '../../src/types/subscriptions.js'; import type { DataStore, EventLog, MessageStore, ProtocolDefinition, ProtocolsConfigureMessage, ResumableTaskStore } from '../../src/index.js'; -import { DwnConstant, PermissionsProtocol, Time } from '../../src/index.js'; +import { DataStoreLevel, DwnConstant, MessageStoreLevel, PermissionsProtocol, Time } from '../../src/index.js'; import { DwnInterfaceName, DwnMethodName } from '../../src/index.js'; import chaiAsPromised from 'chai-as-promised'; @@ -26,7 +26,6 @@ import { Encryption } from '../../src/utils/encryption.js'; import { HdKey } from '../../src/utils/hd-key.js'; import { KeyDerivationScheme } from '../../src/utils/hd-key.js'; import { RecordsReadHandler } from '../../src/handlers/records-read.js'; -import { stubInterface } from 'ts-sinon'; import { TestDataGenerator } from '../utils/test-data-generator.js'; import { TestEventStream } from '../test-event-stream.js'; import { TestStores } from '../test-stores.js'; @@ -48,6 +47,10 @@ export function testRecordsReadHandler(): void { let eventStream: EventStream; let dwn: Dwn; + beforeEach(() => { + sinon.restore(); // wipe all previous stubs/spies/mocks/fakes + }); + describe('functional tests', () => { // important to follow the `before` and `after` pattern to initialize and clean the stores in tests @@ -66,8 +69,6 @@ export function testRecordsReadHandler(): void { }); beforeEach(async () => { - sinon.restore(); // wipe all previous stubs/spies/mocks/fakes - // clean up before each test rather than after so that a test does not depend on other tests to do the clean up await messageStore.clear(); await dataStore.clear(); @@ -1893,10 +1894,10 @@ export function testRecordsReadHandler(): void { // intentionally not supplying the public key so a different public key is generated to simulate invalid signature const mismatchingPersona = await TestDataGenerator.generatePersona({ did: alice.did, keyId: alice.keyId }); const didResolver = TestStubGenerator.createDidResolverStub(mismatchingPersona); - const messageStore = stubInterface(); - const dataStore = stubInterface(); + const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); + const dataStoreStub = sinon.createStubInstance(DataStoreLevel); - const recordsReadHandler = new RecordsReadHandler(didResolver, messageStore, dataStore); + const recordsReadHandler = new RecordsReadHandler(didResolver, messageStoreStub, dataStoreStub); const reply = await recordsReadHandler.handle({ tenant: alice.did, message: recordsRead.message }); expect(reply.status.code).to.equal(401); }); @@ -1911,10 +1912,10 @@ export function testRecordsReadHandler(): void { }); // setting up a stub method resolver & message store - const messageStore = stubInterface(); - const dataStore = stubInterface(); + const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); + const dataStoreStub = sinon.createStubInstance(DataStoreLevel); - const recordsReadHandler = new RecordsReadHandler(didResolver, messageStore, dataStore); + const recordsReadHandler = new RecordsReadHandler(didResolver, messageStoreStub, dataStoreStub); // stub the `parse()` function to throw an error sinon.stub(RecordsRead, 'parse').throws('anyError'); diff --git a/tests/handlers/records-subscribe.spec.ts b/tests/handlers/records-subscribe.spec.ts index fc5c156ca..e9e391c18 100644 --- a/tests/handlers/records-subscribe.spec.ts +++ b/tests/handlers/records-subscribe.spec.ts @@ -15,13 +15,12 @@ import { Message } from '../../src/core/message.js'; import { Poller } from '../utils/poller.js'; import { RecordsSubscribe } from '../../src/interfaces/records-subscribe.js'; import { RecordsSubscribeHandler } from '../../src/handlers/records-subscribe.js'; -import { stubInterface } from 'ts-sinon'; import { TestDataGenerator } from '../utils/test-data-generator.js'; import { TestEventStream } from '../test-event-stream.js'; import { TestStores } from '../test-stores.js'; import { TestStubGenerator } from '../utils/test-stub-generator.js'; import { DidKey, UniversalResolver } from '@web5/dids'; -import { Dwn, DwnErrorCode, DwnMethodName, Time } from '../../src/index.js'; +import { Dwn, DwnErrorCode, DwnMethodName, EventEmitterStream, MessageStoreLevel, Time } from '../../src/index.js'; chai.use(chaiAsPromised); @@ -232,10 +231,10 @@ export function testRecordsSubscribeHandler(): void { // intentionally not supplying the public key so a different public key is generated to simulate invalid signature const mismatchingPersona = await TestDataGenerator.generatePersona({ did: author!.did, keyId: author!.keyId }); const didResolver = TestStubGenerator.createDidResolverStub(mismatchingPersona); - const messageStore = stubInterface(); - const eventStream = stubInterface(); + const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); + const eventStreamStub = sinon.createStubInstance(EventEmitterStream); - const recordsSubscribeHandler = new RecordsSubscribeHandler(didResolver, messageStore, eventStream); + const recordsSubscribeHandler = new RecordsSubscribeHandler(didResolver, messageStoreStub, eventStreamStub); const reply = await recordsSubscribeHandler.handle({ tenant, message, subscriptionHandler: () => {} }); expect(reply.status.code).to.equal(401); @@ -247,9 +246,9 @@ export function testRecordsSubscribeHandler(): void { // setting up a stub method resolver & message store const didResolver = TestStubGenerator.createDidResolverStub(author!); - const messageStore = stubInterface(); - const eventStream = stubInterface(); - const recordsSubscribeHandler = new RecordsSubscribeHandler(didResolver, messageStore, eventStream); + const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); + const eventStreamStub = sinon.createStubInstance(EventEmitterStream); + const recordsSubscribeHandler = new RecordsSubscribeHandler(didResolver, messageStoreStub, eventStreamStub); // stub the `parse()` function to throw an error sinon.stub(RecordsSubscribe, 'parse').throws('anyError'); diff --git a/tests/handlers/records-write.spec.ts b/tests/handlers/records-write.spec.ts index 2f5084676..1d18daaf8 100644 --- a/tests/handlers/records-write.spec.ts +++ b/tests/handlers/records-write.spec.ts @@ -36,7 +36,6 @@ import { PermissionConditionPublication } from '../../src/types/permission-types import { RecordsRead } from '../../src/interfaces/records-read.js'; import { RecordsWrite } from '../../src/interfaces/records-write.js'; import { RecordsWriteHandler } from '../../src/handlers/records-write.js'; -import { stubInterface } from 'ts-sinon'; import { TestDataGenerator } from '../utils/test-data-generator.js'; import { TestEventStream } from '../test-event-stream.js'; import { TestStores } from '../test-stores.js'; @@ -44,8 +43,8 @@ import { TestStubGenerator } from '../utils/test-stub-generator.js'; import { Time } from '../../src/utils/time.js'; import { DwnError, DwnErrorCode } from '../../src/core/dwn-error.js'; +import { DataStoreLevel, DwnConstant, DwnInterfaceName, DwnMethodName, KeyDerivationScheme, MessageStoreLevel, PermissionsProtocol, RecordsDelete, RecordsQuery } from '../../src/index.js'; import { DidKey, UniversalResolver } from '@web5/dids'; -import { DwnConstant, DwnInterfaceName, DwnMethodName, KeyDerivationScheme, PermissionsProtocol, RecordsDelete, RecordsQuery } from '../../src/index.js'; import { Encryption, EncryptionAlgorithm } from '../../src/utils/encryption.js'; chai.use(chaiAsPromised); @@ -60,6 +59,10 @@ export function testRecordsWriteHandler(): void { let eventStream: EventStream; let dwn: Dwn; + beforeEach(() => { + sinon.restore(); + }); + describe('functional tests', () => { // important to follow the `before` and `after` pattern to initialize and clean the stores in tests @@ -78,8 +81,6 @@ export function testRecordsWriteHandler(): void { }); beforeEach(async () => { - sinon.restore(); // wipe all previous stubs/spies/mocks/fakes - // clean up before each test rather than after so that a test does not depend on other tests to do the clean up await messageStore.clear(); await dataStore.clear(); @@ -4231,10 +4232,10 @@ export function testRecordsWriteHandler(): void { const tenant = author.did; const didResolver = TestStubGenerator.createDidResolverStub(author); - const messageStore = stubInterface(); - const dataStore = stubInterface(); + const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); + const dataStoreStub = sinon.createStubInstance(DataStoreLevel); - const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStore, dataStore, eventLog, eventStream); + const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStoreStub, dataStoreStub, eventLog, eventStream); const reply = await recordsWriteHandler.handle({ tenant, message, dataStream: dataStream! }); expect(reply.status.code).to.equal(400); @@ -4255,10 +4256,10 @@ export function testRecordsWriteHandler(): void { const tenant = author.did; const didResolver = sinon.createStubInstance(UniversalResolver); - const messageStore = stubInterface(); - const dataStore = stubInterface(); + const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); + const dataStoreStub = sinon.createStubInstance(DataStoreLevel); - const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStore, dataStore, eventLog, eventStream); + const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStoreStub, dataStoreStub, eventLog, eventStream); const reply = await recordsWriteHandler.handle({ tenant, message, dataStream: dataStream! }); expect(reply.status.code).to.equal(400); @@ -4273,10 +4274,10 @@ export function testRecordsWriteHandler(): void { // intentionally not supplying the public key so a different public key is generated to simulate invalid signature const mismatchingPersona = await TestDataGenerator.generatePersona({ did: author.did, keyId: author.keyId }); const didResolver = TestStubGenerator.createDidResolverStub(mismatchingPersona); - const messageStore = stubInterface(); - const dataStore = stubInterface(); + const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); + const dataStoreStub = sinon.createStubInstance(DataStoreLevel); - const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStore, dataStore, eventLog, eventStream); + const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStoreStub, dataStoreStub, eventLog, eventStream); const reply = await recordsWriteHandler.handle({ tenant, message, dataStream: dataStream! }); expect(reply.status.code).to.equal(401); @@ -4288,10 +4289,10 @@ export function testRecordsWriteHandler(): void { // setting up a stub DID resolver & message store const didResolver = TestStubGenerator.createDidResolverStub(author); - const messageStore = stubInterface(); - const dataStore = stubInterface(); + const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); + const dataStoreStub = sinon.createStubInstance(DataStoreLevel); - const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStore, dataStore, eventLog, eventStream); + const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStoreStub, dataStoreStub, eventLog, eventStream); const tenant = await (await TestDataGenerator.generatePersona()).did; // unauthorized tenant const reply = await recordsWriteHandler.handle({ tenant, message, dataStream: dataStream! }); @@ -4321,10 +4322,10 @@ export function testRecordsWriteHandler(): void { message.authorization = { signature: authorizationBuilder.getJws() }; const didResolver = TestStubGenerator.createDidResolverStub(author); - const messageStore = stubInterface(); - const dataStore = stubInterface(); + const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); + const dataStoreStub = sinon.createStubInstance(DataStoreLevel); - const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStore, dataStore, eventLog, eventStream); + const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStoreStub, dataStoreStub, eventLog, eventStream); const reply = await recordsWriteHandler.handle({ tenant, message, dataStream: dataStream! }); expect(reply.status.code).to.equal(400); @@ -4377,10 +4378,6 @@ export function testRecordsWriteHandler(): void { }); describe('unknown error', () => { - beforeEach(() => { - sinon.restore(); // wipe all previous stubs/spies/mocks/fakes - }); - it('should throw if `recordsWriteHandler.processMessageWithoutDataStream()` throws unknown error', async () => { // simulate an initial write to test non-data path, as initial writes without data are always accepted (bot not readable) // https://github.com/TBD54566975/dwn-sdk-js/issues/628 @@ -4390,11 +4387,10 @@ export function testRecordsWriteHandler(): void { const { message, dataStream } = await TestDataGenerator.generateFromRecordsWrite({ author, existingWrite: initialWrite }); const tenant = author.did; const didResolverStub = TestStubGenerator.createDidResolverStub(author); - - const messageStoreStub = stubInterface(); + const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); messageStoreStub.query.resolves({ messages: [ initialWriteMessage ] }); - const dataStoreStub = stubInterface(); + const dataStoreStub = sinon.createStubInstance(DataStoreLevel); const recordsWriteHandler = new RecordsWriteHandler(didResolverStub, messageStoreStub, dataStoreStub, eventLog, eventStream); diff --git a/tests/interfaces/records-write.spec.ts b/tests/interfaces/records-write.spec.ts index f6b4cd3af..02c4cc91a 100644 --- a/tests/interfaces/records-write.spec.ts +++ b/tests/interfaces/records-write.spec.ts @@ -1,24 +1,26 @@ -import type { MessageStore } from '../../src/types/message-store.js'; import type { EncryptionInput, RecordsWriteOptions } from '../../src/interfaces/records-write.js'; import type { PermissionScope, Signer } from '../../src/index.js'; import chaiAsPromised from 'chai-as-promised'; -import Sinon from 'sinon'; +import sinon from 'sinon'; import chai, { expect } from 'chai'; import { DwnErrorCode } from '../../src/core/dwn-error.js'; import { RecordsWrite } from '../../src/interfaces/records-write.js'; import { RecordsWriteHandler } from '../../src/handlers/records-write.js'; -import { stubInterface } from 'ts-sinon'; import { TestDataGenerator } from '../utils/test-data-generator.js'; import { Time } from '../../src/utils/time.js'; -import { DwnInterfaceName, DwnMethodName, Encoder, Jws, KeyDerivationScheme, Message, PermissionsProtocol } from '../../src/index.js'; +import { DwnInterfaceName, DwnMethodName, Encoder, Jws, KeyDerivationScheme, Message, MessageStoreLevel, PermissionsProtocol } from '../../src/index.js'; chai.use(chaiAsPromised); describe('RecordsWrite', () => { + beforeEach(() => { + sinon.restore(); + }); + describe('create()', () => { it('should be able to create and authorize a valid RecordsWrite message', async () => { // testing `create()` first @@ -40,7 +42,7 @@ describe('RecordsWrite', () => { expect(message.descriptor.dateCreated).to.equal(options.dateCreated); expect(message.recordId).to.equal(options.recordId); - const messageStoreStub = stubInterface(); + const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); await RecordsWriteHandler['authorizeRecordsWrite'](alice.did, recordsWrite, messageStoreStub); }); @@ -346,7 +348,7 @@ describe('RecordsWrite', () => { data : TestDataGenerator.randomBytes(10), }); - const validateJsonSchemaSpy = Sinon.spy(Message, 'validateJsonSchema'); + const validateJsonSchemaSpy = sinon.spy(Message, 'validateJsonSchema'); await RecordsWrite.parse(recordsWrite.message);