bsv-bap 0.0.1 → 0.0.2

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 (68) hide show
  1. package/dist/{src/constants.d.ts → constants.d.ts} +2 -2
  2. package/dist/{src/id.d.ts → id.d.ts} +8 -22
  3. package/dist/index.cjs +2 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/{src/index.d.ts → index.d.ts} +16 -11
  6. package/dist/index.modern.js +2 -0
  7. package/dist/index.modern.js.map +1 -0
  8. package/dist/index.module.js +2 -0
  9. package/dist/index.module.js.map +1 -0
  10. package/dist/index.umd.js +2 -0
  11. package/dist/index.umd.js.map +1 -0
  12. package/dist/{src/interface.d.ts → interface.d.ts} +8 -4
  13. package/dist/{src/poa.d.ts → poa.d.ts} +1 -1
  14. package/dist/{src/utils.d.ts → utils.d.ts} +0 -1
  15. package/package.json +30 -57
  16. package/.babelrc +0 -20
  17. package/.eslintrc +0 -46
  18. package/babel.config.js +0 -6
  19. package/bun.lockb +0 -0
  20. package/coverage/clover.xml +0 -6
  21. package/coverage/coverage-final.json +0 -1
  22. package/coverage/lcov-report/base.css +0 -224
  23. package/coverage/lcov-report/block-navigation.js +0 -87
  24. package/coverage/lcov-report/favicon.png +0 -0
  25. package/coverage/lcov-report/index.html +0 -101
  26. package/coverage/lcov-report/prettify.css +0 -1
  27. package/coverage/lcov-report/prettify.js +0 -2
  28. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  29. package/coverage/lcov-report/sorter.js +0 -196
  30. package/coverage/lcov-report/src/constants.ts.html +0 -113
  31. package/coverage/lcov-report/src/id.ts.html +0 -2207
  32. package/coverage/lcov-report/src/index.html +0 -156
  33. package/coverage/lcov-report/src/index.ts.html +0 -1877
  34. package/coverage/lcov-report/src/utils.ts.html +0 -404
  35. package/coverage/lcov-report/tests/data/index.html +0 -111
  36. package/coverage/lcov-report/tests/data/keys.js.html +0 -86
  37. package/coverage/lcov.info +0 -0
  38. package/dist/jest.config.d.ts +0 -8
  39. package/dist/typescript-npm-package.cjs.d.ts +0 -554
  40. package/dist/typescript-npm-package.cjs.js +0 -1320
  41. package/dist/typescript-npm-package.cjs.js.map +0 -1
  42. package/dist/typescript-npm-package.esm.d.ts +0 -554
  43. package/dist/typescript-npm-package.esm.js +0 -1312
  44. package/dist/typescript-npm-package.esm.js.map +0 -1
  45. package/dist/typescript-npm-package.umd.d.ts +0 -554
  46. package/dist/typescript-npm-package.umd.js +0 -110193
  47. package/dist/typescript-npm-package.umd.js.map +0 -1
  48. package/jest.config.ts +0 -196
  49. package/jsdoc.json +0 -16
  50. package/rollup.config.js +0 -64
  51. package/setup-jest.js +0 -1
  52. package/src/README.md +0 -80
  53. package/src/attributes.json +0 -119
  54. package/src/constants.ts +0 -11
  55. package/src/id.ts +0 -783
  56. package/src/index.ts +0 -631
  57. package/src/interface.ts +0 -26
  58. package/src/poa.ts +0 -9
  59. package/src/utils.ts +0 -111
  60. package/tests/data/ids.json +0 -30
  61. package/tests/data/keys.js +0 -2
  62. package/tests/data/old-ids.json +0 -25
  63. package/tests/data/test-vectors.json +0 -122
  64. package/tests/id.test.js +0 -286
  65. package/tests/index.test.js +0 -335
  66. package/tests/regression.test.js +0 -28
  67. package/tests/utils.test.js +0 -27
  68. package/tsconfig.json +0 -17
