ai 1.1.0 → 2.0.0
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/LICENSE +10 -24
- package/dist/ai-stream.d.ts +18 -0
- package/dist/ai-stream.js +132 -0
- package/dist/ai-stream.mjs +13 -0
- package/dist/anthropic-stream.d.ts +5 -0
- package/dist/anthropic-stream.js +133 -0
- package/dist/anthropic-stream.mjs +8 -0
- package/dist/chunk-265FSSO4.mjs +91 -0
- package/dist/chunk-2L3ZO4UM.mjs +45 -0
- package/dist/chunk-EZJ7FC5E.mjs +33 -0
- package/dist/chunk-JGDC3BXD.mjs +22 -0
- package/dist/chunk-NK2CVBLI.mjs +38 -0
- package/dist/chunk-PEYAHBDF.mjs +43 -0
- package/dist/chunk-TJMME6CL.mjs +24 -0
- package/dist/huggingface-stream.d.ts +5 -0
- package/dist/huggingface-stream.js +121 -0
- package/dist/huggingface-stream.mjs +8 -0
- package/dist/index.d.ts +131 -0
- package/dist/index.js +278 -0
- package/dist/index.mjs +35 -0
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.js +12 -0
- package/dist/index.test.mjs +10 -0
- package/dist/langchain-stream.d.ts +12 -0
- package/dist/langchain-stream.js +102 -0
- package/dist/langchain-stream.mjs +8 -0
- package/dist/openai-stream.d.ts +5 -0
- package/dist/openai-stream.js +144 -0
- package/dist/openai-stream.mjs +8 -0
- package/dist/streaming-text-response.d.ts +17 -0
- package/dist/streaming-text-response.js +75 -0
- package/dist/streaming-text-response.mjs +9 -0
- package/package.json +78 -29
- package/react/dist/chunk-5PP6W52J.mjs +202 -0
- package/react/dist/chunk-6EH3SWMP.mjs +55 -0
- package/react/dist/chunk-PW6HSU2N.mjs +154 -0
- package/react/dist/index.d.ts +3 -0
- package/react/dist/index.js +424 -0
- package/react/dist/index.mjs +12 -0
- package/react/dist/types-f862f74a.d.ts +123 -0
- package/react/dist/use-chat.d.ts +42 -0
- package/react/dist/use-chat.js +276 -0
- package/react/dist/use-chat.mjs +8 -0
- package/react/dist/use-completion.d.ts +47 -0
- package/react/dist/use-completion.js +229 -0
- package/react/dist/use-completion.mjs +8 -0
- package/svelte/dist/chunk-6USBQIV6.mjs +177 -0
- package/svelte/dist/chunk-BQ64GHZ3.mjs +136 -0
- package/svelte/dist/chunk-CENOSGDG.mjs +493 -0
- package/svelte/dist/index.d.ts +4 -0
- package/svelte/dist/index.js +808 -0
- package/svelte/dist/index.mjs +11 -0
- package/svelte/dist/types-f862f74a.d.ts +123 -0
- package/svelte/dist/use-chat.d.ts +39 -0
- package/svelte/dist/use-chat.js +680 -0
- package/svelte/dist/use-chat.mjs +7 -0
- package/svelte/dist/use-completion.d.ts +38 -0
- package/svelte/dist/use-completion.js +640 -0
- package/svelte/dist/use-completion.mjs +7 -0
- package/.npmignore +0 -15
- package/.travis.yml +0 -4
- package/README.md +0 -21
- package/bin/ai.js +0 -22
- package/index.js +0 -37
- package/node_modules/request/.npmignore +0 -2
- package/node_modules/request/.travis.yml +0 -12
- package/node_modules/request/CHANGELOG.md +0 -954
- package/node_modules/request/LICENSE +0 -55
- package/node_modules/request/README.md +0 -421
- package/node_modules/request/index.js +0 -166
- package/node_modules/request/lib/cookies.js +0 -40
- package/node_modules/request/lib/copy.js +0 -8
- package/node_modules/request/lib/debug.js +0 -7
- package/node_modules/request/lib/getSafe.js +0 -34
- package/node_modules/request/lib/optional.js +0 -5
- package/node_modules/request/node_modules/aws-sign2/LICENSE +0 -55
- package/node_modules/request/node_modules/aws-sign2/README.md +0 -4
- package/node_modules/request/node_modules/aws-sign2/index.js +0 -202
- package/node_modules/request/node_modules/aws-sign2/package.json +0 -47
- package/node_modules/request/node_modules/forever-agent/LICENSE +0 -55
- package/node_modules/request/node_modules/forever-agent/README.md +0 -4
- package/node_modules/request/node_modules/forever-agent/index.js +0 -119
- package/node_modules/request/node_modules/forever-agent/package.json +0 -46
- package/node_modules/request/node_modules/form-data/License +0 -19
- package/node_modules/request/node_modules/form-data/Readme.md +0 -175
- package/node_modules/request/node_modules/form-data/lib/form_data.js +0 -351
- package/node_modules/request/node_modules/form-data/node_modules/async/.travis.yml +0 -3
- package/node_modules/request/node_modules/form-data/node_modules/async/LICENSE +0 -19
- package/node_modules/request/node_modules/form-data/node_modules/async/README.md +0 -1646
- package/node_modules/request/node_modules/form-data/node_modules/async/component.json +0 -11
- package/node_modules/request/node_modules/form-data/node_modules/async/lib/async.js +0 -1123
- package/node_modules/request/node_modules/form-data/node_modules/async/package.json +0 -60
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/License +0 -19
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/Readme.md +0 -132
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/lib/combined_stream.js +0 -186
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/.npmignore +0 -2
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/License +0 -19
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/Makefile +0 -7
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/Readme.md +0 -154
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/lib/delayed_stream.js +0 -99
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/package.json +0 -42
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/common.js +0 -6
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-http-upload.js +0 -38
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-stream-auto-pause.js +0 -21
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-stream-pause.js +0 -14
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-stream.js +0 -48
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-handle-source-errors.js +0 -15
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-max-data-size.js +0 -18
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-pipe-resumes.js +0 -13
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-proxy-readable.js +0 -13
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/run.js +0 -7
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/package.json +0 -61
- package/node_modules/request/node_modules/form-data/node_modules/mime/LICENSE +0 -19
- package/node_modules/request/node_modules/form-data/node_modules/mime/README.md +0 -66
- package/node_modules/request/node_modules/form-data/node_modules/mime/mime.js +0 -114
- package/node_modules/request/node_modules/form-data/node_modules/mime/package.json +0 -59
- package/node_modules/request/node_modules/form-data/node_modules/mime/test.js +0 -84
- package/node_modules/request/node_modules/form-data/node_modules/mime/types/mime.types +0 -1588
- package/node_modules/request/node_modules/form-data/node_modules/mime/types/node.types +0 -77
- package/node_modules/request/node_modules/form-data/package.json +0 -80
- package/node_modules/request/node_modules/hawk/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/LICENSE +0 -24
- package/node_modules/request/node_modules/hawk/Makefile +0 -10
- package/node_modules/request/node_modules/hawk/README.md +0 -625
- package/node_modules/request/node_modules/hawk/example/usage.js +0 -78
- package/node_modules/request/node_modules/hawk/images/hawk.png +0 -0
- package/node_modules/request/node_modules/hawk/images/logo.png +0 -0
- package/node_modules/request/node_modules/hawk/index.js +0 -1
- package/node_modules/request/node_modules/hawk/lib/browser.js +0 -507
- package/node_modules/request/node_modules/hawk/lib/client.js +0 -371
- package/node_modules/request/node_modules/hawk/lib/crypto.js +0 -118
- package/node_modules/request/node_modules/hawk/lib/index.js +0 -15
- package/node_modules/request/node_modules/hawk/lib/server.js +0 -523
- package/node_modules/request/node_modules/hawk/lib/utils.js +0 -183
- package/node_modules/request/node_modules/hawk/node_modules/boom/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/node_modules/boom/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/node_modules/boom/LICENSE +0 -24
- package/node_modules/request/node_modules/hawk/node_modules/boom/Makefile +0 -11
- package/node_modules/request/node_modules/hawk/node_modules/boom/README.md +0 -6
- package/node_modules/request/node_modules/hawk/node_modules/boom/images/boom.png +0 -0
- package/node_modules/request/node_modules/hawk/node_modules/boom/index.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/boom/lib/index.js +0 -207
- package/node_modules/request/node_modules/hawk/node_modules/boom/package.json +0 -64
- package/node_modules/request/node_modules/hawk/node_modules/boom/test/index.js +0 -245
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/LICENSE +0 -24
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/Makefile +0 -11
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/README.md +0 -6
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/index.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/lib/index.js +0 -68
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/package.json +0 -65
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/test/index.js +0 -101
- package/node_modules/request/node_modules/hawk/node_modules/hoek/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/node_modules/hoek/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/node_modules/hoek/LICENSE +0 -33
- package/node_modules/request/node_modules/hawk/node_modules/hoek/Makefile +0 -10
- package/node_modules/request/node_modules/hawk/node_modules/hoek/README.md +0 -436
- package/node_modules/request/node_modules/hawk/node_modules/hoek/images/hoek.png +0 -0
- package/node_modules/request/node_modules/hawk/node_modules/hoek/index.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/hoek/lib/escape.js +0 -132
- package/node_modules/request/node_modules/hawk/node_modules/hoek/lib/index.js +0 -585
- package/node_modules/request/node_modules/hawk/node_modules/hoek/package.json +0 -70
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/escaper.js +0 -86
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/index.js +0 -1078
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test1.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test2.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test3.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/sntp/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/node_modules/sntp/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/node_modules/sntp/LICENSE +0 -24
- package/node_modules/request/node_modules/hawk/node_modules/sntp/Makefile +0 -11
- package/node_modules/request/node_modules/hawk/node_modules/sntp/README.md +0 -68
- package/node_modules/request/node_modules/hawk/node_modules/sntp/examples/offset.js +0 -16
- package/node_modules/request/node_modules/hawk/node_modules/sntp/examples/time.js +0 -25
- package/node_modules/request/node_modules/hawk/node_modules/sntp/index.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/sntp/lib/index.js +0 -409
- package/node_modules/request/node_modules/hawk/node_modules/sntp/package.json +0 -65
- package/node_modules/request/node_modules/hawk/node_modules/sntp/test/index.js +0 -359
- package/node_modules/request/node_modules/hawk/package.json +0 -70
- package/node_modules/request/node_modules/hawk/test/browser.js +0 -817
- package/node_modules/request/node_modules/hawk/test/client.js +0 -206
- package/node_modules/request/node_modules/hawk/test/crypto.js +0 -86
- package/node_modules/request/node_modules/hawk/test/index.js +0 -316
- package/node_modules/request/node_modules/hawk/test/message.js +0 -246
- package/node_modules/request/node_modules/hawk/test/readme.js +0 -98
- package/node_modules/request/node_modules/hawk/test/server.js +0 -686
- package/node_modules/request/node_modules/hawk/test/uri.js +0 -456
- package/node_modules/request/node_modules/hawk/test/utils.js +0 -120
- package/node_modules/request/node_modules/http-signature/.dir-locals.el +0 -6
- package/node_modules/request/node_modules/http-signature/.npmignore +0 -7
- package/node_modules/request/node_modules/http-signature/LICENSE +0 -18
- package/node_modules/request/node_modules/http-signature/README.md +0 -75
- package/node_modules/request/node_modules/http-signature/http_signing.md +0 -296
- package/node_modules/request/node_modules/http-signature/lib/index.js +0 -25
- package/node_modules/request/node_modules/http-signature/lib/parser.js +0 -304
- package/node_modules/request/node_modules/http-signature/lib/signer.js +0 -179
- package/node_modules/request/node_modules/http-signature/lib/util.js +0 -249
- package/node_modules/request/node_modules/http-signature/lib/verify.js +0 -42
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/.npmignore +0 -2
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/LICENSE +0 -19
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/README.md +0 -50
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/errors.js +0 -13
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/index.js +0 -27
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/reader.js +0 -267
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/types.js +0 -36
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/writer.js +0 -317
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/index.js +0 -20
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/package.json +0 -63
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/tst/ber/reader.test.js +0 -172
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/tst/ber/writer.test.js +0 -296
- package/node_modules/request/node_modules/http-signature/node_modules/assert-plus/README.md +0 -126
- package/node_modules/request/node_modules/http-signature/node_modules/assert-plus/assert.js +0 -196
- package/node_modules/request/node_modules/http-signature/node_modules/assert-plus/package.json +0 -38
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/CHANGELOG +0 -71
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/LICENSE +0 -24
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/README +0 -82
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/README.old +0 -298
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/ctf.js +0 -245
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/ctio.js +0 -1485
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/ctype.js +0 -944
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/man/man3ctype/ctio.3ctype +0 -241
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/package.json +0 -36
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tools/jsl.conf +0 -129
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tools/jsstyle +0 -839
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/float.json +0 -13
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/int.json +0 -13
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/psinfo.json +0 -104
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/struct.json +0 -19
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.fail.js +0 -39
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.float.js +0 -14
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.int.js +0 -14
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.psinfo.js +0 -17
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.struct.js +0 -18
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.typedef.js +0 -15
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/typedef.json +0 -14
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/float/tst.rfloat.js +0 -767
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/float/tst.wfloat.js +0 -753
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.64.js +0 -638
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.rint.js +0 -101
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.wbounds.js +0 -53
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.wint.js +0 -92
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.64.js +0 -451
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.roundtrip.js +0 -81
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.ruint.js +0 -95
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.wuint.js +0 -156
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.basicr.js +0 -50
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.basicw.js +0 -44
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.char.js +0 -42
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.endian.js +0 -45
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.oldwrite.js +0 -28
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.readSize.js +0 -128
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.structw.js +0 -28
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.writeStruct.js +0 -31
- package/node_modules/request/node_modules/http-signature/package.json +0 -54
- package/node_modules/request/node_modules/json-stringify-safe/LICENSE +0 -27
- package/node_modules/request/node_modules/json-stringify-safe/README.md +0 -49
- package/node_modules/request/node_modules/json-stringify-safe/package.json +0 -51
- package/node_modules/request/node_modules/json-stringify-safe/stringify.js +0 -39
- package/node_modules/request/node_modules/json-stringify-safe/test.js +0 -128
- package/node_modules/request/node_modules/mime-types/.npmignore +0 -14
- package/node_modules/request/node_modules/mime-types/.travis.yml +0 -12
- package/node_modules/request/node_modules/mime-types/LICENSE +0 -22
- package/node_modules/request/node_modules/mime-types/Makefile +0 -9
- package/node_modules/request/node_modules/mime-types/README.md +0 -101
- package/node_modules/request/node_modules/mime-types/SOURCES.md +0 -17
- package/node_modules/request/node_modules/mime-types/component.json +0 -16
- package/node_modules/request/node_modules/mime-types/lib/custom.json +0 -27
- package/node_modules/request/node_modules/mime-types/lib/index.js +0 -75
- package/node_modules/request/node_modules/mime-types/lib/mime.json +0 -3317
- package/node_modules/request/node_modules/mime-types/lib/node.json +0 -55
- package/node_modules/request/node_modules/mime-types/package.json +0 -69
- package/node_modules/request/node_modules/node-uuid/.npmignore +0 -2
- package/node_modules/request/node_modules/node-uuid/LICENSE.md +0 -2
- package/node_modules/request/node_modules/node-uuid/README.md +0 -207
- package/node_modules/request/node_modules/node-uuid/benchmark/README.md +0 -53
- package/node_modules/request/node_modules/node-uuid/benchmark/bench.gnu +0 -174
- package/node_modules/request/node_modules/node-uuid/benchmark/bench.sh +0 -34
- package/node_modules/request/node_modules/node-uuid/benchmark/benchmark-native.c +0 -34
- package/node_modules/request/node_modules/node-uuid/benchmark/benchmark.js +0 -84
- package/node_modules/request/node_modules/node-uuid/component.json +0 -18
- package/node_modules/request/node_modules/node-uuid/package.json +0 -54
- package/node_modules/request/node_modules/node-uuid/test/compare_v1.js +0 -63
- package/node_modules/request/node_modules/node-uuid/test/test.html +0 -17
- package/node_modules/request/node_modules/node-uuid/test/test.js +0 -228
- package/node_modules/request/node_modules/node-uuid/uuid.js +0 -245
- package/node_modules/request/node_modules/oauth-sign/LICENSE +0 -55
- package/node_modules/request/node_modules/oauth-sign/README.md +0 -4
- package/node_modules/request/node_modules/oauth-sign/index.js +0 -43
- package/node_modules/request/node_modules/oauth-sign/package.json +0 -49
- package/node_modules/request/node_modules/oauth-sign/test.js +0 -49
- package/node_modules/request/node_modules/qs/.jshintignore +0 -1
- package/node_modules/request/node_modules/qs/.jshintrc +0 -10
- package/node_modules/request/node_modules/qs/.npmignore +0 -18
- package/node_modules/request/node_modules/qs/.travis.yml +0 -4
- package/node_modules/request/node_modules/qs/LICENSE +0 -28
- package/node_modules/request/node_modules/qs/Makefile +0 -8
- package/node_modules/request/node_modules/qs/Readme.md +0 -120
- package/node_modules/request/node_modules/qs/index.js +0 -1
- package/node_modules/request/node_modules/qs/lib/index.js +0 -15
- package/node_modules/request/node_modules/qs/lib/parse.js +0 -151
- package/node_modules/request/node_modules/qs/lib/stringify.js +0 -52
- package/node_modules/request/node_modules/qs/lib/utils.js +0 -131
- package/node_modules/request/node_modules/qs/package.json +0 -61
- package/node_modules/request/node_modules/qs/test/parse.js +0 -236
- package/node_modules/request/node_modules/qs/test/stringify.js +0 -123
- package/node_modules/request/node_modules/stringstream/.npmignore +0 -15
- package/node_modules/request/node_modules/stringstream/.travis.yml +0 -4
- package/node_modules/request/node_modules/stringstream/LICENSE.txt +0 -4
- package/node_modules/request/node_modules/stringstream/README.md +0 -38
- package/node_modules/request/node_modules/stringstream/example.js +0 -27
- package/node_modules/request/node_modules/stringstream/package.json +0 -48
- package/node_modules/request/node_modules/stringstream/stringstream.js +0 -102
- package/node_modules/request/node_modules/tough-cookie/.jshintrc +0 -70
- package/node_modules/request/node_modules/tough-cookie/.npmignore +0 -3
- package/node_modules/request/node_modules/tough-cookie/.travis.yml +0 -8
- package/node_modules/request/node_modules/tough-cookie/LICENSE +0 -78
- package/node_modules/request/node_modules/tough-cookie/README.md +0 -412
- package/node_modules/request/node_modules/tough-cookie/generate-pubsuffix.js +0 -239
- package/node_modules/request/node_modules/tough-cookie/lib/cookie.js +0 -1107
- package/node_modules/request/node_modules/tough-cookie/lib/memstore.js +0 -123
- package/node_modules/request/node_modules/tough-cookie/lib/pubsuffix.js +0 -69
- package/node_modules/request/node_modules/tough-cookie/lib/store.js +0 -37
- package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/LICENSE-MIT.txt +0 -20
- package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/README.md +0 -176
- package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/package.json +0 -87
- package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/punycode.js +0 -528
- package/node_modules/request/node_modules/tough-cookie/package.json +0 -67
- package/node_modules/request/node_modules/tough-cookie/public-suffix.txt +0 -5229
- package/node_modules/request/node_modules/tough-cookie/test.js +0 -1625
- package/node_modules/request/node_modules/tunnel-agent/.jshintrc +0 -5
- package/node_modules/request/node_modules/tunnel-agent/LICENSE +0 -55
- package/node_modules/request/node_modules/tunnel-agent/README.md +0 -4
- package/node_modules/request/node_modules/tunnel-agent/index.js +0 -236
- package/node_modules/request/node_modules/tunnel-agent/package.json +0 -46
- package/node_modules/request/package.json +0 -77
- package/node_modules/request/request.js +0 -1428
- package/test/fixtures/github-response.json +0 -1367
- package/test/index.js +0 -55
@@ -1,296 +0,0 @@
|
|
1
|
-
# Abstract
|
2
|
-
|
3
|
-
This document describes a way to add origin authentication, message integrity,
|
4
|
-
and replay resistance to HTTP REST requests. It is intended to be used over
|
5
|
-
the HTTPS protocol.
|
6
|
-
|
7
|
-
# Copyright Notice
|
8
|
-
|
9
|
-
Copyright (c) 2011 Joyent, Inc. and the persons identified as document authors.
|
10
|
-
All rights reserved.
|
11
|
-
|
12
|
-
Code Components extracted from this document must include MIT License text.
|
13
|
-
|
14
|
-
# Introduction
|
15
|
-
|
16
|
-
This protocol is intended to provide a standard way for clients to sign HTTP
|
17
|
-
requests. RFC2617 (HTTP Authentication) defines Basic and Digest authentication
|
18
|
-
mechanisms, and RFC5246 (TLS 1.2) defines client-auth, both of which are widely
|
19
|
-
employed on the Internet today. However, it is common place that the burdens of
|
20
|
-
PKI prevent web service operators from deploying that methodoloy, and so many
|
21
|
-
fall back to Basic authentication, which has poor security characteristics.
|
22
|
-
|
23
|
-
Additionally, OAuth provides a fully-specified alternative for authorization
|
24
|
-
of web service requests, but is not (always) ideal for machine to machine
|
25
|
-
communication, as the key acquisition steps (generally) imply a fixed
|
26
|
-
infrastructure that may not make sense to a service provider (e.g., symmetric
|
27
|
-
keys).
|
28
|
-
|
29
|
-
Several web service providers have invented their own schemes for signing
|
30
|
-
HTTP requests, but to date, none have been placed in the public domain as a
|
31
|
-
standard. This document serves that purpose. There are no techniques in this
|
32
|
-
proposal that are novel beyond previous art, however, this aims to be a simple
|
33
|
-
mechanism for signing these requests.
|
34
|
-
|
35
|
-
# Signature Authentication Scheme
|
36
|
-
|
37
|
-
The "signature" authentication scheme is based on the model that the client must
|
38
|
-
authenticate itself with a digital signature produced by either a private
|
39
|
-
asymmetric key (e.g., RSA) or a shared symmetric key (e.g., HMAC). The scheme
|
40
|
-
is parameterized enough such that it is not bound to any particular key type or
|
41
|
-
signing algorithm. However, it does explicitly assume that clients can send an
|
42
|
-
HTTP `Date` header.
|
43
|
-
|
44
|
-
## Authorization Header
|
45
|
-
|
46
|
-
The client is expected to send an Authorization header (as defined in RFC 2617)
|
47
|
-
with the following parameterization:
|
48
|
-
|
49
|
-
credentials := "Signature" params
|
50
|
-
params := 1#(keyId | algorithm | [headers] | [ext] | signature)
|
51
|
-
digitalSignature := plain-string
|
52
|
-
|
53
|
-
keyId := "keyId" "=" <"> plain-string <">
|
54
|
-
algorithm := "algorithm" "=" <"> plain-string <">
|
55
|
-
headers := "headers" "=" <"> 1#headers-value <">
|
56
|
-
ext := "ext" "=" <"> plain-string <">
|
57
|
-
signature := "signature" "=" <"> plain-string <">
|
58
|
-
|
59
|
-
headers-value := plain-string
|
60
|
-
plain-string = 1*( %x20-21 / %x23-5B / %x5D-7E )
|
61
|
-
|
62
|
-
### Signature Parameters
|
63
|
-
|
64
|
-
#### keyId
|
65
|
-
|
66
|
-
REQUIRED. The `keyId` field is an opaque string that the server can use to look
|
67
|
-
up the component they need to validate the signature. It could be an SSH key
|
68
|
-
fingerprint, an LDAP DN, etc. Management of keys and assignment of `keyId` is
|
69
|
-
out of scope for this document.
|
70
|
-
|
71
|
-
#### algorithm
|
72
|
-
|
73
|
-
REQUIRED. The `algorithm` parameter is used if the client and server agree on a
|
74
|
-
non-standard digital signature algorithm. The full list of supported signature
|
75
|
-
mechanisms is listed below.
|
76
|
-
|
77
|
-
#### headers
|
78
|
-
|
79
|
-
OPTIONAL. The `headers` parameter is used to specify the list of HTTP headers
|
80
|
-
used to sign the request. If specified, it should be a quoted list of HTTP
|
81
|
-
header names, separated by a single space character. By default, only one
|
82
|
-
HTTP header is signed, which is the `Date` header. Note that the list MUST be
|
83
|
-
specified in the order the values are concatenated together during signing. To
|
84
|
-
include the HTTP request line in the signature calculation, use the special
|
85
|
-
`request-line` value. While this is overloading the definition of `headers` in
|
86
|
-
HTTP linguism, the request-line is defined in RFC 2616, and as the outlier from
|
87
|
-
headers in useful signature calculation, it is deemed simpler to simply use
|
88
|
-
`request-line` than to add a separate parameter for it.
|
89
|
-
|
90
|
-
#### extensions
|
91
|
-
|
92
|
-
OPTIONAL. The `extensions` parameter is used to include additional information
|
93
|
-
which is covered by the request. The content and format of the string is out of
|
94
|
-
scope for this document, and expected to be specified by implementors.
|
95
|
-
|
96
|
-
#### signature
|
97
|
-
|
98
|
-
REQUIRED. The `signature` parameter is a `Base64` encoded digital signature
|
99
|
-
generated by the client. The client uses the `algorithm` and `headers` request
|
100
|
-
parameters to form a canonicalized `signing string`. This `signing string` is
|
101
|
-
then signed with the key associated with `keyId` and the algorithm
|
102
|
-
corresponding to `algorithm`. The `signature` parameter is then set to the
|
103
|
-
`Base64` encoding of the signature.
|
104
|
-
|
105
|
-
### Signing String Composition
|
106
|
-
|
107
|
-
In order to generate the string that is signed with a key, the client MUST take
|
108
|
-
the values of each HTTP header specified by `headers` in the order they appear.
|
109
|
-
|
110
|
-
1. If the header name is not `request-line` then append the lowercased header
|
111
|
-
name followed with an ASCII colon `:` and an ASCII space ` `.
|
112
|
-
2. If the header name is `request-line` then appened the HTTP request line,
|
113
|
-
otherwise append the header value.
|
114
|
-
3. If value is not the last value then append an ASCII newline `\n`. The string
|
115
|
-
MUST NOT include a trailing ASCII newline.
|
116
|
-
|
117
|
-
# Example Requests
|
118
|
-
|
119
|
-
All requests refer to the following request (body ommitted):
|
120
|
-
|
121
|
-
POST /foo HTTP/1.1
|
122
|
-
Host: example.org
|
123
|
-
Date: Tue, 07 Jun 2011 20:51:35 GMT
|
124
|
-
Content-Type: application/json
|
125
|
-
Content-MD5: h0auK8hnYJKmHTLhKtMTkQ==
|
126
|
-
Content-Length: 123
|
127
|
-
|
128
|
-
The "rsa-key-1" keyId refers to a private key known to the client and a public
|
129
|
-
key known to the server. The "hmac-key-1" keyId refers to key known to the
|
130
|
-
client and server.
|
131
|
-
|
132
|
-
## Default parameterization
|
133
|
-
|
134
|
-
The authorization header and signature would be generated as:
|
135
|
-
|
136
|
-
Authorization: Signature keyId="rsa-key-1",algorithm="rsa-sha256",signature="Base64(RSA-SHA256(signing string))"
|
137
|
-
|
138
|
-
The client would compose the signing string as:
|
139
|
-
|
140
|
-
date: Tue, 07 Jun 2011 20:51:35 GMT
|
141
|
-
|
142
|
-
## Header List
|
143
|
-
|
144
|
-
The authorization header and signature would be generated as:
|
145
|
-
|
146
|
-
Authorization: Signature keyId="rsa-key-1",algorithm="rsa-sha256",headers="request-line date content-type content-md5",signature="Base64(RSA-SHA256(signing string))"
|
147
|
-
|
148
|
-
The client would compose the signing string as (`+ "\n"` inserted for
|
149
|
-
readability):
|
150
|
-
|
151
|
-
POST /foo HTTP/1.1 + "\n"
|
152
|
-
date: Tue, 07 Jun 2011 20:51:35 GMT + "\n"
|
153
|
-
content-type: application/json + "\n"
|
154
|
-
content-md5: h0auK8hnYJKmHTLhKtMTkQ==
|
155
|
-
|
156
|
-
## Algorithm
|
157
|
-
|
158
|
-
The authorization header and signature would be generated as:
|
159
|
-
|
160
|
-
Authorization: Signature keyId="hmac-key-1",algorithm="hmac-sha1",signature="Base64(HMAC-SHA1(signing string))"
|
161
|
-
|
162
|
-
The client would compose the signing string as:
|
163
|
-
|
164
|
-
date: Tue, 07 Jun 2011 20:51:35 GMT
|
165
|
-
|
166
|
-
# Signing Algorithms
|
167
|
-
|
168
|
-
Currently supported algorithm names are:
|
169
|
-
|
170
|
-
* rsa-sha1
|
171
|
-
* rsa-sha256
|
172
|
-
* rsa-sha512
|
173
|
-
* dsa-sha1
|
174
|
-
* hmac-sha1
|
175
|
-
* hmac-sha256
|
176
|
-
* hmac-sha512
|
177
|
-
|
178
|
-
# Security Considerations
|
179
|
-
|
180
|
-
## Default Parameters
|
181
|
-
|
182
|
-
Note the default parameterization of the `Signature` scheme is only safe if all
|
183
|
-
requests are carried over a secure transport (i.e., TLS). Sending the default
|
184
|
-
scheme over a non-secure transport will leave the request vulnerable to
|
185
|
-
spoofing, tampering, replay/repudiaton, and integrity violations (if using the
|
186
|
-
STRIDE threat-modeling methodology).
|
187
|
-
|
188
|
-
## Insecure Transports
|
189
|
-
|
190
|
-
If sending the request over plain HTTP, service providers SHOULD require clients
|
191
|
-
to sign ALL HTTP headers, and the `request-line`. Additionally, service
|
192
|
-
providers SHOULD require `Content-MD5` calculations to be performed to ensure
|
193
|
-
against any tampering from clients.
|
194
|
-
|
195
|
-
## Nonces
|
196
|
-
|
197
|
-
Nonces are out of scope for this document simply because many service providers
|
198
|
-
fail to implement them correctly, or do not adopt security specfiications
|
199
|
-
because of the infrastructure complexity. Given the `header` parameterization,
|
200
|
-
a service provider is fully enabled to add nonce semantics into this scheme by
|
201
|
-
using something like an `x-request-nonce` header, and ensuring it is signed
|
202
|
-
with the `Date` header.
|
203
|
-
|
204
|
-
## Clock Skew
|
205
|
-
|
206
|
-
As the default scheme is to sign the `Date` header, service providers SHOULD
|
207
|
-
protect against logged replay attacks by enforcing a clock skew. The server
|
208
|
-
SHOULD be synchronized with NTP, and the recommendation in this specification
|
209
|
-
is to allow 300s of clock skew (in either direction).
|
210
|
-
|
211
|
-
## Required Headers to Sign
|
212
|
-
|
213
|
-
It is out of scope for this document to dictate what headers a service provider
|
214
|
-
will want to enforce, but service providers SHOULD at minimum include the
|
215
|
-
`Date` header.
|
216
|
-
|
217
|
-
# References
|
218
|
-
|
219
|
-
## Normative References
|
220
|
-
|
221
|
-
* [RFC2616] Hypertext Transfer Protocol -- HTTP/1.1
|
222
|
-
* [RFC2617] HTTP Authentication: Basic and Digest Access Authentication
|
223
|
-
* [RFC5246] The Transport Layer Security (TLS) Protocol Version 1.2
|
224
|
-
|
225
|
-
## Informative References
|
226
|
-
|
227
|
-
Name: Mark Cavage (editor)
|
228
|
-
Company: Joyent, Inc.
|
229
|
-
Email: mark.cavage@joyent.com
|
230
|
-
URI: http://www.joyent.com
|
231
|
-
|
232
|
-
# Appendix A - Test Values
|
233
|
-
|
234
|
-
The following test data uses the RSA (2048b) keys, which we will refer
|
235
|
-
to as `keyId=Test` in the following samples:
|
236
|
-
|
237
|
-
-----BEGIN PUBLIC KEY-----
|
238
|
-
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDCFENGw33yGihy92pDjZQhl0C3
|
239
|
-
6rPJj+CvfSC8+q28hxA161QFNUd13wuCTUcq0Qd2qsBe/2hFyc2DCJJg0h1L78+6
|
240
|
-
Z4UMR7EOcpfdUE9Hf3m/hs+FUR45uBJeDK1HSFHD8bHKD6kv8FPGfJTotc+2xjJw
|
241
|
-
oYi+1hqp1fIekaxsyQIDAQAB
|
242
|
-
-----END PUBLIC KEY-----
|
243
|
-
|
244
|
-
-----BEGIN RSA PRIVATE KEY-----
|
245
|
-
MIICXgIBAAKBgQDCFENGw33yGihy92pDjZQhl0C36rPJj+CvfSC8+q28hxA161QF
|
246
|
-
NUd13wuCTUcq0Qd2qsBe/2hFyc2DCJJg0h1L78+6Z4UMR7EOcpfdUE9Hf3m/hs+F
|
247
|
-
UR45uBJeDK1HSFHD8bHKD6kv8FPGfJTotc+2xjJwoYi+1hqp1fIekaxsyQIDAQAB
|
248
|
-
AoGBAJR8ZkCUvx5kzv+utdl7T5MnordT1TvoXXJGXK7ZZ+UuvMNUCdN2QPc4sBiA
|
249
|
-
QWvLw1cSKt5DsKZ8UETpYPy8pPYnnDEz2dDYiaew9+xEpubyeW2oH4Zx71wqBtOK
|
250
|
-
kqwrXa/pzdpiucRRjk6vE6YY7EBBs/g7uanVpGibOVAEsqH1AkEA7DkjVH28WDUg
|
251
|
-
f1nqvfn2Kj6CT7nIcE3jGJsZZ7zlZmBmHFDONMLUrXR/Zm3pR5m0tCmBqa5RK95u
|
252
|
-
412jt1dPIwJBANJT3v8pnkth48bQo/fKel6uEYyboRtA5/uHuHkZ6FQF7OUkGogc
|
253
|
-
mSJluOdc5t6hI1VsLn0QZEjQZMEOWr+wKSMCQQCC4kXJEsHAve77oP6HtG/IiEn7
|
254
|
-
kpyUXRNvFsDE0czpJJBvL/aRFUJxuRK91jhjC68sA7NsKMGg5OXb5I5Jj36xAkEA
|
255
|
-
gIT7aFOYBFwGgQAQkWNKLvySgKbAZRTeLBacpHMuQdl1DfdntvAyqpAZ0lY0RKmW
|
256
|
-
G6aFKaqQfOXKCyWoUiVknQJAXrlgySFci/2ueKlIE1QqIiLSZ8V8OlpFLRnb1pzI
|
257
|
-
7U1yQXnTAEFYM560yJlzUpOb1V4cScGd365tiSMvxLOvTA==
|
258
|
-
-----END RSA PRIVATE KEY-----
|
259
|
-
|
260
|
-
And all examples use this request:
|
261
|
-
|
262
|
-
POST /foo?param=value&pet=dog HTTP/1.1
|
263
|
-
Host: example.com
|
264
|
-
Date: Thu, 05 Jan 2012 21:31:40 GMT
|
265
|
-
Content-Type: application/json
|
266
|
-
Content-MD5: Sd/dVLAcvNLSq16eXua5uQ==
|
267
|
-
Content-Length: 18
|
268
|
-
|
269
|
-
{"hello": "world"}
|
270
|
-
|
271
|
-
### Default
|
272
|
-
|
273
|
-
The string to sign would be:
|
274
|
-
|
275
|
-
date: Thu, 05 Jan 2012 21:31:40 GMT
|
276
|
-
|
277
|
-
The Authorization header would be:
|
278
|
-
|
279
|
-
Authorization: Signature keyId="Test",algorithm="rsa-sha256",signature="JldXnt8W9t643M2Sce10gqCh/+E7QIYLiI+bSjnFBGCti7s+mPPvOjVb72sbd1FjeOUwPTDpKbrQQORrm+xBYfAwCxF3LBSSzORvyJ5nRFCFxfJ3nlQD6Kdxhw8wrVZX5nSem4A/W3C8qH5uhFTRwF4ruRjh+ENHWuovPgO/HGQ="
|
280
|
-
|
281
|
-
### All Headers
|
282
|
-
|
283
|
-
Parameterized to include all headers, the string to sign would be (`+ "\n"`
|
284
|
-
inserted for readability):
|
285
|
-
|
286
|
-
POST /foo?param=value&pet=dog HTTP/1.1 + "\n"
|
287
|
-
host: example.com + "\n"
|
288
|
-
date: Thu, 05 Jan 2012 21:31:40 GMT + "\n"
|
289
|
-
content-type: application/json + "\n"
|
290
|
-
content-md5: Sd/dVLAcvNLSq16eXua5uQ== + "\n"
|
291
|
-
content-length: 18
|
292
|
-
|
293
|
-
The Authorization header would be:
|
294
|
-
|
295
|
-
Authorization: Signature keyId="Test",algorithm="rsa-sha256",headers="request-line host date content-type content-md5 content-length",signature="Gm7W/r+e90REDpWytALMrft4MqZxCmslOTOvwJX17ViEBA5E65QqvWI0vIH3l/vSsGiaMVmuUgzYsJLYMLcm5dGrv1+a+0fCoUdVKPZWHyImQEqpLkopVwqEH67LVECFBqFTAKlQgBn676zrfXQbb+b/VebAsNUtvQMe6cTjnDY="
|
296
|
-
|
@@ -1,25 +0,0 @@
|
|
1
|
-
// Copyright 2011 Joyent, Inc. All rights reserved.
|
2
|
-
|
3
|
-
var parser = require('./parser');
|
4
|
-
var signer = require('./signer');
|
5
|
-
var verify = require('./verify');
|
6
|
-
var util = require('./util');
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
///--- API
|
11
|
-
|
12
|
-
module.exports = {
|
13
|
-
|
14
|
-
parse: parser.parseRequest,
|
15
|
-
parseRequest: parser.parseRequest,
|
16
|
-
|
17
|
-
sign: signer.signRequest,
|
18
|
-
signRequest: signer.signRequest,
|
19
|
-
|
20
|
-
sshKeyToPEM: util.sshKeyToPEM,
|
21
|
-
sshKeyFingerprint: util.fingerprint,
|
22
|
-
|
23
|
-
verify: verify.verifySignature,
|
24
|
-
verifySignature: verify.verifySignature
|
25
|
-
};
|
@@ -1,304 +0,0 @@
|
|
1
|
-
// Copyright 2012 Joyent, Inc. All rights reserved.
|
2
|
-
|
3
|
-
var assert = require('assert-plus');
|
4
|
-
var util = require('util');
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
///--- Globals
|
9
|
-
|
10
|
-
var Algorithms = {
|
11
|
-
'rsa-sha1': true,
|
12
|
-
'rsa-sha256': true,
|
13
|
-
'rsa-sha512': true,
|
14
|
-
'dsa-sha1': true,
|
15
|
-
'hmac-sha1': true,
|
16
|
-
'hmac-sha256': true,
|
17
|
-
'hmac-sha512': true
|
18
|
-
};
|
19
|
-
|
20
|
-
var State = {
|
21
|
-
New: 0,
|
22
|
-
Params: 1
|
23
|
-
};
|
24
|
-
|
25
|
-
var ParamsState = {
|
26
|
-
Name: 0,
|
27
|
-
Quote: 1,
|
28
|
-
Value: 2,
|
29
|
-
Comma: 3
|
30
|
-
};
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
///--- Specific Errors
|
35
|
-
|
36
|
-
function HttpSignatureError(message, caller) {
|
37
|
-
if (Error.captureStackTrace)
|
38
|
-
Error.captureStackTrace(this, caller || HttpSignatureError);
|
39
|
-
|
40
|
-
this.message = message;
|
41
|
-
this.name = caller.name;
|
42
|
-
}
|
43
|
-
util.inherits(HttpSignatureError, Error);
|
44
|
-
|
45
|
-
function ExpiredRequestError(message) {
|
46
|
-
HttpSignatureError.call(this, message, ExpiredRequestError);
|
47
|
-
}
|
48
|
-
util.inherits(ExpiredRequestError, HttpSignatureError);
|
49
|
-
|
50
|
-
|
51
|
-
function InvalidHeaderError(message) {
|
52
|
-
HttpSignatureError.call(this, message, InvalidHeaderError);
|
53
|
-
}
|
54
|
-
util.inherits(InvalidHeaderError, HttpSignatureError);
|
55
|
-
|
56
|
-
|
57
|
-
function InvalidParamsError(message) {
|
58
|
-
HttpSignatureError.call(this, message, InvalidParamsError);
|
59
|
-
}
|
60
|
-
util.inherits(InvalidParamsError, HttpSignatureError);
|
61
|
-
|
62
|
-
|
63
|
-
function MissingHeaderError(message) {
|
64
|
-
HttpSignatureError.call(this, message, MissingHeaderError);
|
65
|
-
}
|
66
|
-
util.inherits(MissingHeaderError, HttpSignatureError);
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
///--- Exported API
|
71
|
-
|
72
|
-
module.exports = {
|
73
|
-
|
74
|
-
/**
|
75
|
-
* Parses the 'Authorization' header out of an http.ServerRequest object.
|
76
|
-
*
|
77
|
-
* Note that this API will fully validate the Authorization header, and throw
|
78
|
-
* on any error. It will not however check the signature, or the keyId format
|
79
|
-
* as those are specific to your environment. You can use the options object
|
80
|
-
* to pass in extra constraints.
|
81
|
-
*
|
82
|
-
* As a response object you can expect this:
|
83
|
-
*
|
84
|
-
* {
|
85
|
-
* "scheme": "Signature",
|
86
|
-
* "params": {
|
87
|
-
* "keyId": "foo",
|
88
|
-
* "algorithm": "rsa-sha256",
|
89
|
-
* "headers": [
|
90
|
-
* "date" or "x-date",
|
91
|
-
* "content-md5"
|
92
|
-
* ],
|
93
|
-
* "signature": "base64"
|
94
|
-
* },
|
95
|
-
* "signingString": "ready to be passed to crypto.verify()"
|
96
|
-
* }
|
97
|
-
*
|
98
|
-
* @param {Object} request an http.ServerRequest.
|
99
|
-
* @param {Object} options an optional options object with:
|
100
|
-
* - clockSkew: allowed clock skew in seconds (default 300).
|
101
|
-
* - headers: required header names (def: date or x-date)
|
102
|
-
* - algorithms: algorithms to support (default: all).
|
103
|
-
* @return {Object} parsed out object (see above).
|
104
|
-
* @throws {TypeError} on invalid input.
|
105
|
-
* @throws {InvalidHeaderError} on an invalid Authorization header error.
|
106
|
-
* @throws {InvalidParamsError} if the params in the scheme are invalid.
|
107
|
-
* @throws {MissingHeaderError} if the params indicate a header not present,
|
108
|
-
* either in the request headers from the params,
|
109
|
-
* or not in the params from a required header
|
110
|
-
* in options.
|
111
|
-
* @throws {ExpiredRequestError} if the value of date or x-date exceeds skew.
|
112
|
-
*/
|
113
|
-
parseRequest: function parseRequest(request, options) {
|
114
|
-
assert.object(request, 'request');
|
115
|
-
assert.object(request.headers, 'request.headers');
|
116
|
-
if (options === undefined) {
|
117
|
-
options = {};
|
118
|
-
}
|
119
|
-
if (options.headers === undefined) {
|
120
|
-
options.headers = [request.headers['x-date'] ? 'x-date' : 'date'];
|
121
|
-
}
|
122
|
-
assert.object(options, 'options');
|
123
|
-
assert.arrayOfString(options.headers, 'options.headers');
|
124
|
-
assert.optionalNumber(options.clockSkew, 'options.clockSkew');
|
125
|
-
|
126
|
-
if (!request.headers.authorization)
|
127
|
-
throw new MissingHeaderError('no authorization header present in ' +
|
128
|
-
'the request');
|
129
|
-
|
130
|
-
options.clockSkew = options.clockSkew || 300;
|
131
|
-
|
132
|
-
|
133
|
-
var i = 0;
|
134
|
-
var state = State.New;
|
135
|
-
var substate = ParamsState.Name;
|
136
|
-
var tmpName = '';
|
137
|
-
var tmpValue = '';
|
138
|
-
|
139
|
-
var parsed = {
|
140
|
-
scheme: '',
|
141
|
-
params: {},
|
142
|
-
signingString: '',
|
143
|
-
|
144
|
-
get algorithm() {
|
145
|
-
return this.params.algorithm.toUpperCase();
|
146
|
-
},
|
147
|
-
|
148
|
-
get keyId() {
|
149
|
-
return this.params.keyId;
|
150
|
-
}
|
151
|
-
|
152
|
-
};
|
153
|
-
|
154
|
-
var authz = request.headers.authorization;
|
155
|
-
for (i = 0; i < authz.length; i++) {
|
156
|
-
var c = authz.charAt(i);
|
157
|
-
|
158
|
-
switch (Number(state)) {
|
159
|
-
|
160
|
-
case State.New:
|
161
|
-
if (c !== ' ') parsed.scheme += c;
|
162
|
-
else state = State.Params;
|
163
|
-
break;
|
164
|
-
|
165
|
-
case State.Params:
|
166
|
-
switch (Number(substate)) {
|
167
|
-
|
168
|
-
case ParamsState.Name:
|
169
|
-
var code = c.charCodeAt(0);
|
170
|
-
// restricted name of A-Z / a-z
|
171
|
-
if ((code >= 0x41 && code <= 0x5a) || // A-Z
|
172
|
-
(code >= 0x61 && code <= 0x7a)) { // a-z
|
173
|
-
tmpName += c;
|
174
|
-
} else if (c === '=') {
|
175
|
-
if (tmpName.length === 0)
|
176
|
-
throw new InvalidHeaderError('bad param format');
|
177
|
-
substate = ParamsState.Quote;
|
178
|
-
} else {
|
179
|
-
throw new InvalidHeaderError('bad param format');
|
180
|
-
}
|
181
|
-
break;
|
182
|
-
|
183
|
-
case ParamsState.Quote:
|
184
|
-
if (c === '"') {
|
185
|
-
tmpValue = '';
|
186
|
-
substate = ParamsState.Value;
|
187
|
-
} else {
|
188
|
-
throw new InvalidHeaderError('bad param format');
|
189
|
-
}
|
190
|
-
break;
|
191
|
-
|
192
|
-
case ParamsState.Value:
|
193
|
-
if (c === '"') {
|
194
|
-
parsed.params[tmpName] = tmpValue;
|
195
|
-
substate = ParamsState.Comma;
|
196
|
-
} else {
|
197
|
-
tmpValue += c;
|
198
|
-
}
|
199
|
-
break;
|
200
|
-
|
201
|
-
case ParamsState.Comma:
|
202
|
-
if (c === ',') {
|
203
|
-
tmpName = '';
|
204
|
-
substate = ParamsState.Name;
|
205
|
-
} else {
|
206
|
-
throw new InvalidHeaderError('bad param format');
|
207
|
-
}
|
208
|
-
break;
|
209
|
-
|
210
|
-
default:
|
211
|
-
throw new Error('Invalid substate');
|
212
|
-
}
|
213
|
-
break;
|
214
|
-
|
215
|
-
default:
|
216
|
-
throw new Error('Invalid substate');
|
217
|
-
}
|
218
|
-
|
219
|
-
}
|
220
|
-
|
221
|
-
if (!parsed.params.headers || parsed.params.headers === '') {
|
222
|
-
if (request.headers['x-date']) {
|
223
|
-
parsed.params.headers = ['x-date'];
|
224
|
-
} else {
|
225
|
-
parsed.params.headers = ['date'];
|
226
|
-
}
|
227
|
-
} else {
|
228
|
-
parsed.params.headers = parsed.params.headers.split(' ');
|
229
|
-
}
|
230
|
-
|
231
|
-
// Minimally validate the parsed object
|
232
|
-
if (!parsed.scheme || parsed.scheme !== 'Signature')
|
233
|
-
throw new InvalidHeaderError('scheme was not "Signature"');
|
234
|
-
|
235
|
-
if (!parsed.params.keyId)
|
236
|
-
throw new InvalidHeaderError('keyId was not specified');
|
237
|
-
|
238
|
-
if (!parsed.params.algorithm)
|
239
|
-
throw new InvalidHeaderError('algorithm was not specified');
|
240
|
-
|
241
|
-
if (!parsed.params.signature)
|
242
|
-
throw new InvalidHeaderError('signature was not specified');
|
243
|
-
|
244
|
-
// Check the algorithm against the official list
|
245
|
-
parsed.params.algorithm = parsed.params.algorithm.toLowerCase();
|
246
|
-
if (!Algorithms[parsed.params.algorithm])
|
247
|
-
throw new InvalidParamsError(parsed.params.algorithm +
|
248
|
-
' is not supported');
|
249
|
-
|
250
|
-
// Build the signingString
|
251
|
-
for (i = 0; i < parsed.params.headers.length; i++) {
|
252
|
-
var h = parsed.params.headers[i].toLowerCase();
|
253
|
-
parsed.params.headers[i] = h;
|
254
|
-
|
255
|
-
if (h !== 'request-line') {
|
256
|
-
var value = request.headers[h];
|
257
|
-
if (!value)
|
258
|
-
throw new MissingHeaderError(h + ' was not in the request');
|
259
|
-
parsed.signingString += h + ': ' + value;
|
260
|
-
} else {
|
261
|
-
parsed.signingString +=
|
262
|
-
request.method + ' ' + request.url + ' HTTP/' + request.httpVersion;
|
263
|
-
}
|
264
|
-
|
265
|
-
if ((i + 1) < parsed.params.headers.length)
|
266
|
-
parsed.signingString += '\n';
|
267
|
-
}
|
268
|
-
|
269
|
-
// Check against the constraints
|
270
|
-
var date;
|
271
|
-
if (request.headers.date || request.headers['x-date']) {
|
272
|
-
if (request.headers['x-date']) {
|
273
|
-
date = new Date(request.headers['x-date']);
|
274
|
-
} else {
|
275
|
-
date = new Date(request.headers.date);
|
276
|
-
}
|
277
|
-
var now = new Date();
|
278
|
-
var skew = Math.abs(now.getTime() - date.getTime());
|
279
|
-
|
280
|
-
if (skew > options.clockSkew * 1000) {
|
281
|
-
throw new ExpiredRequestError('clock skew of ' +
|
282
|
-
(skew / 1000) +
|
283
|
-
's was greater than ' +
|
284
|
-
options.clockSkew + 's');
|
285
|
-
}
|
286
|
-
}
|
287
|
-
|
288
|
-
options.headers.forEach(function (hdr) {
|
289
|
-
// Remember that we already checked any headers in the params
|
290
|
-
// were in the request, so if this passes we're good.
|
291
|
-
if (parsed.params.headers.indexOf(hdr) < 0)
|
292
|
-
throw new MissingHeaderError(hdr + ' was not a signed header');
|
293
|
-
});
|
294
|
-
|
295
|
-
if (options.algorithms) {
|
296
|
-
if (options.algorithms.indexOf(parsed.params.algorithm) === -1)
|
297
|
-
throw new InvalidParamsError(parsed.params.algorithm +
|
298
|
-
' is not a supported algorithm');
|
299
|
-
}
|
300
|
-
|
301
|
-
return parsed;
|
302
|
-
}
|
303
|
-
|
304
|
-
};
|