ai 1.1.0 → 2.0.1
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-GT4HKF2X.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,78 +0,0 @@
|
|
1
|
-
// Load modules
|
2
|
-
|
3
|
-
var Http = require('http');
|
4
|
-
var Request = require('request');
|
5
|
-
var Hawk = require('../lib');
|
6
|
-
|
7
|
-
|
8
|
-
// Declare internals
|
9
|
-
|
10
|
-
var internals = {
|
11
|
-
credentials: {
|
12
|
-
dh37fgj492je: {
|
13
|
-
id: 'dh37fgj492je', // Required by Hawk.client.header
|
14
|
-
key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn',
|
15
|
-
algorithm: 'sha256',
|
16
|
-
user: 'Steve'
|
17
|
-
}
|
18
|
-
}
|
19
|
-
};
|
20
|
-
|
21
|
-
|
22
|
-
// Credentials lookup function
|
23
|
-
|
24
|
-
var credentialsFunc = function (id, callback) {
|
25
|
-
|
26
|
-
return callback(null, internals.credentials[id]);
|
27
|
-
};
|
28
|
-
|
29
|
-
|
30
|
-
// Create HTTP server
|
31
|
-
|
32
|
-
var handler = function (req, res) {
|
33
|
-
|
34
|
-
Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) {
|
35
|
-
|
36
|
-
var payload = (!err ? 'Hello ' + credentials.user + ' ' + artifacts.ext : 'Shoosh!');
|
37
|
-
var headers = {
|
38
|
-
'Content-Type': 'text/plain',
|
39
|
-
'Server-Authorization': Hawk.server.header(credentials, artifacts, { payload: payload, contentType: 'text/plain' })
|
40
|
-
};
|
41
|
-
|
42
|
-
res.writeHead(!err ? 200 : 401, headers);
|
43
|
-
res.end(payload);
|
44
|
-
});
|
45
|
-
};
|
46
|
-
|
47
|
-
Http.createServer(handler).listen(8000, '127.0.0.1');
|
48
|
-
|
49
|
-
|
50
|
-
// Send unauthenticated request
|
51
|
-
|
52
|
-
Request('http://127.0.0.1:8000/resource/1?b=1&a=2', function (error, response, body) {
|
53
|
-
|
54
|
-
console.log(response.statusCode + ': ' + body);
|
55
|
-
});
|
56
|
-
|
57
|
-
|
58
|
-
// Send authenticated request
|
59
|
-
|
60
|
-
credentialsFunc('dh37fgj492je', function (err, credentials) {
|
61
|
-
|
62
|
-
var header = Hawk.client.header('http://127.0.0.1:8000/resource/1?b=1&a=2', 'GET', { credentials: credentials, ext: 'and welcome!' });
|
63
|
-
var options = {
|
64
|
-
uri: 'http://127.0.0.1:8000/resource/1?b=1&a=2',
|
65
|
-
method: 'GET',
|
66
|
-
headers: {
|
67
|
-
authorization: header.field
|
68
|
-
}
|
69
|
-
};
|
70
|
-
|
71
|
-
Request(options, function (error, response, body) {
|
72
|
-
|
73
|
-
var isValid = Hawk.client.authenticate(response, credentials, header.artifacts, { payload: body });
|
74
|
-
console.log(response.statusCode + ': ' + body + (isValid ? ' (valid)' : ' (invalid)'));
|
75
|
-
process.exit(0);
|
76
|
-
});
|
77
|
-
});
|
78
|
-
|
Binary file
|
Binary file
|
@@ -1 +0,0 @@
|
|
1
|
-
module.exports = require('./lib');
|
@@ -1,507 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
HTTP Hawk Authentication Scheme
|
3
|
-
Copyright (c) 2012-2013, Eran Hammer <eran@hueniverse.com>
|
4
|
-
MIT Licensed
|
5
|
-
*/
|
6
|
-
|
7
|
-
|
8
|
-
// Declare namespace
|
9
|
-
|
10
|
-
var hawk = {};
|
11
|
-
|
12
|
-
|
13
|
-
// Export if used as a module
|
14
|
-
|
15
|
-
if (typeof module !== "undefined" && module.exports) {
|
16
|
-
module.exports = hawk;
|
17
|
-
}
|
18
|
-
|
19
|
-
hawk.client = {
|
20
|
-
|
21
|
-
// Generate an Authorization header for a given request
|
22
|
-
|
23
|
-
/*
|
24
|
-
uri: 'http://example.com/resource?a=b'
|
25
|
-
method: HTTP verb (e.g. 'GET', 'POST')
|
26
|
-
options: {
|
27
|
-
|
28
|
-
// Required
|
29
|
-
|
30
|
-
credentials: {
|
31
|
-
id: 'dh37fgj492je',
|
32
|
-
key: 'aoijedoaijsdlaksjdl',
|
33
|
-
algorithm: 'sha256' // 'sha1', 'sha256'
|
34
|
-
},
|
35
|
-
|
36
|
-
// Optional
|
37
|
-
|
38
|
-
ext: 'application-specific', // Application specific data sent via the ext attribute
|
39
|
-
timestamp: Date.now() / 1000, // A pre-calculated timestamp in seconds
|
40
|
-
nonce: '2334f34f', // A pre-generated nonce
|
41
|
-
localtimeOffsetMsec: 400, // Time offset to sync with server time (ignored if timestamp provided)
|
42
|
-
payload: '{"some":"payload"}', // UTF-8 encoded string for body hash generation (ignored if hash provided)
|
43
|
-
contentType: 'application/json', // Payload content-type (ignored if hash provided)
|
44
|
-
hash: 'U4MKKSmiVxk37JCCrAVIjV=', // Pre-calculated payload hash
|
45
|
-
app: '24s23423f34dx', // Oz application id
|
46
|
-
dlg: '234sz34tww3sd' // Oz delegated-by application id
|
47
|
-
}
|
48
|
-
*/
|
49
|
-
|
50
|
-
header: function (uri, method, options) {
|
51
|
-
|
52
|
-
var result = {
|
53
|
-
field: '',
|
54
|
-
artifacts: {}
|
55
|
-
};
|
56
|
-
|
57
|
-
// Validate inputs
|
58
|
-
|
59
|
-
if (!uri || (typeof uri !== 'string' && typeof uri !== 'object') ||
|
60
|
-
!method || typeof method !== 'string' ||
|
61
|
-
!options || typeof options !== 'object') {
|
62
|
-
|
63
|
-
result.err = 'Invalid argument type';
|
64
|
-
return result;
|
65
|
-
}
|
66
|
-
|
67
|
-
// Application time
|
68
|
-
|
69
|
-
var timestamp = options.timestamp || Math.floor((hawk.utils.now() + (options.localtimeOffsetMsec || 0)) / 1000)
|
70
|
-
|
71
|
-
// Validate credentials
|
72
|
-
|
73
|
-
var credentials = options.credentials;
|
74
|
-
if (!credentials ||
|
75
|
-
!credentials.id ||
|
76
|
-
!credentials.key ||
|
77
|
-
!credentials.algorithm) {
|
78
|
-
|
79
|
-
result.err = 'Invalid credential object';
|
80
|
-
return result;
|
81
|
-
}
|
82
|
-
|
83
|
-
if (hawk.crypto.algorithms.indexOf(credentials.algorithm) === -1) {
|
84
|
-
result.err = 'Unknown algorithm';
|
85
|
-
return result;
|
86
|
-
}
|
87
|
-
|
88
|
-
// Parse URI
|
89
|
-
|
90
|
-
if (typeof uri === 'string') {
|
91
|
-
uri = hawk.utils.parseUri(uri);
|
92
|
-
}
|
93
|
-
|
94
|
-
// Calculate signature
|
95
|
-
|
96
|
-
var artifacts = {
|
97
|
-
ts: timestamp,
|
98
|
-
nonce: options.nonce || hawk.utils.randomString(6),
|
99
|
-
method: method,
|
100
|
-
resource: uri.relative,
|
101
|
-
host: uri.hostname,
|
102
|
-
port: uri.port,
|
103
|
-
hash: options.hash,
|
104
|
-
ext: options.ext,
|
105
|
-
app: options.app,
|
106
|
-
dlg: options.dlg
|
107
|
-
};
|
108
|
-
|
109
|
-
result.artifacts = artifacts;
|
110
|
-
|
111
|
-
// Calculate payload hash
|
112
|
-
|
113
|
-
if (!artifacts.hash &&
|
114
|
-
options.hasOwnProperty('payload')) {
|
115
|
-
|
116
|
-
artifacts.hash = hawk.crypto.calculatePayloadHash(options.payload, credentials.algorithm, options.contentType);
|
117
|
-
}
|
118
|
-
|
119
|
-
var mac = hawk.crypto.calculateMac('header', credentials, artifacts);
|
120
|
-
|
121
|
-
// Construct header
|
122
|
-
|
123
|
-
var hasExt = artifacts.ext !== null && artifacts.ext !== undefined && artifacts.ext !== ''; // Other falsey values allowed
|
124
|
-
var header = 'Hawk id="' + credentials.id +
|
125
|
-
'", ts="' + artifacts.ts +
|
126
|
-
'", nonce="' + artifacts.nonce +
|
127
|
-
(artifacts.hash ? '", hash="' + artifacts.hash : '') +
|
128
|
-
(hasExt ? '", ext="' + hawk.utils.escapeHeaderAttribute(artifacts.ext) : '') +
|
129
|
-
'", mac="' + mac + '"';
|
130
|
-
|
131
|
-
if (artifacts.app) {
|
132
|
-
header += ', app="' + artifacts.app +
|
133
|
-
(artifacts.dlg ? '", dlg="' + artifacts.dlg : '') + '"';
|
134
|
-
}
|
135
|
-
|
136
|
-
result.field = header;
|
137
|
-
|
138
|
-
return result;
|
139
|
-
},
|
140
|
-
|
141
|
-
|
142
|
-
// Validate server response
|
143
|
-
|
144
|
-
/*
|
145
|
-
request: object created via 'new XMLHttpRequest()' after response received
|
146
|
-
artifacts: object recieved from header().artifacts
|
147
|
-
options: {
|
148
|
-
payload: optional payload received
|
149
|
-
required: specifies if a Server-Authorization header is required. Defaults to 'false'
|
150
|
-
}
|
151
|
-
*/
|
152
|
-
|
153
|
-
authenticate: function (request, credentials, artifacts, options) {
|
154
|
-
|
155
|
-
options = options || {};
|
156
|
-
|
157
|
-
if (request.getResponseHeader('www-authenticate')) {
|
158
|
-
|
159
|
-
// Parse HTTP WWW-Authenticate header
|
160
|
-
|
161
|
-
var attributes = hawk.utils.parseAuthorizationHeader(request.getResponseHeader('www-authenticate'), ['ts', 'tsm', 'error']);
|
162
|
-
if (!attributes) {
|
163
|
-
return false;
|
164
|
-
}
|
165
|
-
|
166
|
-
if (attributes.ts) {
|
167
|
-
var tsm = hawk.crypto.calculateTsMac(attributes.ts, credentials);
|
168
|
-
if (tsm !== attributes.tsm) {
|
169
|
-
return false;
|
170
|
-
}
|
171
|
-
|
172
|
-
hawk.utils.setNtpOffset(attributes.ts - Math.floor(Date.now() / 1000)); // Keep offset at 1 second precision
|
173
|
-
}
|
174
|
-
}
|
175
|
-
|
176
|
-
// Parse HTTP Server-Authorization header
|
177
|
-
|
178
|
-
if (!request.getResponseHeader('server-authorization') &&
|
179
|
-
!options.required) {
|
180
|
-
|
181
|
-
return true;
|
182
|
-
}
|
183
|
-
|
184
|
-
var attributes = hawk.utils.parseAuthorizationHeader(request.getResponseHeader('server-authorization'), ['mac', 'ext', 'hash']);
|
185
|
-
if (!attributes) {
|
186
|
-
return false;
|
187
|
-
}
|
188
|
-
|
189
|
-
var modArtifacts = {
|
190
|
-
ts: artifacts.ts,
|
191
|
-
nonce: artifacts.nonce,
|
192
|
-
method: artifacts.method,
|
193
|
-
resource: artifacts.resource,
|
194
|
-
host: artifacts.host,
|
195
|
-
port: artifacts.port,
|
196
|
-
hash: attributes.hash,
|
197
|
-
ext: attributes.ext,
|
198
|
-
app: artifacts.app,
|
199
|
-
dlg: artifacts.dlg
|
200
|
-
};
|
201
|
-
|
202
|
-
var mac = hawk.crypto.calculateMac('response', credentials, modArtifacts);
|
203
|
-
if (mac !== attributes.mac) {
|
204
|
-
return false;
|
205
|
-
}
|
206
|
-
|
207
|
-
if (!options.hasOwnProperty('payload')) {
|
208
|
-
return true;
|
209
|
-
}
|
210
|
-
|
211
|
-
if (!attributes.hash) {
|
212
|
-
return false;
|
213
|
-
}
|
214
|
-
|
215
|
-
var calculatedHash = hawk.crypto.calculatePayloadHash(options.payload, credentials.algorithm, request.getResponseHeader('content-type'));
|
216
|
-
return (calculatedHash === attributes.hash);
|
217
|
-
},
|
218
|
-
|
219
|
-
message: function (host, port, message, options) {
|
220
|
-
|
221
|
-
// Validate inputs
|
222
|
-
|
223
|
-
if (!host || typeof host !== 'string' ||
|
224
|
-
!port || typeof port !== 'number' ||
|
225
|
-
message === null || message === undefined || typeof message !== 'string' ||
|
226
|
-
!options || typeof options !== 'object') {
|
227
|
-
|
228
|
-
return null;
|
229
|
-
}
|
230
|
-
|
231
|
-
// Application time
|
232
|
-
|
233
|
-
var timestamp = options.timestamp || Math.floor((hawk.utils.now() + (options.localtimeOffsetMsec || 0)) / 1000)
|
234
|
-
|
235
|
-
// Validate credentials
|
236
|
-
|
237
|
-
var credentials = options.credentials;
|
238
|
-
if (!credentials ||
|
239
|
-
!credentials.id ||
|
240
|
-
!credentials.key ||
|
241
|
-
!credentials.algorithm) {
|
242
|
-
|
243
|
-
// Invalid credential object
|
244
|
-
return null;
|
245
|
-
}
|
246
|
-
|
247
|
-
if (hawk.crypto.algorithms.indexOf(credentials.algorithm) === -1) {
|
248
|
-
return null;
|
249
|
-
}
|
250
|
-
|
251
|
-
// Calculate signature
|
252
|
-
|
253
|
-
var artifacts = {
|
254
|
-
ts: timestamp,
|
255
|
-
nonce: options.nonce || hawk.utils.randomString(6),
|
256
|
-
host: host,
|
257
|
-
port: port,
|
258
|
-
hash: hawk.crypto.calculatePayloadHash(message, credentials.algorithm)
|
259
|
-
};
|
260
|
-
|
261
|
-
// Construct authorization
|
262
|
-
|
263
|
-
var result = {
|
264
|
-
id: credentials.id,
|
265
|
-
ts: artifacts.ts,
|
266
|
-
nonce: artifacts.nonce,
|
267
|
-
hash: artifacts.hash,
|
268
|
-
mac: hawk.crypto.calculateMac('message', credentials, artifacts)
|
269
|
-
};
|
270
|
-
|
271
|
-
return result;
|
272
|
-
},
|
273
|
-
|
274
|
-
authenticateTimestamp: function (message, credentials, updateClock) { // updateClock defaults to true
|
275
|
-
|
276
|
-
var tsm = hawk.crypto.calculateTsMac(message.ts, credentials);
|
277
|
-
if (tsm !== message.tsm) {
|
278
|
-
return false;
|
279
|
-
}
|
280
|
-
|
281
|
-
if (updateClock !== false) {
|
282
|
-
hawk.utils.setNtpOffset(message.ts - Math.floor(Date.now() / 1000)); // Keep offset at 1 second precision
|
283
|
-
}
|
284
|
-
|
285
|
-
return true;
|
286
|
-
}
|
287
|
-
};
|
288
|
-
|
289
|
-
|
290
|
-
hawk.crypto = {
|
291
|
-
|
292
|
-
headerVersion: '1',
|
293
|
-
|
294
|
-
algorithms: ['sha1', 'sha256'],
|
295
|
-
|
296
|
-
calculateMac: function (type, credentials, options) {
|
297
|
-
|
298
|
-
var normalized = hawk.crypto.generateNormalizedString(type, options);
|
299
|
-
|
300
|
-
var hmac = CryptoJS['Hmac' + credentials.algorithm.toUpperCase()](normalized, credentials.key);
|
301
|
-
return hmac.toString(CryptoJS.enc.Base64);
|
302
|
-
},
|
303
|
-
|
304
|
-
generateNormalizedString: function (type, options) {
|
305
|
-
|
306
|
-
var normalized = 'hawk.' + hawk.crypto.headerVersion + '.' + type + '\n' +
|
307
|
-
options.ts + '\n' +
|
308
|
-
options.nonce + '\n' +
|
309
|
-
(options.method || '').toUpperCase() + '\n' +
|
310
|
-
(options.resource || '') + '\n' +
|
311
|
-
options.host.toLowerCase() + '\n' +
|
312
|
-
options.port + '\n' +
|
313
|
-
(options.hash || '') + '\n';
|
314
|
-
|
315
|
-
if (options.ext) {
|
316
|
-
normalized += options.ext.replace('\\', '\\\\').replace('\n', '\\n');
|
317
|
-
}
|
318
|
-
|
319
|
-
normalized += '\n';
|
320
|
-
|
321
|
-
if (options.app) {
|
322
|
-
normalized += options.app + '\n' +
|
323
|
-
(options.dlg || '') + '\n';
|
324
|
-
}
|
325
|
-
|
326
|
-
return normalized;
|
327
|
-
},
|
328
|
-
|
329
|
-
calculatePayloadHash: function (payload, algorithm, contentType) {
|
330
|
-
|
331
|
-
var hash = CryptoJS.algo[algorithm.toUpperCase()].create();
|
332
|
-
hash.update('hawk.' + hawk.crypto.headerVersion + '.payload\n');
|
333
|
-
hash.update(hawk.utils.parseContentType(contentType) + '\n');
|
334
|
-
hash.update(payload || '');
|
335
|
-
hash.update('\n');
|
336
|
-
return hash.finalize().toString(CryptoJS.enc.Base64);
|
337
|
-
},
|
338
|
-
|
339
|
-
calculateTsMac: function (ts, credentials) {
|
340
|
-
|
341
|
-
var hash = CryptoJS['Hmac' + credentials.algorithm.toUpperCase()]('hawk.' + hawk.crypto.headerVersion + '.ts\n' + ts + '\n', credentials.key);
|
342
|
-
return hash.toString(CryptoJS.enc.Base64);
|
343
|
-
}
|
344
|
-
};
|
345
|
-
|
346
|
-
|
347
|
-
hawk.utils = {
|
348
|
-
|
349
|
-
storage: { // localStorage compatible interface
|
350
|
-
_cache: {},
|
351
|
-
setItem: function (key, value) {
|
352
|
-
|
353
|
-
hawk.utils.storage._cache[key] = value;
|
354
|
-
},
|
355
|
-
getItem: function (key) {
|
356
|
-
|
357
|
-
return hawk.utils.storage._cache[key];
|
358
|
-
}
|
359
|
-
},
|
360
|
-
|
361
|
-
setStorage: function (storage) {
|
362
|
-
|
363
|
-
var ntpOffset = hawk.utils.getNtpOffset() || 0;
|
364
|
-
hawk.utils.storage = storage;
|
365
|
-
hawk.utils.setNtpOffset(ntpOffset);
|
366
|
-
},
|
367
|
-
|
368
|
-
setNtpOffset: function (offset) {
|
369
|
-
|
370
|
-
try {
|
371
|
-
hawk.utils.storage.setItem('hawk_ntp_offset', offset);
|
372
|
-
}
|
373
|
-
catch (err) {
|
374
|
-
console.error('[hawk] could not write to storage.');
|
375
|
-
console.error(err);
|
376
|
-
}
|
377
|
-
},
|
378
|
-
|
379
|
-
getNtpOffset: function () {
|
380
|
-
|
381
|
-
return parseInt(hawk.utils.storage.getItem('hawk_ntp_offset') || '0', 10);
|
382
|
-
},
|
383
|
-
|
384
|
-
now: function () {
|
385
|
-
|
386
|
-
return Date.now() + hawk.utils.getNtpOffset();
|
387
|
-
},
|
388
|
-
|
389
|
-
escapeHeaderAttribute: function (attribute) {
|
390
|
-
|
391
|
-
return attribute.replace(/\\/g, '\\\\').replace(/\"/g, '\\"');
|
392
|
-
},
|
393
|
-
|
394
|
-
parseContentType: function (header) {
|
395
|
-
|
396
|
-
if (!header) {
|
397
|
-
return '';
|
398
|
-
}
|
399
|
-
|
400
|
-
return header.split(';')[0].trim().toLowerCase();
|
401
|
-
},
|
402
|
-
|
403
|
-
parseAuthorizationHeader: function (header, keys) {
|
404
|
-
|
405
|
-
if (!header) {
|
406
|
-
return null;
|
407
|
-
}
|
408
|
-
|
409
|
-
var headerParts = header.match(/^(\w+)(?:\s+(.*))?$/); // Header: scheme[ something]
|
410
|
-
if (!headerParts) {
|
411
|
-
return null;
|
412
|
-
}
|
413
|
-
|
414
|
-
var scheme = headerParts[1];
|
415
|
-
if (scheme.toLowerCase() !== 'hawk') {
|
416
|
-
return null;
|
417
|
-
}
|
418
|
-
|
419
|
-
var attributesString = headerParts[2];
|
420
|
-
if (!attributesString) {
|
421
|
-
return null;
|
422
|
-
}
|
423
|
-
|
424
|
-
var attributes = {};
|
425
|
-
var verify = attributesString.replace(/(\w+)="([^"\\]*)"\s*(?:,\s*|$)/g, function ($0, $1, $2) {
|
426
|
-
|
427
|
-
// Check valid attribute names
|
428
|
-
|
429
|
-
if (keys.indexOf($1) === -1) {
|
430
|
-
return;
|
431
|
-
}
|
432
|
-
|
433
|
-
// Allowed attribute value characters: !#$%&'()*+,-./:;<=>?@[]^_`{|}~ and space, a-z, A-Z, 0-9
|
434
|
-
|
435
|
-
if ($2.match(/^[ \w\!#\$%&'\(\)\*\+,\-\.\/\:;<\=>\?@\[\]\^`\{\|\}~]+$/) === null) {
|
436
|
-
return;
|
437
|
-
}
|
438
|
-
|
439
|
-
// Check for duplicates
|
440
|
-
|
441
|
-
if (attributes.hasOwnProperty($1)) {
|
442
|
-
return;
|
443
|
-
}
|
444
|
-
|
445
|
-
attributes[$1] = $2;
|
446
|
-
return '';
|
447
|
-
});
|
448
|
-
|
449
|
-
if (verify !== '') {
|
450
|
-
return null;
|
451
|
-
}
|
452
|
-
|
453
|
-
return attributes;
|
454
|
-
},
|
455
|
-
|
456
|
-
randomString: function (size) {
|
457
|
-
|
458
|
-
var randomSource = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
459
|
-
var len = randomSource.length;
|
460
|
-
|
461
|
-
var result = [];
|
462
|
-
for (var i = 0; i < size; ++i) {
|
463
|
-
result[i] = randomSource[Math.floor(Math.random() * len)];
|
464
|
-
}
|
465
|
-
|
466
|
-
return result.join('');
|
467
|
-
},
|
468
|
-
|
469
|
-
parseUri: function (input) {
|
470
|
-
|
471
|
-
// Based on: parseURI 1.2.2
|
472
|
-
// http://blog.stevenlevithan.com/archives/parseuri
|
473
|
-
// (c) Steven Levithan <stevenlevithan.com>
|
474
|
-
// MIT License
|
475
|
-
|
476
|
-
var keys = ['source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'hostname', 'port', 'resource', 'relative', 'pathname', 'directory', 'file', 'query', 'fragment'];
|
477
|
-
|
478
|
-
var uriRegex = /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?(((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?)(?:#(.*))?)/;
|
479
|
-
var uriByNumber = uriRegex.exec(input);
|
480
|
-
var uri = {};
|
481
|
-
|
482
|
-
var i = 15;
|
483
|
-
while (i--) {
|
484
|
-
uri[keys[i]] = uriByNumber[i] || '';
|
485
|
-
}
|
486
|
-
|
487
|
-
if (uri.port === null ||
|
488
|
-
uri.port === '') {
|
489
|
-
|
490
|
-
uri.port = (uri.protocol.toLowerCase() === 'http' ? '80' : (uri.protocol.toLowerCase() === 'https' ? '443' : ''));
|
491
|
-
}
|
492
|
-
|
493
|
-
return uri;
|
494
|
-
}
|
495
|
-
};
|
496
|
-
|
497
|
-
|
498
|
-
// Based on: Crypto-JS v3.1.2
|
499
|
-
// Copyright (c) 2009-2013, Jeff Mott. All rights reserved.
|
500
|
-
// http://code.google.com/p/crypto-js/
|
501
|
-
// http://code.google.com/p/crypto-js/wiki/License
|
502
|
-
|
503
|
-
var CryptoJS=CryptoJS||function(h,r){var k={},l=k.lib={},n=function(){},f=l.Base={extend:function(a){n.prototype=this;var b=new n;a&&b.mixIn(a);b.hasOwnProperty("init")||(b.init=function(){b.$super.init.apply(this,arguments)});b.init.prototype=b;b.$super=this;return b},create:function(){var a=this.extend();a.init.apply(a,arguments);return a},init:function(){},mixIn:function(a){for(var b in a)a.hasOwnProperty(b)&&(this[b]=a[b]);a.hasOwnProperty("toString")&&(this.toString=a.toString)},clone:function(){return this.init.prototype.extend(this)}},j=l.WordArray=f.extend({init:function(a,b){a=this.words=a||[];this.sigBytes=b!=r?b:4*a.length},toString:function(a){return(a||s).stringify(this)},concat:function(a){var b=this.words,d=a.words,c=this.sigBytes;a=a.sigBytes;this.clamp();if(c%4)for(var e=0;e<a;e++)b[c+e>>>2]|=(d[e>>>2]>>>24-8*(e%4)&255)<<24-8*((c+e)%4);else if(65535<d.length)for(e=0;e<a;e+=4)b[c+e>>>2]=d[e>>>2];else b.push.apply(b,d);this.sigBytes+=a;return this},clamp:function(){var a=this.words,b=this.sigBytes;a[b>>>2]&=4294967295<<32-8*(b%4);a.length=h.ceil(b/4)},clone:function(){var a=f.clone.call(this);a.words=this.words.slice(0);return a},random:function(a){for(var b=[],d=0;d<a;d+=4)b.push(4294967296*h.random()|0);return new j.init(b,a)}}),m=k.enc={},s=m.Hex={stringify:function(a){var b=a.words;a=a.sigBytes;for(var d=[],c=0;c<a;c++){var e=b[c>>>2]>>>24-8*(c%4)&255;d.push((e>>>4).toString(16));d.push((e&15).toString(16))}return d.join("")},parse:function(a){for(var b=a.length,d=[],c=0;c<b;c+=2)d[c>>>3]|=parseInt(a.substr(c,2),16)<<24-4*(c%8);return new j.init(d,b/2)}},p=m.Latin1={stringify:function(a){var b=a.words;a=a.sigBytes;for(var d=[],c=0;c<a;c++)d.push(String.fromCharCode(b[c>>>2]>>>24-8*(c%4)&255));return d.join("")},parse:function(a){for(var b=a.length,d=[],c=0;c<b;c++)d[c>>>2]|=(a.charCodeAt(c)&255)<<24-8*(c%4);return new j.init(d,b)}},t=m.Utf8={stringify:function(a){try{return decodeURIComponent(escape(p.stringify(a)))}catch(b){throw Error("Malformed UTF-8 data");}},parse:function(a){return p.parse(unescape(encodeURIComponent(a)))}},q=l.BufferedBlockAlgorithm=f.extend({reset:function(){this._data=new j.init;this._nDataBytes=0},_append:function(a){"string"==typeof a&&(a=t.parse(a));this._data.concat(a);this._nDataBytes+=a.sigBytes},_process:function(a){var b=this._data,d=b.words,c=b.sigBytes,e=this.blockSize,f=c/(4*e),f=a?h.ceil(f):h.max((f|0)-this._minBufferSize,0);a=f*e;c=h.min(4*a,c);if(a){for(var g=0;g<a;g+=e)this._doProcessBlock(d,g);g=d.splice(0,a);b.sigBytes-=c}return new j.init(g,c)},clone:function(){var a=f.clone.call(this);a._data=this._data.clone();return a},_minBufferSize:0});l.Hasher=q.extend({cfg:f.extend(),init:function(a){this.cfg=this.cfg.extend(a);this.reset()},reset:function(){q.reset.call(this);this._doReset()},update:function(a){this._append(a);this._process();return this},finalize:function(a){a&&this._append(a);return this._doFinalize()},blockSize:16,_createHelper:function(a){return function(b,d){return(new a.init(d)).finalize(b)}},_createHmacHelper:function(a){return function(b,d){return(new u.HMAC.init(a,d)).finalize(b)}}});var u=k.algo={};return k}(Math);
|
504
|
-
(function () { var k = CryptoJS, b = k.lib, m = b.WordArray, l = b.Hasher, d = [], b = k.algo.SHA1 = l.extend({ _doReset: function () { this._hash = new m.init([1732584193, 4023233417, 2562383102, 271733878, 3285377520]) }, _doProcessBlock: function (n, p) { for (var a = this._hash.words, e = a[0], f = a[1], h = a[2], j = a[3], b = a[4], c = 0; 80 > c; c++) { if (16 > c) d[c] = n[p + c] | 0; else { var g = d[c - 3] ^ d[c - 8] ^ d[c - 14] ^ d[c - 16]; d[c] = g << 1 | g >>> 31 } g = (e << 5 | e >>> 27) + b + d[c]; g = 20 > c ? g + ((f & h | ~f & j) + 1518500249) : 40 > c ? g + ((f ^ h ^ j) + 1859775393) : 60 > c ? g + ((f & h | f & j | h & j) - 1894007588) : g + ((f ^ h ^ j) - 899497514); b = j; j = h; h = f << 30 | f >>> 2; f = e; e = g } a[0] = a[0] + e | 0; a[1] = a[1] + f | 0; a[2] = a[2] + h | 0; a[3] = a[3] + j | 0; a[4] = a[4] + b | 0 }, _doFinalize: function () { var b = this._data, d = b.words, a = 8 * this._nDataBytes, e = 8 * b.sigBytes; d[e >>> 5] |= 128 << 24 - e % 32; d[(e + 64 >>> 9 << 4) + 14] = Math.floor(a / 4294967296); d[(e + 64 >>> 9 << 4) + 15] = a; b.sigBytes = 4 * d.length; this._process(); return this._hash }, clone: function () { var b = l.clone.call(this); b._hash = this._hash.clone(); return b } }); k.SHA1 = l._createHelper(b); k.HmacSHA1 = l._createHmacHelper(b) })();
|
505
|
-
(function (k) { for (var g = CryptoJS, h = g.lib, v = h.WordArray, j = h.Hasher, h = g.algo, s = [], t = [], u = function (q) { return 4294967296 * (q - (q | 0)) | 0 }, l = 2, b = 0; 64 > b;) { var d; a: { d = l; for (var w = k.sqrt(d), r = 2; r <= w; r++) if (!(d % r)) { d = !1; break a } d = !0 } d && (8 > b && (s[b] = u(k.pow(l, 0.5))), t[b] = u(k.pow(l, 1 / 3)), b++); l++ } var n = [], h = h.SHA256 = j.extend({ _doReset: function () { this._hash = new v.init(s.slice(0)) }, _doProcessBlock: function (q, h) { for (var a = this._hash.words, c = a[0], d = a[1], b = a[2], k = a[3], f = a[4], g = a[5], j = a[6], l = a[7], e = 0; 64 > e; e++) { if (16 > e) n[e] = q[h + e] | 0; else { var m = n[e - 15], p = n[e - 2]; n[e] = ((m << 25 | m >>> 7) ^ (m << 14 | m >>> 18) ^ m >>> 3) + n[e - 7] + ((p << 15 | p >>> 17) ^ (p << 13 | p >>> 19) ^ p >>> 10) + n[e - 16] } m = l + ((f << 26 | f >>> 6) ^ (f << 21 | f >>> 11) ^ (f << 7 | f >>> 25)) + (f & g ^ ~f & j) + t[e] + n[e]; p = ((c << 30 | c >>> 2) ^ (c << 19 | c >>> 13) ^ (c << 10 | c >>> 22)) + (c & d ^ c & b ^ d & b); l = j; j = g; g = f; f = k + m | 0; k = b; b = d; d = c; c = m + p | 0 } a[0] = a[0] + c | 0; a[1] = a[1] + d | 0; a[2] = a[2] + b | 0; a[3] = a[3] + k | 0; a[4] = a[4] + f | 0; a[5] = a[5] + g | 0; a[6] = a[6] + j | 0; a[7] = a[7] + l | 0 }, _doFinalize: function () { var d = this._data, b = d.words, a = 8 * this._nDataBytes, c = 8 * d.sigBytes; b[c >>> 5] |= 128 << 24 - c % 32; b[(c + 64 >>> 9 << 4) + 14] = k.floor(a / 4294967296); b[(c + 64 >>> 9 << 4) + 15] = a; d.sigBytes = 4 * b.length; this._process(); return this._hash }, clone: function () { var b = j.clone.call(this); b._hash = this._hash.clone(); return b } }); g.SHA256 = j._createHelper(h); g.HmacSHA256 = j._createHmacHelper(h) })(Math);
|
506
|
-
(function(){var c=CryptoJS,k=c.enc.Utf8;c.algo.HMAC=c.lib.Base.extend({init:function(a,b){a=this._hasher=new a.init;"string"==typeof b&&(b=k.parse(b));var c=a.blockSize,e=4*c;b.sigBytes>e&&(b=a.finalize(b));b.clamp();for(var f=this._oKey=b.clone(),g=this._iKey=b.clone(),h=f.words,j=g.words,d=0;d<c;d++)h[d]^=1549556828,j[d]^=909522486;f.sigBytes=g.sigBytes=e;this.reset()},reset:function(){var a=this._hasher;a.reset();a.update(this._iKey)},update:function(a){this._hasher.update(a);return this},finalize:function(a){var b=this._hasher;a=b.finalize(a);b.reset();return b.finalize(this._oKey.clone().concat(a))}})})();
|
507
|
-
(function(){var h=CryptoJS,j=h.lib.WordArray;h.enc.Base64={stringify:function(b){var e=b.words,f=b.sigBytes,c=this._map;b.clamp();b=[];for(var a=0;a<f;a+=3)for(var d=(e[a>>>2]>>>24-8*(a%4)&255)<<16|(e[a+1>>>2]>>>24-8*((a+1)%4)&255)<<8|e[a+2>>>2]>>>24-8*((a+2)%4)&255,g=0;4>g&&a+0.75*g<f;g++)b.push(c.charAt(d>>>6*(3-g)&63));if(e=c.charAt(64))for(;b.length%4;)b.push(e);return b.join("")},parse:function(b){var e=b.length,f=this._map,c=f.charAt(64);c&&(c=b.indexOf(c),-1!=c&&(e=c));for(var c=[],a=0,d=0;d<e;d++)if(d%4){var g=f.indexOf(b.charAt(d-1))<<2*(d%4),h=f.indexOf(b.charAt(d))>>>6-2*(d%4);c[a>>>2]|=(g|h)<<24-8*(a%4);a++}return j.create(c,a)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}})();
|