package/src/utils.ts DELETED
@@ -1,111 +0,0 @@
1
- import randomBytes from "randombytes";
2
- import type {PathPrefix} from "./interface";
3
-
4
- export const Utils = {
5
- /**
6
- * Helper function for encoding strings to hex
7
- *
8
- * @param string
9
- * @returns {string}
10
- */
11
- hexEncode(string: string) {
12
- return `0x${Buffer.from(string).toString('hex')}`;
13
- },
14
-
15
- /**
16
- * Helper function for encoding strings to hex
17
- *
18
- * @param hexString string
19
- * @param encoding BufferEncoding
20
- * @returns {string}
21
- */
22
- hexDecode(hexString: string, encoding: BufferEncoding = 'utf8') {
23
- return Buffer.from(hexString.replace('0x', ''), 'hex').toString(encoding);
24
- },
25
-
26
- /**
27
- * Helper function to generate a random nonce
28
- *
29
- * @returns {string}
30
- */
31
- getRandomString(length = 32) {
32
- return randomBytes(length).toString('hex');
33
- },
34
-
35
- /**
36
- * Test whether the given string is hex
37
- *
38
- * @param value any
39
- * @returns {boolean}
40
- */
41
- isHex(value: string): boolean {
42
- if (typeof value !== 'string') {
43
- return false;
44
- }
45
- return /^[0-9a-fA-F]+$/.test(value);
46
- },
47
-
48
- /**
49
- * Get a signing path from a hex number
50
- *
51
- * @param hexString {string}
52
- * @param hardened {boolean} Whether to return a hardened path
53
- * @returns {string}
54
- */
55
- getSigningPathFromHex(hexString: string, hardened = true) {
56
- // "m/0/0/1"
57
- let signingPath = 'm';
58
- const signingHex = hexString.match(/.{1,8}/g);
59
- if (!signingHex) {
60
- throw new Error('Invalid hex string');
61
- }
62
- const maxNumber = 2147483648 - 1; // 0x80000000
63
- for (const hexNumber of signingHex) {
64
- let number = Number(`0x${hexNumber}`);
65
- if (number > maxNumber) number -= maxNumber;
66
- signingPath += `/${number}${(hardened ? "'" : '')}`;
67
- }
68
-
69
- return signingPath;
70
- },
71
-
72
- /**
73
- * Increment that second to last part from the given part, set the last part to 0
74
- *
75
- * @param path string
76
- * @returns {*}
77
- */
78
- getNextIdentityPath(path: string): PathPrefix {
79
- const pathValues = path.split('/');
80
- const secondToLastPart = pathValues[pathValues.length - 2];
81
-
82
- let hardened = false;
83
- if (secondToLastPart.match('\'')) {
84
- hardened = true;
85
- }
86
-
87
- const nextPath = (Number(secondToLastPart.replace(/[^0-9]/g, '')) + 1).toString();
88
- pathValues[pathValues.length - 2] = nextPath + (hardened ? '\'' : '');
89
- pathValues[pathValues.length - 1] = `0${hardened ? '\'' : ''}`;
90
-
91
- return pathValues.join('/') as PathPrefix;
92
- },
93
-
94
- /**
95
- * Increment that last part of the given path
96
- *
97
- * @param path string
98
- * @returns {*}
99
- */
100
- getNextPath(path: string) {
101
- const pathValues = path.split('/');
102
- const lastPart = pathValues[pathValues.length - 1];
103
- let hardened = false;
104
- if (lastPart.match('\'')) {
105
- hardened = true;
106
- }
107
- const nextPath = (Number(lastPart.replace(/[^0-9]/g, '')) + 1).toString();
108
- pathValues[pathValues.length - 1] = nextPath + (hardened ? '\'' : '');
109
- return pathValues.join('/');
110
- },
111
- };
@@ -1,30 +0,0 @@
1
- {
2
- "lastIdPath": "/26562456/876543/345346",
3
- "ids": [
4
- {
5
- "name": "Social media id",
6
- "description": "Safe to share with social media companies",
7
- "identityKey": "4a59332b7d81c4c68a6edcb1160f4683037a97286b97cc500b5881632e921849z",
8
- "lastIdPath": "",
9
- "rootPath": "m/424150'/0'/0'/26562456/876543/0",
10
- "rootAddress": "12Ne5DNJLtXzR5TFGrZvRwJP4rxsBovgHj",
11
- "currentPath": "m/424150'/0'/0'/26562456/876543/345346",
12
- "previousPath": "m/424150'/0'/0'/26562456/876543/345345",
13
- "idSeed": "",
14
- "identityAttributes": {
15
- "uniKey": {
16
- "value": "042e65eedd59a4600919a985e5d74c4fb337059e03b17d6e270e149481fa3bc8",
17
- "nonce": "ea88e989c4d7383634057a21cfc0c5b854399f4f1955efdafc9292edf340d06b"
18
- },
19
- "name": {
20
- "value": "John Doe",
21
- "nonce": "e2c6fb4063cc04af58935737eaffc938011dff546d47b7fbb18ed346f8c4d4fa"
22
- },
23
- "email": {
24
- "value": "john.doe@example.com",
25
- "nonce": "2864fd138ab1e9ddaaea763c77a45898dac64a26229f9f3d0f2280e4bfa915de"
26
- }
27
- }
28
- }
29
- ]
30
- }
@@ -1,2 +0,0 @@
1
- export const HDPrivateKey = 'xprv9s21ZrQH143K2LcEfSnFRH1JvdKAcuZj2C8kAzCDnvqC4kgo417hYmAYQKdYDSzQSnQMLWXjDG42TgWwdYqwhAWTWpEBG1ighLLNnVHNKxx';
2
- export const HDPublicKey = 'xpub661MyMwAqRbcEpghmUKFnQx3Uf9f2NHaPR4LyNbqMGNAwZ1wbYRx6ZV2FaimDygDPbrHYuii12mYCNwFRWnvXXKnh12CK17XMFGiqUYNwew';
@@ -1,25 +0,0 @@
1
- [
2
- {
3
- "name": "Social media id",
4
- "description": "Safe to share with social media companies",
5
- "identityKey": "4a59332b7d81c4c68a6edcb1160f4683037a97286b97cc500b5881632e921849z",
6
- "rootPath": "m/424150'/0'/0'/26562456/876543/0",
7
- "rootAddress": "12Ne5DNJLtXzR5TFGrZvRwJP4rxsBovgHj",
8
- "currentPath": "m/424150'/0'/0'/26562456/876543/345346",
9
- "previousPath": "m/424150'/0'/0'/26562456/876543/345345",
10
- "identityAttributes": {
11
- "uniKey": {
12
- "value": "042e65eedd59a4600919a985e5d74c4fb337059e03b17d6e270e149481fa3bc8",
13
- "nonce": "ea88e989c4d7383634057a21cfc0c5b854399f4f1955efdafc9292edf340d06b"
14
- },
15
- "name": {
16
- "value": "John Doe",
17
- "nonce": "e2c6fb4063cc04af58935737eaffc938011dff546d47b7fbb18ed346f8c4d4fa"
18
- },
19
- "email": {
20
- "value": "john.doe@example.com",
21
- "nonce": "2864fd138ab1e9ddaaea763c77a45898dac64a26229f9f3d0f2280e4bfa915de"
22
- }
23
- }
24
- }
25
- ]
@@ -1,122 +0,0 @@
1
- [
2
- {
3
- "HDPrivateKey": "xprv9s21ZrQH143K3BcoP3NDU1L9HKbWim7fpQmLvVTJLWAiWWmxV4qxVadLRGJGFDWrGtQWGwvoLmo7GAGgTZuBcyqtRRRQxPsn78tZn97hndd",
4
- "rootPath": "m/424150'/0'/0'/0'/0'/0'",
5
- "rootAddress": "1wt1buQLx2G39adHovj2QJZnZK9vsXUjC",
6
- "rootSha256": "f8df2c6d1d7767fa1d26f8a0fb768420d86136b7a1b95622e9e971b59db0bb64",
7
- "rootRipemd160": "f8d991dcb289d17085544a3fcebff8042175f2bf",
8
- "rootBase58": "4U5eEMQSUdmPXeqmyQJtvELPNE8E",
9
- "idKey": "4U5eEMQSUdmPXeqmyQJtvELPNE8E",
10
- "tx": [
11
- "31424150537561506e66476e53424d33474c56397968785564596534764762644d54",
12
- "4944",
13
- "34553565454d515355646d505865716d79514a7476454c504e453845",
14
- "314b314d316e71705752654a52314a546a7169334754456336535669327178455841",
15
- "7c",
16
- "313550636948473232534e4c514a584d6f5355615756693757537163376843667661",
17
- "424954434f494e5f4543445341",
18
- "317774316275514c78324733396164486f766a32514a5a6e5a4b39767358556a43",
19
- "20c84a5d41f9041841a5bec69c25d9b46c30705de07486c6b7bc22e0c806302b214a47783d43dfb5588d120a65b27a16b106483c130b4d381b7a12ab0e88cae5a9"
20
- ]
21
- },
22
- {
23
- "HDPrivateKey": "xprv9s21ZrQH143K3GUBRVhWpwHTip7ejEBgU24rbJC6BdvqHtAoVopAGQj9K8FDvSVA9uSdvHtE1u5QNFND46VkyBQbtNvoqdQHN8s1cGV6NHX",
24
- "rootPath": "m/424150'/0'/0'/0'/0'/0'",
25
- "rootAddress": "17bBcqF6bfFWRRtLEvfup5Ez2z1UyJHQUi",
26
- "rootSha256": "cf96add68aa0d4203db2b5e534ec5fafb279fd40fb7889afe592739233652f10",
27
- "rootRipemd160": "d3278593d558f335a1b98fb773d81ea978a97f49",
28
- "rootBase58": "3wcztPg44xCLKi7pAt9qQHeb74Pr",
29
- "idKey": "3wcztPg44xCLKi7pAt9qQHeb74Pr",
30
- "tx": [
31
- "31424150537561506e66476e53424d33474c56397968785564596534764762644d54",
32
- "4944",
33
- "3377637a745067343478434c4b693770417439715148656237345072",
34
- "315076755a3676464a4379325974476271366b4d4a677239375157624e7a58386351",
35
- "7c",
36
- "313550636948473232534e4c514a584d6f5355615756693757537163376843667661",
37
- "424954434f494e5f4543445341",
38
- "3137624263714636626646575252744c457666757035457a327a3155794a48515569",
39
- "206bb7e0d289b49d45fecf3e98d036d314d8d1d88b5f73b7e294b5b882183d9afb562f36d7a88891dda4a170f0df91305045f4ebf36eb6dc1fc9c8ec66c2b03cfd"
40
- ]
41
- },
42
- {
43
- "HDPrivateKey": "xprv9s21ZrQH143K3QWj8yExWYjJx2cLrw2G353L9YC5DzYDGRWqGSFQ5nadQjmLSHidDiky8EAXU54XJeJEqPnZY7RbzZCuXTjHg2E97Gg787C",
44
- "rootPath": "m/424150'/0'/0'/0'/0'/0'",
45
- "rootAddress": "1DxxijXoBXrK2tiLLnr6uxQnfX53NQZN9T",
46
- "rootSha256": "708396bb94402a747895b484f8449e9d2032438900bcff050f3d20fc3d2df1ed",
47
- "rootRipemd160": "ac01980ce46158f40f79ea468770046f62d3f55f",
48
- "rootBase58": "3PzGsvDZXmm66mhVNLzSewHMW9in",
49
- "idKey": "3PzGsvDZXmm66mhVNLzSewHMW9in",
50
- "tx": [
51
- "31424150537561506e66476e53424d33474c56397968785564596534764762644d54",
52
- "4944",
53
- "33507a477376445a586d6d36366d68564e4c7a536577484d5739696e",
54
- "314c6b7a694c773131524d6b57576e4c6b3379324842436d5835706d4b7647433566",
55
- "7c",
56
- "313550636948473232534e4c514a584d6f5355615756693757537163376843667661",
57
- "424954434f494e5f4543445341",
58
- "31447878696a586f4258724b3274694c4c6e72367578516e665835334e515a4e3954",
59
- "1f0028d13676149bb9b6cc927274e1ec410b5a66384c4aa03ddde91c7aabc5b06107a8e1f17ab5eac926869252e4f8ef11fae3d757cc8f9173191b0192db672990"
60
- ]
61
- },
62
- {
63
- "HDPrivateKey": "xprv9s21ZrQH143K2n3FGVYiDqaFDQkbCxX8Z9MhLaHVmGsfr5HgCv5Y2vxkmwDeam7Fhb2zqGkfy5vyWL2RqDjHCoY5kf9p3ReV28WymTwsyiD",
64
- "rootPath": "m/424150'/0'/0'/0'/0'/0'",
65
- "rootAddress": "1DVN336g2rEfvrmWot5LufE47moMSSrguj",
66
- "rootSha256": "f99c96a904bd849d4a0aa489219a01d67d700f3005e7c86e932e287a3b245bc4",
67
- "rootRipemd160": "a18f9936007cf49d9f68c9f0b032786d3b6d3ad3",
68
- "rootBase58": "3FYk5crXc81pZZA17ffzofyTaqfp",
69
- "idKey": "3FYk5crXc81pZZA17ffzofyTaqfp",
70
- "tx": [
71
- "31424150537561506e66476e53424d33474c56397968785564596534764762644d54",
72
- "4944",
73
- "3346596b35637258633831705a5a41313766667a6f66795461716670",
74
- "314370754474576b4545796835467837484b4c473474626e58694e34695053696977",
75
- "7c",
76
- "313550636948473232534e4c514a584d6f5355615756693757537163376843667661",
77
- "424954434f494e5f4543445341",
78
- "3144564e333336673272456676726d576f74354c75664534376d6f4d53537267756a",
79
- "1feb243ecdb32d091513c931337aba240f446ac6e01c777a05793e0d42e3d8ac3b23b088f5ef62da158428cdf0c4cb745e873ba9cfb0e6810d029fd473d0b4effe"
80
- ]
81
- },
82
- {
83
- "HDPrivateKey": "xprv9s21ZrQH143K2xfRXanwL1Tx82Enucrq46ZKDqNsSsbW9X9smcDxGc16fnXQV4tMZg9HrskczDTthsS83XEwyWJHDTuxohTcZXEBxi6hTXT",
84
- "rootPath": "m/424150'/0'/0'/0'/0'/0'",
85
- "rootAddress": "16Kd8HcQ79fa6BFWVRK6PsDNhkxoubNWrS",
86
- "rootSha256": "2e76901a9712c3925d89ca778bc236e2c1d850a8f69fc0f23269ba70da7c34cd",
87
- "rootRipemd160": "95966d63808eb299f1492ff07078cffe3a51d7f3",
88
- "rootBase58": "35sbjSD55abC3N5hLtbN5kWXhLhx",
89
- "idKey": "35sbjSD55abC3N5hLtbN5kWXhLhx",
90
- "tx": [
91
- "31424150537561506e66476e53424d33474c56397968785564596534764762644d54",
92
- "4944",
93
- "333573626a53443535616243334e35684c74624e356b5758684c6878",
94
- "31373867655678766a65464531576354636f6e6f6e734367537356353752645432",
95
- "7c",
96
- "313550636948473232534e4c514a584d6f5355615756693757537163376843667661",
97
- "424954434f494e5f4543445341",
98
- "31364b6438486351373966613642465756524b365073444e686b786f75624e577253",
99
- "1f690cbc0a1bbc7acee8e378d54d5e646011f8e36b08f6bb3f0eb5f972a4e9c49a4865eb97334805934fac37d7e3a3365b540d1008321d80bb9e0785b866569708"
100
- ]
101
- },
102
- {
103
- "HDPrivateKey": "xprv9s21ZrQH143K3gjDedgKXZTj3VtS91p6rdm5Zcdu4WmT1zLcLTZUWhzbzNAAtZximg6s1ejJiaBCRt8qnmaAWu7SgFvTZvqmE3KDTPtrpBv",
104
- "rootPath": "m/424150'/0'/0'/0'/0'/0'",
105
- "rootAddress": "1M7NLLBwu6BzCWDeMFP18SqYAmUtyRfJwf",
106
- "rootSha256": "9003948e05cfb70b2e97626420cabf2eb874a09f7a6aceebd91dcdecb21a020e",
107
- "rootRipemd160": "c4b12bf6f7adfcebc546d036d868cfd5ad5497e7",
108
- "rootBase58": "3jwCu5ZcixQBfBDk3JhUbfj9ZdGr",
109
- "idKey": "3jwCu5ZcixQBfBDk3JhUbfj9ZdGr",
110
- "tx": [
111
- "31424150537561506e66476e53424d33474c56397968785564596534764762644d54",
112
- "4944",
113
- "336a774375355a63697851426642446b334a685562666a395a644772",
114
- "314d726e725a74726967527632547652516767347973714a504a637539746f4c7654",
115
- "7c",
116
- "313550636948473232534e4c514a584d6f5355615756693757537163376843667661",
117
- "424954434f494e5f4543445341",
118
- "314d374e4c4c42777536427a435744654d46503138537159416d55747952664a7766",
119
- "1f09ddcbaf387768982a510533af8f6deb1d7d32e85f813388d931c07950b57fc0749e1b03772eb88245d78acf6fcafae367a9ac83d6a518faed23527361c9fc57"
120
- ]
121
- }
122
- ]
package/tests/id.test.js DELETED
@@ -1,286 +0,0 @@
1
- import { describe, expect, beforeEach, test } from "@jest/globals";
2
- import { BAP } from "../src";
3
- import { BAP_ID } from "../src/id";
4
- import { HDPrivateKey } from "./data/keys";
5
- import { HD, PrivateKey } from "@bsv/sdk";
6
- import {
7
- BAP_BITCOM_ADDRESS_HEX,
8
- AIP_BITCOM_ADDRESS_HEX,
9
- SIGNING_PATH_PREFIX,
10
- } from "../src/constants";
11
-
12
- const identityAttributes = {
13
- name: {
14
- value: "John Doe",
15
- nonce: "e2c6fb4063cc04af58935737eaffc938011dff546d47b7fbb18ed346f8c4d4fa",
16
- },
17
- email: {
18
- value: "john.doe@example.com",
19
- nonce: "2864fd138ab1e9ddaaea763c77a45898dac64a26229f9f3d0f2280e4bfa915de",
20
- },
21
- };
22
- const identityAttributeStrings = `
23
- urn:bap:id:name:John Doe:e2c6fb4063cc04af58935737eaffc938011dff546d47b7fbb18ed346f8c4d4fa
24
- urn:bap:id:email:john.doe@example.com:2864fd138ab1e9ddaaea763c77a45898dac64a26229f9f3d0f2280e4bfa915de
25
- `;
26
-
27
- let bap;
28
-
29
- describe("bap-id", () => {
30
- beforeEach(() => {
31
- bap = new BAP(HDPrivateKey);
32
- });
33
-
34
- test("new id", () => {
35
- const bapId = bap.newId();
36
-
37
- const identityKey = bapId.getIdentityKey();
38
- expect(typeof identityKey).toBe("string");
39
- expect(identityKey).toHaveLength(27);
40
- expect(bapId.getAttributes()).toMatchObject({});
41
- });
42
-
43
- test("new id with known key", () => {
44
- const userId = new BAP_ID(HD.fromString(HDPrivateKey));
45
- const rootAddress = userId.rootAddress;
46
- const identityKey = userId.getIdentityKey();
47
- expect(rootAddress).toBe("1CSJiMMYzfW8gbhXXNYyEJ1NsWJohLXyet");
48
- expect(identityKey).toBe("2cWvSXKfFQScCgDFssRPKvDLjNYx");
49
- });
50
-
51
- test("new id with seeded keys", () => {
52
- const userId = new BAP_ID(HD.fromString(HDPrivateKey), {}, "test");
53
- const rootAddress = userId.rootAddress;
54
- const identityKey = userId.getIdentityKey();
55
- expect(rootAddress).toBe("189oxMiD6wFA4nD38CkoWBKragxXUfw26J");
56
- expect(identityKey).toBe("ffw3VszEVByph2DuHUiswEMNjRm");
57
-
58
- const userId2 = new BAP_ID(HD.fromString(HDPrivateKey), {}, "testing 123");
59
- const rootAddress2 = userId2.rootAddress;
60
- const identityKey2 = userId2.getIdentityKey();
61
- expect(rootAddress2).toBe("18zrzzv2Nieve7QAj2AwGDcPYyBziz8vWk");
62
- expect(identityKey2).toBe("2UKj9321g9pDExCjL7dPhXMtM326");
63
- });
64
-
65
- test("set BAP_SERVER", () => {
66
- const bap = new BAP(HDPrivateKey);
67
- const id = bap.newId();
68
- expect(id.BAP_SERVER).toBe("https://bap.network/api/v1");
69
-
70
- const newServer = "https://bapdev.legallychained.com/";
71
- id.BAP_SERVER = newServer;
72
- expect(id.BAP_SERVER).toBe(newServer);
73
- });
74
-
75
- test("parseAttributes", () => {
76
- const bapId = bap.newId();
77
- const parsed = bapId.parseAttributes(identityAttributes);
78
- expect(parsed).toStrictEqual(identityAttributes);
79
-
80
- const parsed2 = bapId.parseAttributes(identityAttributeStrings);
81
- expect(parsed2).toStrictEqual(identityAttributes);
82
- });
83
-
84
- test("parseStringUrns", () => {
85
- const bapId = bap.newId();
86
- const parsed = bapId.parseStringUrns(identityAttributeStrings);
87
- expect(parsed).toStrictEqual(identityAttributes);
88
-
89
- expect(() => {
90
- bapId.parseStringUrns({ value: "John Doe", nonce: "" });
91
- }).toThrow();
92
- });
93
-
94
- test("attributes", () => {
95
- const bapId = bap.newId(false, identityAttributes);
96
- bapId.addAttribute("birthday", "1990-05-22"); // nonce will be automatically generated
97
- bapId.addAttribute(
98
- "over18",
99
- "1",
100
- "ca17ccaacd671b28dc811332525f2f2cd594d8e8e7825de515ce5d52d30e8",
101
- );
102
-
103
- expect(bapId.getAttribute("name").value).toBe("John Doe");
104
- expect(bapId.getAttribute("name").nonce).toBe(
105
- "e2c6fb4063cc04af58935737eaffc938011dff546d47b7fbb18ed346f8c4d4fa",
106
- );
107
-
108
- expect(bapId.getAttribute("birthday").value).toBe("1990-05-22");
109
- expect(typeof bapId.getAttribute("birthday").nonce).toBe("string");
110
- expect(bapId.getAttribute("birthday").nonce).toHaveLength(64);
111
-
112
- expect(bapId.getAttribute("over18").value).toBe("1");
113
- expect(bapId.getAttribute("over18").nonce).toBe(
114
- "ca17ccaacd671b28dc811332525f2f2cd594d8e8e7825de515ce5d52d30e8",
115
- );
116
-
117
- expect(bapId.getAttribute("over21")).toBe(null);
118
- });
119
-
120
- test("getAttributeUrns", () => {
121
- const bapId = bap.newId(false, identityAttributes);
122
-
123
- const expectedName =
124
- "urn:bap:id:name:John Doe:e2c6fb4063cc04af58935737eaffc938011dff546d47b7fbb18ed346f8c4d4fa";
125
- expect(bapId.getAttributeUrn("name")).toBe(expectedName);
126
- expect(bapId.getAttributeUrn("over21")).toBe(null);
127
-
128
- const attributeStrings = bapId.getAttributeUrns();
129
- const expectedAtt = `urn:bap:id:name:John Doe:e2c6fb4063cc04af58935737eaffc938011dff546d47b7fbb18ed346f8c4d4fa
130
- urn:bap:id:email:john.doe@example.com:2864fd138ab1e9ddaaea763c77a45898dac64a26229f9f3d0f2280e4bfa915de
131
- `;
132
- expect(attributeStrings).toBe(expectedAtt);
133
- });
134
-
135
- test("incrementPath", () => {
136
- const randomHDPrivateKey = HD.fromRandom();
137
- const bapId = new BAP_ID(randomHDPrivateKey);
138
-
139
- expect(bapId.currentPath).toBe(`${SIGNING_PATH_PREFIX}/0/0/1`);
140
- bapId.incrementPath();
141
- expect(bapId.previousPath).toBe(`${SIGNING_PATH_PREFIX}/0/0/1`);
142
- expect(bapId.currentPath).toBe(`${SIGNING_PATH_PREFIX}/0/0/2`);
143
- bapId.incrementPath();
144
- expect(bapId.previousPath).toBe(`${SIGNING_PATH_PREFIX}/0/0/2`);
145
- expect(bapId.currentPath).toBe(`${SIGNING_PATH_PREFIX}/0/0/3`);
146
- bapId.incrementPath();
147
- expect(bapId.previousPath).toBe(`${SIGNING_PATH_PREFIX}/0/0/3`);
148
- expect(bapId.currentPath).toBe(`${SIGNING_PATH_PREFIX}/0/0/4`);
149
- });
150
-
151
- test("signingPath", () => {
152
- const bapId = bap.newId();
153
- expect(bapId.rootPath).toBe("m/424150'/0'/0'/0'/0'/0'");
154
- expect(bapId.currentPath).toBe("m/424150'/0'/0'/0'/0'/1'");
155
-
156
- bapId.currentPath = "/0/0/2";
157
- expect(bapId.currentPath).toBe("m/424150'/0'/0'/0/0/2");
158
-
159
- expect(() => {
160
- bapId.rootPath = "test";
161
- }).toThrow();
162
- expect(() => {
163
- bapId.currentPath = "test";
164
- }).toThrow();
165
- });
166
-
167
- test("getAttestation / Hash", () => {
168
- const bapId = bap.newId(false, identityAttributes);
169
- const urn = bapId.getAttributeUrn("name");
170
- expect(urn).toBe(
171
- "urn:bap:id:name:John Doe:e2c6fb4063cc04af58935737eaffc938011dff546d47b7fbb18ed346f8c4d4fa",
172
- );
173
- const attestation = bapId.getAttestation(urn);
174
- const expectedAttestation =
175
- "bap:attest:b17c8e606afcf0d8dca65bdf8f33d275239438116557980203c82b0fae259838:GbPKb7tQpfZDut9mJnBm5BMtGqu";
176
- expect(attestation).toBe(expectedAttestation);
177
-
178
- const hash = bapId.getAttestationHash("name");
179
- expect(hash).toBe(
180
- "bc91964394e81cb0fc0a0cad53894456711e2f7e4626ce3977de0a92abdded70",
181
- );
182
- });
183
-
184
- test("getInitialIdTransaction", () => {
185
- const bapId = bap.newId(false, identityAttributes);
186
- const tx = bapId.getInitialIdTransaction();
187
- expect(`0x${tx[0]}`).toBe(BAP_BITCOM_ADDRESS_HEX);
188
- expect(tx[1]).toBe(Buffer.from("ID").toString("hex"));
189
- expect(tx[2]).toBe(Buffer.from(bapId.getIdentityKey()).toString("hex"));
190
- expect(tx[3]).toBe(
191
- Buffer.from(bapId.getAddress(bapId.currentPath)).toString("hex"),
192
- );
193
- expect(tx[4]).toBe(Buffer.from("|").toString("hex"));
194
- expect(`0x${tx[5]}`).toBe(AIP_BITCOM_ADDRESS_HEX);
195
- expect(tx[6]).toBe(Buffer.from("BITCOIN_ECDSA").toString("hex"));
196
- expect(tx[7]).toBe(
197
- Buffer.from(bapId.getAddress(bapId.rootPath)).toString("hex"),
198
- );
199
- expect(typeof tx[8]).toBe("string");
200
- });
201
-
202
- test("encryption public keys", () => {
203
- const bapId = bap.newId(false, identityAttributes);
204
- const pubKey = bapId.getEncryptionPublicKey();
205
- expect(pubKey).toBe(
206
- "02a257adfbba04a25a7c37600209a0926aa264428b2d3d2b17fa97cf9c31b87cdf",
207
- );
208
-
209
- const pubKeySeed = bapId.getEncryptionPublicKeyWithSeed("test-seed");
210
- expect(pubKeySeed).toBe(
211
- "0344786ed9e861b40b1157e841d6f0f7667548f03adff2709ebd74061068f8376a",
212
- );
213
- });
214
-
215
- test("encryption", () => {
216
- const bapId = bap.newId(false, identityAttributes);
217
- const pubKey = bapId.getEncryptionPublicKey();
218
- expect(pubKey).toBe(
219
- "02a257adfbba04a25a7c37600209a0926aa264428b2d3d2b17fa97cf9c31b87cdf",
220
- );
221
-
222
- const testData = "This is a test we are going to encrypt";
223
- const ciphertext = bapId.encrypt(testData);
224
- expect(typeof ciphertext).toBe("string");
225
- expect(testData === ciphertext).toBe(false);
226
-
227
- const decrypted = bapId.decrypt(ciphertext);
228
- expect(testData === decrypted).toBe(true);
229
- });
230
-
231
- test("encryption with counterparty", () => {
232
- const bapId = bap.newId(false, identityAttributes);
233
- const pubKey = bapId.getEncryptionPublicKey();
234
- expect(pubKey).toBe(
235
- "02a257adfbba04a25a7c37600209a0926aa264428b2d3d2b17fa97cf9c31b87cdf",
236
- );
237
-
238
- const counterPartyKey = PrivateKey.fromRandom().publicKey;
239
-
240
- const testData =
241
- "This is a test we are going to encrypt for the counterparty";
242
- const ciphertext = bapId.encrypt(testData, counterPartyKey);
243
- expect(typeof ciphertext).toBe("string");
244
- expect(testData === ciphertext).toBe(false);
245
-
246
- const decrypted = bapId.decrypt(ciphertext, counterPartyKey);
247
- expect(testData === decrypted).toBe(true);
248
- });
249
-
250
- test("encryption with seed", () => {
251
- const bapId = bap.newId(false, identityAttributes);
252
- const pubKey = bapId.getEncryptionPublicKey();
253
- expect(pubKey).toBe(
254
- "02a257adfbba04a25a7c37600209a0926aa264428b2d3d2b17fa97cf9c31b87cdf",
255
- );
256
-
257
- const seed = "test-seed";
258
-
259
- const testData = "This is a test we are going to encrypt";
260
- const ciphertext = bapId.encryptWithSeed(testData, seed);
261
- expect(typeof ciphertext).toBe("string");
262
- expect(testData === ciphertext).toBe(false);
263
-
264
- const decrypted = bapId.decryptWithSeed(ciphertext, seed);
265
- expect(testData === decrypted).toBe(true);
266
- });
267
-
268
- test("encryption with seed with counterparty", () => {
269
- const bapId = bap.newId(false, identityAttributes);
270
- const pubKey = bapId.getEncryptionPublicKey();
271
- expect(pubKey).toBe(
272
- "02a257adfbba04a25a7c37600209a0926aa264428b2d3d2b17fa97cf9c31b87cdf",
273
- );
274
-
275
- const seed = "test-seed";
276
- const counterPartyKey = PrivateKey.fromRandom().pubKey;
277
-
278
- const testData = "This is a test we are going to encrypt";
279
- const ciphertext = bapId.encryptWithSeed(testData, seed, counterPartyKey);
280
- expect(typeof ciphertext).toBe("string");
281
- expect(testData === ciphertext).toBe(false);
282
-
283
- const decrypted = bapId.decryptWithSeed(ciphertext, seed, counterPartyKey);
284
- expect(testData === decrypted).toBe(true);
285
- });
286
- });