hbsig 0.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.
Files changed (44) hide show
  1. package/cjs/bin_to_str.js +44 -0
  2. package/cjs/collect-body-keys.js +470 -0
  3. package/cjs/encode-array-item.js +110 -0
  4. package/cjs/encode-utils.js +236 -0
  5. package/cjs/encode.js +1318 -0
  6. package/cjs/erl_json.js +317 -0
  7. package/cjs/erl_str.js +1037 -0
  8. package/cjs/flat.js +222 -0
  9. package/cjs/http-message-signatures/httpbis.js +489 -0
  10. package/cjs/http-message-signatures/index.js +25 -0
  11. package/cjs/http-message-signatures/structured-header.js +129 -0
  12. package/cjs/httpsig.js +716 -0
  13. package/cjs/httpsig2.js +1160 -0
  14. package/cjs/id.js +470 -0
  15. package/cjs/index.js +63 -0
  16. package/cjs/send.js +194 -0
  17. package/cjs/signer-utils.js +617 -0
  18. package/cjs/signer.js +606 -0
  19. package/cjs/structured.js +296 -0
  20. package/cjs/test.js +27 -0
  21. package/cjs/utils.js +42 -0
  22. package/esm/bin_to_str.js +46 -0
  23. package/esm/collect-body-keys.js +436 -0
  24. package/esm/encode-array-item.js +112 -0
  25. package/esm/encode-utils.js +185 -0
  26. package/esm/encode.js +1219 -0
  27. package/esm/erl_json.js +289 -0
  28. package/esm/erl_str.js +1139 -0
  29. package/esm/flat.js +196 -0
  30. package/esm/http-message-signatures/httpbis.js +438 -0
  31. package/esm/http-message-signatures/index.js +4 -0
  32. package/esm/http-message-signatures/structured-header.js +105 -0
  33. package/esm/httpsig.js +658 -0
  34. package/esm/httpsig2.js +1097 -0
  35. package/esm/id.js +459 -0
  36. package/esm/index.js +4 -0
  37. package/esm/package.json +3 -0
  38. package/esm/send.js +124 -0
  39. package/esm/signer-utils.js +494 -0
  40. package/esm/signer.js +452 -0
  41. package/esm/structured.js +269 -0
  42. package/esm/test.js +6 -0
  43. package/esm/utils.js +28 -0
  44. package/package.json +28 -0
package/esm/test.js ADDED
@@ -0,0 +1,6 @@
1
+ import { readFileSync } from "fs"
2
+ import { resolve } from "path"
3
+ import { acc } from "./accounts.js"
4
+ import { toAddr, dirname, wait } from "./utils.js"
5
+
6
+ export { toAddr, wait, acc }
package/esm/utils.js ADDED
@@ -0,0 +1,28 @@
1
+ import sha256 from "fast-sha256"
2
+
3
+ function base64urlDecode(str) {
4
+ str = str.replace(/-/g, "+").replace(/_/g, "/")
5
+ const pad = str.length % 4
6
+ if (pad === 2) str += "=="
7
+ else if (pad === 3) str += "="
8
+ else if (pad !== 0) throw new Error("Invalid base64url string")
9
+ const bin = atob(str)
10
+ const bytes = new Uint8Array(bin.length)
11
+ for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i)
12
+ return bytes
13
+ }
14
+
15
+ function base64urlEncode(bytes) {
16
+ let bin = ""
17
+ for (const b of bytes) bin += String.fromCharCode(b)
18
+ let b64 = btoa(bin)
19
+ return b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "")
20
+ }
21
+
22
+ function toAddr(n) {
23
+ const pubBytes = base64urlDecode(n)
24
+ const hash = sha256(pubBytes)
25
+ return base64urlEncode(hash)
26
+ }
27
+
28
+ export { toAddr }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "hbsig",
3
+ "version": "0.0.1",
4
+ "main": "cjs/index.js",
5
+ "license": "MIT",
6
+ "devDependencies": {
7
+ "@babel/plugin-transform-modules-commonjs": "^7.24.8",
8
+ "@babel/cli": "^7.24.8",
9
+ "@babel/core": "^7.25.2",
10
+ "@babel/preset-env": "^7.25.3"
11
+ },
12
+ "dependencies": {
13
+ "wao": "^0.32.2",
14
+ "@permaweb/aoconnect": "^0.0.85",
15
+ "base64url": "^3.0.1",
16
+ "fast-sha256": "^1.3.0",
17
+ "ramda": "^0.31.3",
18
+ "structured-headers": "^2.0.1"
19
+ },
20
+ "module": "esm/index.js",
21
+ "bin": {
22
+ "wao": "./cjs/cli.js",
23
+ "wao-esm": "./esm/cli.js"
24
+ },
25
+ "scripts": {
26
+ "server": "node --experimental-wasm-memory64 cjs/run.js"
27
+ }
28
+ }