spec-3nweb-server 1.8.5 → 1.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitlab-ci-linux.yml +50 -0
- package/.gitlab-ci-mac.yml +29 -0
- package/.gitlab-ci-windows.yml +29 -0
- package/.gitlab-ci.yml +63 -0
- package/build/mock/tls-options.js +46 -44
- package/build/tests/admin-proto/signup.d.ts +1 -0
- package/build/tests/admin-proto/signup.js +235 -0
- package/build/tests/jasmine.d.ts +1 -0
- package/build/tests/jasmine.js +32 -0
- package/build/tests/libs-for-tests/3nstorage.d.ts +22 -0
- package/build/tests/libs-for-tests/3nstorage.js +123 -0
- package/build/tests/libs-for-tests/asmail.d.ts +22 -0
- package/build/tests/libs-for-tests/asmail.js +179 -0
- package/build/tests/libs-for-tests/assert.d.ts +1 -0
- package/build/tests/libs-for-tests/assert.js +26 -0
- package/build/tests/libs-for-tests/async-jasmine.d.ts +7 -0
- package/build/tests/libs-for-tests/async-jasmine.js +77 -0
- package/build/tests/libs-for-tests/bytes-equal.d.ts +1 -0
- package/build/tests/libs-for-tests/bytes-equal.js +34 -0
- package/build/tests/libs-for-tests/json-copy.d.ts +1 -0
- package/build/tests/libs-for-tests/json-copy.js +45 -0
- package/build/tests/libs-for-tests/json-equal.d.ts +4 -0
- package/build/tests/libs-for-tests/json-equal.js +67 -0
- package/build/tests/libs-for-tests/mailerid.d.ts +13 -0
- package/build/tests/libs-for-tests/mailerid.js +114 -0
- package/build/tests/libs-for-tests/pkl.d.ts +28 -0
- package/build/tests/libs-for-tests/pkl.js +89 -0
- package/build/tests/libs-for-tests/server-components/3nstorage.d.ts +20 -0
- package/build/tests/libs-for-tests/server-components/3nstorage.js +200 -0
- package/build/tests/libs-for-tests/server-components/admin.d.ts +6 -0
- package/build/tests/libs-for-tests/server-components/admin.js +43 -0
- package/build/tests/libs-for-tests/server-components/asmail.d.ts +16 -0
- package/build/tests/libs-for-tests/server-components/asmail.js +143 -0
- package/build/tests/libs-for-tests/server-components/component.d.ts +13 -0
- package/build/tests/libs-for-tests/server-components/component.js +77 -0
- package/build/tests/libs-for-tests/server-components/mailerid.d.ts +10 -0
- package/build/tests/libs-for-tests/server-components/mailerid.js +103 -0
- package/build/tests/libs-for-tests/server-runner.d.ts +15 -0
- package/build/tests/libs-for-tests/server-runner.js +69 -0
- package/build/tests/libs-for-tests/spec-assembly.d.ts +6 -0
- package/build/tests/libs-for-tests/spec-assembly.js +55 -0
- package/build/tests/libs-for-tests/ws-utils.d.ts +3 -0
- package/build/tests/libs-for-tests/ws-utils.js +59 -0
- package/build/tests/libs-for-tests/xhr-utils.d.ts +61 -0
- package/build/tests/libs-for-tests/xhr-utils.js +154 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.js +84 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.js +78 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.js +83 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.js +77 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-obj.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-obj.js +75 -0
- package/build/tests/protocols/3nstorage/owner/specs/events.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/events.js +91 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.js +269 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-root.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-root.js +262 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.js +79 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-root-status.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-root-status.js +72 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.js +287 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-root.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-root.js +274 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.js +73 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.js +72 -0
- package/build/tests/protocols/3nstorage/owner/test-utils.d.ts +14 -0
- package/build/tests/protocols/3nstorage/owner/test-utils.js +54 -0
- package/build/tests/protocols/3nstorage/owner.d.ts +1 -0
- package/build/tests/protocols/3nstorage/owner.js +138 -0
- package/build/tests/protocols/asmail/config.d.ts +1 -0
- package/build/tests/protocols/asmail/config.js +117 -0
- package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.js +60 -0
- package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.js +68 -0
- package/build/tests/protocols/asmail/delivery/specs/put-metadata.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/put-metadata.js +83 -0
- package/build/tests/protocols/asmail/delivery/specs/put-obj.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/put-obj.js +123 -0
- package/build/tests/protocols/asmail/delivery/specs/restart-session.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/restart-session.js +79 -0
- package/build/tests/protocols/asmail/delivery/specs/start-session.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/start-session.js +64 -0
- package/build/tests/protocols/asmail/delivery/test-utils.d.ts +16 -0
- package/build/tests/protocols/asmail/delivery/test-utils.js +46 -0
- package/build/tests/protocols/asmail/delivery.d.ts +1 -0
- package/build/tests/protocols/asmail/delivery.js +46 -0
- package/build/tests/protocols/asmail/retrieval/specs/events.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/events.js +62 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.js +70 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.js +166 -0
- package/build/tests/protocols/asmail/retrieval/specs/list-messages.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/list-messages.js +96 -0
- package/build/tests/protocols/asmail/retrieval/specs/remove-message.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/remove-message.js +66 -0
- package/build/tests/protocols/asmail/retrieval/test-utils.d.ts +17 -0
- package/build/tests/protocols/asmail/retrieval/test-utils.js +46 -0
- package/build/tests/protocols/asmail/retrieval.d.ts +1 -0
- package/build/tests/protocols/asmail/retrieval.js +92 -0
- package/build/tests/protocols/mailerid.d.ts +1 -0
- package/build/tests/protocols/mailerid.js +210 -0
- package/build/tests/shared-checks/check-mid-login.d.ts +2 -0
- package/build/tests/shared-checks/check-mid-login.js +131 -0
- package/build/tests/shared-checks/requests.d.ts +20 -0
- package/build/tests/shared-checks/requests.js +123 -0
- package/package.json +1 -1
- package/packing/create-deb.sh +57 -0
- package/packing/deb/lib/systemd/system/3nweb.service +11 -0
- package/packing/deb/postinst +44 -0
- package/packing/deb/usr/share/doc/3nweb-server/conf-for-postinstall.yaml +19 -0
- package/packing/deb/usr/share/doc/3nweb-server/copyright +22 -0
- package/publish-task.sh +10 -0
- package/push-to-github.sh +105 -0
- package/ts-code/3nstorage/3nstorage-app.ts +99 -0
- package/ts-code/3nstorage/owner.ts +178 -0
- package/ts-code/3nstorage/resources/sessions.ts +37 -0
- package/ts-code/3nstorage/resources/store.ts +896 -0
- package/ts-code/3nstorage/resources/users.ts +258 -0
- package/ts-code/3nstorage/routes/owner/archive-obj-version.ts +73 -0
- package/ts-code/3nstorage/routes/owner/cancel-trans.ts +58 -0
- package/ts-code/3nstorage/routes/owner/delete-obj.ts +103 -0
- package/ts-code/3nstorage/routes/owner/get-archived-obj-ver.ts +111 -0
- package/ts-code/3nstorage/routes/owner/get-current-obj.ts +122 -0
- package/ts-code/3nstorage/routes/owner/get-obj-status.ts +55 -0
- package/ts-code/3nstorage/routes/owner/param-getter.ts +51 -0
- package/ts-code/3nstorage/routes/owner/param-setter.ts +50 -0
- package/ts-code/3nstorage/routes/owner/put-current-obj.ts +284 -0
- package/ts-code/3nstorage/routes/owner/session-params.ts +49 -0
- package/ts-code/3nstorage/shared.ts +43 -0
- package/ts-code/asmail/asmail-app.ts +91 -0
- package/ts-code/asmail/config.ts +96 -0
- package/ts-code/asmail/delivery.ts +94 -0
- package/ts-code/asmail/resources/delivery-sessions.ts +118 -0
- package/ts-code/asmail/resources/inbox.ts +696 -0
- package/ts-code/asmail/resources/recipients.ts +495 -0
- package/ts-code/asmail/resources/sessions.ts +37 -0
- package/ts-code/asmail/retrieval.ts +96 -0
- package/ts-code/asmail/routes/config/param-getter.ts +49 -0
- package/ts-code/asmail/routes/config/param-setter.ts +49 -0
- package/ts-code/asmail/routes/delivery/finalize-delivery.ts +50 -0
- package/ts-code/asmail/routes/delivery/pre-flight.ts +132 -0
- package/ts-code/asmail/routes/delivery/provide-recipient-pubkey.ts +58 -0
- package/ts-code/asmail/routes/delivery/put-metadata.ts +94 -0
- package/ts-code/asmail/routes/delivery/put-obj.ts +166 -0
- package/ts-code/asmail/routes/delivery/restart-session.ts +130 -0
- package/ts-code/asmail/routes/delivery/sender-authorization.ts +81 -0
- package/ts-code/asmail/routes/delivery/start-session.ts +151 -0
- package/ts-code/asmail/routes/retrieval/get-message-meta.ts +53 -0
- package/ts-code/asmail/routes/retrieval/get-message-obj.ts +109 -0
- package/ts-code/asmail/routes/retrieval/list-messages.ts +70 -0
- package/ts-code/asmail/routes/retrieval/remove-message.ts +47 -0
- package/ts-code/cli/index.ts +82 -0
- package/ts-code/cli/run-cmd.ts +81 -0
- package/ts-code/cli/show-sample-config.ts +78 -0
- package/ts-code/cli/signup-cmd.ts +229 -0
- package/ts-code/cli/user-cmd.ts +68 -0
- package/ts-code/cli/utils.ts +105 -0
- package/ts-code/config/default-confs.ts +22 -0
- package/ts-code/config/from-yaml.ts +35 -0
- package/ts-code/config/letsencrypt.ts +77 -0
- package/ts-code/config/signup.ts +137 -0
- package/ts-code/lib-common/admin-api/signup.ts +120 -0
- package/ts-code/lib-common/assert.ts +22 -0
- package/ts-code/lib-common/async-fs-node.ts +656 -0
- package/ts-code/lib-common/buffer-utils.ts +124 -0
- package/ts-code/lib-common/byte-streaming/common.ts +166 -0
- package/ts-code/lib-common/bytes-equal.ts +25 -0
- package/ts-code/lib-common/canonical-address.ts +92 -0
- package/ts-code/lib-common/exceptions/error.ts +44 -0
- package/ts-code/lib-common/exceptions/file.ts +84 -0
- package/ts-code/lib-common/exceptions/http.ts +69 -0
- package/ts-code/lib-common/ipc/generic-ipc.ts +750 -0
- package/ts-code/lib-common/ipc/ws-ipc.ts +117 -0
- package/ts-code/lib-common/json-equal.ts +55 -0
- package/ts-code/lib-common/json-utils.ts +130 -0
- package/ts-code/lib-common/jwkeys.ts +246 -0
- package/ts-code/lib-common/map-of-sets.ts +60 -0
- package/ts-code/lib-common/mid-sigs-NaCl-Ed.ts +677 -0
- package/ts-code/lib-common/objs-on-disk/file-layout.ts +480 -0
- package/ts-code/lib-common/objs-on-disk/obj-file.ts +325 -0
- package/ts-code/lib-common/objs-on-disk/utils.ts +201 -0
- package/ts-code/lib-common/objs-on-disk/v1-obj-file-format.ts +329 -0
- package/ts-code/lib-common/processes.ts +501 -0
- package/ts-code/lib-common/random-node.ts +79 -0
- package/ts-code/lib-common/service-api/3nstorage/owner.ts +559 -0
- package/ts-code/lib-common/service-api/3nstorage/root-route.ts +22 -0
- package/ts-code/lib-common/service-api/asmail/config.ts +144 -0
- package/ts-code/lib-common/service-api/asmail/delivery.ts +250 -0
- package/ts-code/lib-common/service-api/asmail/retrieval.ts +238 -0
- package/ts-code/lib-common/service-api/asmail/root-route.ts +22 -0
- package/ts-code/lib-common/service-api/ipc-api.ts +44 -0
- package/ts-code/lib-common/service-api/locker.ts +44 -0
- package/ts-code/lib-common/service-api/mailer-id/login.ts +80 -0
- package/ts-code/lib-common/service-api/mailer-id/provisioning.ts +64 -0
- package/ts-code/lib-common/service-api/mailer-id/root-route.ts +25 -0
- package/ts-code/lib-common/service-api/pub-key-login.ts +75 -0
- package/ts-code/lib-common/service-api/web-socket-base.ts +87 -0
- package/ts-code/lib-common/session-encryptor.ts +54 -0
- package/ts-code/lib-common/time-window-cache.ts +74 -0
- package/ts-code/lib-common/transferable.d.ts +30 -0
- package/ts-code/lib-server/conf-util.ts +35 -0
- package/ts-code/lib-server/mid-access.ts +45 -0
- package/ts-code/lib-server/middleware/body-parsers.ts +248 -0
- package/ts-code/lib-server/middleware/error-handler.ts +79 -0
- package/ts-code/lib-server/pkl-access.ts +46 -0
- package/ts-code/lib-server/resources/dns.ts +151 -0
- package/ts-code/lib-server/resources/mailerid-authorizer.ts +115 -0
- package/ts-code/lib-server/resources/mem-backed-sessions-factory.ts +132 -0
- package/ts-code/lib-server/resources/server-data-folders.ts +160 -0
- package/ts-code/lib-server/resources/server-key-for-pkl-challenge.ts +41 -0
- package/ts-code/lib-server/resources/sessions.ts +232 -0
- package/ts-code/lib-server/resources/user-files.ts +147 -0
- package/ts-code/lib-server/routes/pub-key-login/complete-exchange.ts +63 -0
- package/ts-code/lib-server/routes/pub-key-login/start-exchange.ts +189 -0
- package/ts-code/lib-server/routes/sessions/close.ts +27 -0
- package/ts-code/lib-server/routes/sessions/mid-auth.ts +77 -0
- package/ts-code/lib-server/routes/sessions/start.ts +116 -0
- package/ts-code/lib-server/web-sockets/app.ts +339 -0
- package/ts-code/lib-server/web-sockets/server-events.ts +63 -0
- package/ts-code/lib.ts +29 -0
- package/ts-code/locker/locker-app.ts +60 -0
- package/ts-code/locker/resources/lockers.ts +17 -0
- package/ts-code/locker/resources/sessions.ts +37 -0
- package/ts-code/locker/routes/create-locker.ts +47 -0
- package/ts-code/mailerId/mailerId-app.ts +107 -0
- package/ts-code/mailerId/resources/certifier.ts +181 -0
- package/ts-code/mailerId/resources/sessions.ts +44 -0
- package/ts-code/mailerId/resources/users.ts +88 -0
- package/ts-code/mailerId/routes/certify.ts +68 -0
- package/ts-code/main.ts +304 -0
- package/ts-code/mock/dns.ts +106 -0
- package/ts-code/mock/mock-as-child-proc.ts +130 -0
- package/ts-code/mock/node-child-ipc.ts +69 -0
- package/ts-code/mock/run-in-proc.ts +111 -0
- package/ts-code/mock/tls-options.ts +73 -0
- package/ts-code/services.ts +138 -0
- package/ts-code/signup/resources/users.ts +429 -0
- package/ts-code/signup/routes/add.ts +65 -0
- package/ts-code/signup/routes/get-available-addresses.ts +49 -0
- package/ts-code/signup/routes/get-available-domains.ts +45 -0
- package/ts-code/signup/signup-app.ts +54 -0
- package/ts-code/signup/signup-tokens.ts +148 -0
- package/ts-code/tests/admin-proto/signup.ts +277 -0
- package/ts-code/tests/jasmine.ts +37 -0
- package/ts-code/tests/libs-for-tests/3nstorage.ts +144 -0
- package/ts-code/tests/libs-for-tests/asmail.ts +220 -0
- package/ts-code/tests/libs-for-tests/assert.ts +22 -0
- package/ts-code/tests/libs-for-tests/async-jasmine.ts +89 -0
- package/ts-code/tests/libs-for-tests/bytes-equal.ts +25 -0
- package/ts-code/tests/libs-for-tests/json-copy.ts +38 -0
- package/ts-code/tests/libs-for-tests/json-equal.ts +55 -0
- package/ts-code/tests/libs-for-tests/mailerid.ts +123 -0
- package/ts-code/tests/libs-for-tests/pkl.ts +127 -0
- package/ts-code/tests/libs-for-tests/server-components/3nstorage.ts +206 -0
- package/ts-code/tests/libs-for-tests/server-components/admin.ts +49 -0
- package/ts-code/tests/libs-for-tests/server-components/asmail.ts +152 -0
- package/ts-code/tests/libs-for-tests/server-components/component.ts +90 -0
- package/ts-code/tests/libs-for-tests/server-components/mailerid.ts +114 -0
- package/ts-code/tests/libs-for-tests/server-runner.ts +82 -0
- package/ts-code/tests/libs-for-tests/spec-assembly.ts +60 -0
- package/ts-code/tests/libs-for-tests/ws-utils.ts +61 -0
- package/ts-code/tests/libs-for-tests/xhr-utils.ts +179 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/archive-obj-ver.ts +100 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/archive-root-ver.ts +91 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.ts +99 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.ts +90 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/delete-obj.ts +84 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/events.ts +125 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-obj.ts +298 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-root.ts +290 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-obj-status.ts +88 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-root-status.ts +80 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-obj.ts +366 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-root.ts +329 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel-root.ts +86 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel.ts +86 -0
- package/ts-code/tests/protocols/3nstorage/owner/test-utils.ts +72 -0
- package/ts-code/tests/protocols/3nstorage/owner.ts +198 -0
- package/ts-code/tests/protocols/asmail/config.ts +172 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/finalize-delivery.ts +69 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.ts +88 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/put-metadata.ts +102 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/put-obj.ts +156 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/restart-session.ts +97 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/start-session.ts +79 -0
- package/ts-code/tests/protocols/asmail/delivery/test-utils.ts +64 -0
- package/ts-code/tests/protocols/asmail/delivery.ts +56 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/events.ts +78 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-meta.ts +80 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-obj.ts +197 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/list-messages.ts +110 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/remove-message.ts +74 -0
- package/ts-code/tests/protocols/asmail/retrieval/test-utils.ts +60 -0
- package/ts-code/tests/protocols/asmail/retrieval.ts +115 -0
- package/ts-code/tests/protocols/mailerid.ts +271 -0
- package/ts-code/tests/shared-checks/check-mid-login.ts +164 -0
- package/ts-code/tests/shared-checks/requests.ts +135 -0
- package/ts-code/tsconfig.json +11 -0
- package/ts-code/web3n.d.ts +1068 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2017 3NSoft Inc.
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
6
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
7
|
+
version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful, but
|
|
10
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
See the GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU General Public License along with
|
|
15
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { RawDuplex, EventfulServer, makeEventfulServer,
|
|
19
|
+
SubscribingClient, makeSubscribingClient, Envelope, Observer,
|
|
20
|
+
MultiObserverWrap }
|
|
21
|
+
from './generic-ipc';
|
|
22
|
+
import * as WebSocket from 'ws';
|
|
23
|
+
|
|
24
|
+
export { RequestEnvelope, RequestHandler, EventfulServer, makeEventfulServer,
|
|
25
|
+
SubscribingClient }
|
|
26
|
+
from './generic-ipc';
|
|
27
|
+
|
|
28
|
+
export interface WSException extends web3n.RuntimeException {
|
|
29
|
+
type: 'websocket',
|
|
30
|
+
socketSlow?: true
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const MAX_TXT_BUFFER = 64*1024;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* This creates a json communication point on a given web socket.
|
|
37
|
+
* Point may have many listeners, allowing for single parsing of incoming
|
|
38
|
+
* messages.
|
|
39
|
+
* @param ws
|
|
40
|
+
*/
|
|
41
|
+
export function makeJsonCommPoint(ws: WebSocket): RawDuplex<Envelope> {
|
|
42
|
+
|
|
43
|
+
const observers = new MultiObserverWrap<Envelope>();
|
|
44
|
+
|
|
45
|
+
ws.on('message', onTxtMessage(ws, observers));
|
|
46
|
+
ws.on('close', onClose(observers));
|
|
47
|
+
ws.on('error', onError(ws, observers));
|
|
48
|
+
|
|
49
|
+
const commPoint: RawDuplex<Envelope> = {
|
|
50
|
+
subscribe: obs => observers.add(obs),
|
|
51
|
+
postMessage(env: Envelope): void {
|
|
52
|
+
if ((ws as any).bufferedAmount > MAX_TXT_BUFFER) {
|
|
53
|
+
const exc: WSException = {
|
|
54
|
+
runtimeException: true,
|
|
55
|
+
type: 'websocket',
|
|
56
|
+
socketSlow: true
|
|
57
|
+
};
|
|
58
|
+
throw exc;
|
|
59
|
+
}
|
|
60
|
+
ws.send(JSON.stringify(env));
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
return commPoint;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* This generates an on-message callback for text messages in a web socket.
|
|
68
|
+
* @param ws
|
|
69
|
+
* @param observers
|
|
70
|
+
*/
|
|
71
|
+
function onTxtMessage(ws: WebSocket, observers: MultiObserverWrap<Envelope>):
|
|
72
|
+
(data: any) => void {
|
|
73
|
+
return (data: any): void => {
|
|
74
|
+
if (typeof data !== 'string') { return; }
|
|
75
|
+
if (observers.done) { return; }
|
|
76
|
+
|
|
77
|
+
let env: Envelope;
|
|
78
|
+
try {
|
|
79
|
+
env = JSON.parse(data);
|
|
80
|
+
} catch (err) {
|
|
81
|
+
ws.close();
|
|
82
|
+
observers.error(err);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
observers.next(env);
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* This generates an on-close callback for a web socket.
|
|
92
|
+
* @param observers
|
|
93
|
+
*/
|
|
94
|
+
function onClose(observers: MultiObserverWrap<any>): () => void {
|
|
95
|
+
return () => observers.complete();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* This generates an on-error callback for a web socket.
|
|
100
|
+
* @param ws
|
|
101
|
+
* @param observers
|
|
102
|
+
*/
|
|
103
|
+
function onError(ws: WebSocket, observers: MultiObserverWrap<any>):
|
|
104
|
+
((err: any) => void) {
|
|
105
|
+
return (err?: any): void => {
|
|
106
|
+
observers.error(err);
|
|
107
|
+
ws.close();
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function makeSubscriber(ws: WebSocket, ipcChannel: string|undefined):
|
|
112
|
+
SubscribingClient {
|
|
113
|
+
const comm = makeJsonCommPoint(ws);
|
|
114
|
+
return makeSubscribingClient(ipcChannel, comm);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 3NSoft Inc.
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
6
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
7
|
+
version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful, but
|
|
10
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
See the GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU General Public License along with
|
|
15
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This module provides hex encoding of binary array into a string.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
export function deepEqual(a: any, b: any): boolean {
|
|
23
|
+
|
|
24
|
+
const t = typeof a;
|
|
25
|
+
|
|
26
|
+
if (t !== typeof b) { return false; }
|
|
27
|
+
|
|
28
|
+
if (t !== 'object') {
|
|
29
|
+
return (a === b);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (a === b) { return true; }
|
|
33
|
+
if ((a === null) || (b === null)) { return false; }
|
|
34
|
+
|
|
35
|
+
if (Array.isArray(a)) {
|
|
36
|
+
if (!Array.isArray(b)) { return false; }
|
|
37
|
+
const aArr = <Array<any>> a;
|
|
38
|
+
const bArr = <Array<any>> b;
|
|
39
|
+
if (aArr.length !== bArr.length) { return false; }
|
|
40
|
+
for (let i=0; i<aArr.length; i+=1) {
|
|
41
|
+
if (!deepEqual(aArr[i], bArr[i])) { return false; }
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
const keys = Object.keys(a);
|
|
45
|
+
if (keys.length !== Object.keys(b).length) { return false; }
|
|
46
|
+
for (let i=0; i<keys.length; i+=1) {
|
|
47
|
+
const key = keys[i];
|
|
48
|
+
if (!deepEqual(a[key], b[key])) { return false; }
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2016 - 2018 3NSoft Inc.
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
6
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
7
|
+
version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful, but
|
|
10
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
See the GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU General Public License along with
|
|
15
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* This function creates a copy of json entity with a caveat that Buffer and
|
|
21
|
+
* byte arrays are shared between original and a copy.
|
|
22
|
+
* @param orig is an object, which copy is created. Buffer and byte arrays
|
|
23
|
+
* passed through like primitives.
|
|
24
|
+
* @param excludeTopFields is an optional list of fields to exclude from copy.
|
|
25
|
+
*/
|
|
26
|
+
export function copy<T>(orig: T, excludeTopFields?: string[]): T {
|
|
27
|
+
const origType = typeof orig;
|
|
28
|
+
if (origType !== 'object') {
|
|
29
|
+
return ((origType !== 'function') ? orig : (undefined as any));
|
|
30
|
+
}
|
|
31
|
+
if (orig === null) { return (null as any); }
|
|
32
|
+
if (Buffer.isBuffer(orig)) { return (orig as any); }
|
|
33
|
+
if (ArrayBuffer.isView(orig)) { return (orig as any); }
|
|
34
|
+
if (Array.isArray(orig)) {
|
|
35
|
+
const arr: any[] = orig;
|
|
36
|
+
const c: any[] = [];
|
|
37
|
+
for (let i=0; i < arr.length; i+=1) {
|
|
38
|
+
c[i] = copy(arr[i]);
|
|
39
|
+
}
|
|
40
|
+
return (c as any);
|
|
41
|
+
} else {
|
|
42
|
+
const c = ({} as T);
|
|
43
|
+
const fields = Object.keys(orig!);
|
|
44
|
+
if (excludeTopFields) {
|
|
45
|
+
for (const f of fields) {
|
|
46
|
+
if (excludeTopFields.includes(f)) { continue; }
|
|
47
|
+
c[f] = copy<any>(orig![f]);
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
for (const f of fields) {
|
|
51
|
+
c[f] = copy<any>(orig![f]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return c;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function deepEqual(a: any, b: any): boolean {
|
|
59
|
+
|
|
60
|
+
const t = typeof a;
|
|
61
|
+
|
|
62
|
+
if (t !== typeof b) { return false; }
|
|
63
|
+
|
|
64
|
+
if (t !== 'object') {
|
|
65
|
+
return (a === b);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (a === b) { return true; }
|
|
69
|
+
if ((a === null) || (b === null)) { return false; }
|
|
70
|
+
|
|
71
|
+
if (Array.isArray(a)) {
|
|
72
|
+
if (!Array.isArray(b)) { return false; }
|
|
73
|
+
const aArr = <Array<any>> a;
|
|
74
|
+
const bArr = <Array<any>> b;
|
|
75
|
+
if (aArr.length !== bArr.length) { return false; }
|
|
76
|
+
for (let i=0; i<aArr.length; i+=1) {
|
|
77
|
+
if (!deepEqual(aArr[i], bArr[i])) { return false; }
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
const keys = Object.keys(a);
|
|
81
|
+
if (keys.length !== Object.keys(b).length) { return false; }
|
|
82
|
+
for (let i=0; i<keys.length; i+=1) {
|
|
83
|
+
const key = keys[i];
|
|
84
|
+
if (!deepEqual(a[key], b[key])) { return false; }
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function* deepFind(a: any, predicate: (val: any) => boolean):
|
|
92
|
+
IterableIterator<{ pos: string[]; val: any; }> {
|
|
93
|
+
if ((typeof a !== 'object') || !a) {
|
|
94
|
+
if (predicate(a)) {
|
|
95
|
+
yield { pos: [], val: a };
|
|
96
|
+
}
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
for (const field in a) {
|
|
101
|
+
const val = a[field];
|
|
102
|
+
if (predicate(val)) {
|
|
103
|
+
yield { pos: [ field ], val };
|
|
104
|
+
} else {
|
|
105
|
+
for (const inner of deepFind(val, predicate)) {
|
|
106
|
+
inner.pos.unshift(field);
|
|
107
|
+
yield inner;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* This function applies given changes to object.
|
|
115
|
+
* @param json is an object that is being changed
|
|
116
|
+
* @param changes is a set of changes to apply to an object. Undefined value in
|
|
117
|
+
* in a fields means that respective field should be deleted from an object.
|
|
118
|
+
*/
|
|
119
|
+
export function applyChangesToJSON<T>(json: T, changes: Partial<T>): void {
|
|
120
|
+
for (const f of Object.keys(changes)) {
|
|
121
|
+
const newValue = changes[f as keyof T];
|
|
122
|
+
if (newValue === undefined) {
|
|
123
|
+
delete json[f];
|
|
124
|
+
} else {
|
|
125
|
+
json[f] = newValue;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 3NSoft Inc.
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
6
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
7
|
+
version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful, but
|
|
10
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
See the GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU General Public License along with
|
|
15
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This module defines json form of keys and signed objects.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { utf8, base64 } from "./buffer-utils";
|
|
23
|
+
|
|
24
|
+
export interface JsonKeyShort {
|
|
25
|
+
/**
|
|
26
|
+
* This is a base64 representation of key's bytes.
|
|
27
|
+
*/
|
|
28
|
+
k: string;
|
|
29
|
+
/**
|
|
30
|
+
* This is key's id.
|
|
31
|
+
*/
|
|
32
|
+
kid: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface JsonKey extends JsonKeyShort {
|
|
36
|
+
/**
|
|
37
|
+
* This field is indicates application's use of this key, for example,
|
|
38
|
+
* "private-mail-key". Notice that it has noting to do with crypto
|
|
39
|
+
* primitives, and everything to do with how key should be used by
|
|
40
|
+
* applications, that should check this field, so as to guard against
|
|
41
|
+
* miss-use of key material. Such strictness makes key reuse (bad security
|
|
42
|
+
* design) difficult.
|
|
43
|
+
*/
|
|
44
|
+
use: string;
|
|
45
|
+
/**
|
|
46
|
+
* This field indicates which crypto-box high level function should be used
|
|
47
|
+
* with this key, for example, "NaCl-xsp-box". Notice that, unlike initial
|
|
48
|
+
* JWK standard, alg is not for naming crypto primitive, because you,
|
|
49
|
+
* developer, should use complete functionality, like that provided by NaCl,
|
|
50
|
+
* and you should not be dealing with crypto primitives. Crypto primitives
|
|
51
|
+
* are for libs, that should be written by cryptographers. If cryptographer
|
|
52
|
+
* gives you only primitives, it is the same as car dealer giving you parts
|
|
53
|
+
* for the car instead of an actual car. Your would call dealer's bullshit,
|
|
54
|
+
* and you must call cryptographer's one as well. They, cryptographer, in a
|
|
55
|
+
* 2nd decade of the 21st centure have no excuse to give us, developers,
|
|
56
|
+
* incomplete libs with mere crypto primitives, which hurt, when assembled
|
|
57
|
+
* incorrectly.
|
|
58
|
+
*/
|
|
59
|
+
alg: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function isLikeJsonKey(jkey: JsonKey): boolean {
|
|
63
|
+
return (('object' === typeof jkey) && !!jkey &&
|
|
64
|
+
('string' === typeof jkey.alg) && !!jkey.alg &&
|
|
65
|
+
('string' === typeof jkey.kid) && !!jkey.kid &&
|
|
66
|
+
('string' === typeof jkey.k) && !!jkey.k &&
|
|
67
|
+
('string' === typeof jkey.kid && !!jkey.kid));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface Key {
|
|
71
|
+
/**
|
|
72
|
+
* This is key's bytes.
|
|
73
|
+
*/
|
|
74
|
+
k: Uint8Array;
|
|
75
|
+
/**
|
|
76
|
+
* This is key's id.
|
|
77
|
+
*/
|
|
78
|
+
kid: string;
|
|
79
|
+
/**
|
|
80
|
+
* This field is indicates application's use of this key, for example,
|
|
81
|
+
* "private-mail-key". Notice that it has noting to do with crypto
|
|
82
|
+
* primitives, and everything to do with how key should be used by
|
|
83
|
+
* applications, that should check this field, so as to guard against
|
|
84
|
+
* miss-use of key material. Such strictness makes key reuse (bad security
|
|
85
|
+
* design) difficult.
|
|
86
|
+
*/
|
|
87
|
+
use: string;
|
|
88
|
+
/**
|
|
89
|
+
* This field indicates which crypto-box high level function should be used
|
|
90
|
+
* with this key, for example, "NaCl-xsp-box". Notice that, unlike initial
|
|
91
|
+
* JWK standard, alg is not for naming crypto primitive, because you,
|
|
92
|
+
* developer, should use complete functionality, like that provided by NaCl,
|
|
93
|
+
* and you should not be dealing with crypto primitives. Crypto primitives
|
|
94
|
+
* are for libs, that should be written by cryptographers. If cryptographer
|
|
95
|
+
* gives you only primitives, it is the same as car dealer giving you parts
|
|
96
|
+
* for the car instead of an actual car. Your would call dealer's bullshit,
|
|
97
|
+
* and you must call cryptographer's one as well. They, cryptographer, in a
|
|
98
|
+
* 2nd decade of the 21st centure have no excuse to give us, developers,
|
|
99
|
+
* incomplete libs with mere crypto primitives, which hurt, when assembled
|
|
100
|
+
* incorrectly.
|
|
101
|
+
*/
|
|
102
|
+
alg: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface SignedLoad {
|
|
106
|
+
/**
|
|
107
|
+
* This is an id of a key that did the signature.
|
|
108
|
+
*/
|
|
109
|
+
alg: string;
|
|
110
|
+
/**
|
|
111
|
+
* This is a function, used to make signature.
|
|
112
|
+
*/
|
|
113
|
+
kid: string;
|
|
114
|
+
/**
|
|
115
|
+
* This is signature bytes, packed into base64 string.
|
|
116
|
+
*/
|
|
117
|
+
sig: string;
|
|
118
|
+
/**
|
|
119
|
+
* This is bytes (packed into base64 string), on which signature was done.
|
|
120
|
+
*/
|
|
121
|
+
load: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function isLikeSignedLoad(load: SignedLoad): boolean {
|
|
125
|
+
return (('object' === typeof load) && !!load &&
|
|
126
|
+
('string' === typeof load.alg) && !!load.alg &&
|
|
127
|
+
('string' === typeof load.kid) && !!load.kid &&
|
|
128
|
+
('string' === typeof load.sig) && !!load.sig &&
|
|
129
|
+
('string' === typeof load.load && !!load.load));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface KeyCert {
|
|
133
|
+
cert: {
|
|
134
|
+
publicKey: JsonKey;
|
|
135
|
+
principal: { address: string };
|
|
136
|
+
};
|
|
137
|
+
issuer: string;
|
|
138
|
+
issuedAt: number;
|
|
139
|
+
expiresAt: number;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function isLikeKeyCert(cert: KeyCert): boolean {
|
|
143
|
+
return (('object' === typeof cert) && !!cert &&
|
|
144
|
+
('number' === typeof cert.expiresAt) &&
|
|
145
|
+
('number' === typeof cert.issuedAt) &&
|
|
146
|
+
(cert.expiresAt > cert.issuedAt) &&
|
|
147
|
+
('string' === typeof cert.issuer) && !!cert.issuer &&
|
|
148
|
+
('object' === typeof cert.cert) && !!cert.cert &&
|
|
149
|
+
('object' === typeof cert.cert.principal) &&
|
|
150
|
+
!!cert.cert.principal &&
|
|
151
|
+
('string' === typeof cert.cert.principal.address) &&
|
|
152
|
+
!!cert.cert.principal.address &&
|
|
153
|
+
isLikeJsonKey(cert.cert.publicKey));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function isLikeSignedKeyCert(load: SignedLoad): boolean {
|
|
157
|
+
if (!isLikeSignedLoad(load)) { return false; }
|
|
158
|
+
try {
|
|
159
|
+
return isLikeKeyCert(JSON.parse(utf8.open(base64.open(load.load))));
|
|
160
|
+
} catch (e) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function keyFromJson(key: JsonKey,
|
|
166
|
+
use: string, alg: string, klen: number): Key {
|
|
167
|
+
if (key.use === use) {
|
|
168
|
+
if (key.alg === alg) {
|
|
169
|
+
const bytes = base64.open(key.k);
|
|
170
|
+
if (bytes.length !== klen) { throw new Error(
|
|
171
|
+
"Key "+key.kid+" has a wrong number of bytes"); }
|
|
172
|
+
return {
|
|
173
|
+
use: key.use,
|
|
174
|
+
alg: key.alg,
|
|
175
|
+
kid: key.kid,
|
|
176
|
+
k: bytes
|
|
177
|
+
};
|
|
178
|
+
} else {
|
|
179
|
+
throw new Error("Key "+key.kid+
|
|
180
|
+
", should be used with unsupported algorithm '"+
|
|
181
|
+
key.alg+"'");
|
|
182
|
+
}
|
|
183
|
+
} else {
|
|
184
|
+
throw new Error("Key "+key.kid+" has incorrect use '"+key.use+
|
|
185
|
+
"', instead of '"+use+"'");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function keyToJson(key: Key): JsonKey {
|
|
190
|
+
return {
|
|
191
|
+
use: key.use,
|
|
192
|
+
alg: key.alg,
|
|
193
|
+
kid: key.kid,
|
|
194
|
+
k: base64.pack(key.k)
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function getKeyCert(signedCert: SignedLoad): KeyCert {
|
|
199
|
+
return JSON.parse(utf8.open(base64.open(signedCert.load)));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function getPubKey(signedCert: SignedLoad): JsonKey {
|
|
203
|
+
return getKeyCert(signedCert).cert.publicKey;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function getPrincipalAddress(signedCert: SignedLoad): string {
|
|
207
|
+
return getKeyCert(signedCert).cert.principal.address;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export module use {
|
|
211
|
+
|
|
212
|
+
export const MID_PKLOGIN = 'login-pub-key';
|
|
213
|
+
|
|
214
|
+
}
|
|
215
|
+
Object.freeze(use);
|
|
216
|
+
|
|
217
|
+
export interface MailerIdAssertionLoad {
|
|
218
|
+
user: string;
|
|
219
|
+
rpDomain: string;
|
|
220
|
+
sessionId: string;
|
|
221
|
+
issuedAt: number;
|
|
222
|
+
expiresAt: number;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function isLikeMailerIdAssertion(
|
|
226
|
+
assertLoad: MailerIdAssertionLoad): boolean {
|
|
227
|
+
return (('object' === typeof assertLoad) && !!assertLoad &&
|
|
228
|
+
('string' === typeof assertLoad.user) && !!assertLoad.user &&
|
|
229
|
+
('string' === typeof assertLoad.rpDomain) && !!assertLoad.rpDomain &&
|
|
230
|
+
('string' === typeof assertLoad.sessionId) && !!assertLoad.sessionId &&
|
|
231
|
+
('number' === typeof assertLoad.expiresAt) &&
|
|
232
|
+
('number' === typeof assertLoad.issuedAt) &&
|
|
233
|
+
(assertLoad.expiresAt > assertLoad.issuedAt));
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function isLikeSignedMailerIdAssertion(load: SignedLoad): boolean {
|
|
237
|
+
if (!isLikeSignedLoad(load)) { return false; }
|
|
238
|
+
try {
|
|
239
|
+
return isLikeMailerIdAssertion(
|
|
240
|
+
JSON.parse(utf8.open(base64.open(load.load))));
|
|
241
|
+
} catch (e) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2017 3NSoft Inc.
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
6
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
7
|
+
version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful, but
|
|
10
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
See the GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU General Public License along with
|
|
15
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export class MapOfSets<TKey, TValue> {
|
|
19
|
+
|
|
20
|
+
private map = new Map<TKey, Set<TValue>>();
|
|
21
|
+
|
|
22
|
+
constructor() {
|
|
23
|
+
Object.freeze(this);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get(key: TKey): Set<TValue> | undefined {
|
|
27
|
+
return this.map.get(key);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
add(key: TKey, value: TValue): void {
|
|
31
|
+
let set = this.map.get(key);
|
|
32
|
+
if (set === undefined) {
|
|
33
|
+
set = new Set<TValue>();
|
|
34
|
+
this.map.set(key, set);
|
|
35
|
+
}
|
|
36
|
+
set.add(value);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
remove(key: TKey, value: TValue): void {
|
|
40
|
+
const set = this.map.get(key);
|
|
41
|
+
if (set === undefined) { return; }
|
|
42
|
+
set.delete(value);
|
|
43
|
+
if (set.size === 0) {
|
|
44
|
+
this.map.delete(key);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
removeAll(key: TKey): void {
|
|
49
|
+
this.map.delete(key);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
clear(): void {
|
|
53
|
+
this.map.clear();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
Object.freeze(MapOfSets.prototype);
|
|
58
|
+
Object.freeze(MapOfSets);
|
|
59
|
+
|
|
60
|
+
Object.freeze(exports);
|