@enbox/dwn-sdk-js 0.2.0 → 0.2.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 (29) hide show
  1. package/dist/browser.mjs +8 -8
  2. package/dist/browser.mjs.map +4 -4
  3. package/dist/esm/generated/precompiled-validators.js +164 -52
  4. package/dist/esm/generated/precompiled-validators.js.map +1 -1
  5. package/dist/esm/src/handlers/messages-sync.js +231 -0
  6. package/dist/esm/src/handlers/messages-sync.js.map +1 -1
  7. package/dist/esm/src/handlers/protocols-configure.js +9 -0
  8. package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
  9. package/dist/esm/src/interfaces/messages-sync.js +2 -0
  10. package/dist/esm/src/interfaces/messages-sync.js.map +1 -1
  11. package/dist/esm/tests/handlers/messages-sync.spec.js +147 -0
  12. package/dist/esm/tests/handlers/messages-sync.spec.js.map +1 -1
  13. package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
  14. package/dist/types/src/handlers/messages-sync.d.ts +36 -0
  15. package/dist/types/src/handlers/messages-sync.d.ts.map +1 -1
  16. package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -1
  17. package/dist/types/src/index.d.ts +1 -1
  18. package/dist/types/src/index.d.ts.map +1 -1
  19. package/dist/types/src/interfaces/messages-sync.d.ts +4 -0
  20. package/dist/types/src/interfaces/messages-sync.d.ts.map +1 -1
  21. package/dist/types/src/types/messages-types.d.ts +30 -1
  22. package/dist/types/src/types/messages-types.d.ts.map +1 -1
  23. package/dist/types/tests/handlers/messages-sync.spec.d.ts.map +1 -1
  24. package/package.json +1 -1
  25. package/src/handlers/messages-sync.ts +280 -1
  26. package/src/handlers/protocols-configure.ts +10 -0
  27. package/src/index.ts +1 -1
  28. package/src/interfaces/messages-sync.ts +6 -0
  29. package/src/types/messages-types.ts +31 -1
@@ -6774,7 +6774,7 @@ function validate59(data, { instancePath = "", parentData, parentDataProperty, r
6774
6774
  } validate59.errors = vErrors; return errors === 0; }
6775
6775
  validate59.evaluated = { "props": true, "dynamicProps": false, "dynamicItems": false };
6776
6776
  export const MessagesSync = validate62;
6777
- const schema86 = { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://identity.foundation/dwn/json-schemas/messages-sync.json", "type": "object", "additionalProperties": false, "required": ["authorization", "descriptor"], "properties": { "authorization": { "$ref": "https://identity.foundation/dwn/json-schemas/authorization.json" }, "descriptor": { "type": "object", "additionalProperties": false, "required": ["interface", "method", "messageTimestamp", "action"], "properties": { "interface": { "enum": ["Messages"], "type": "string" }, "method": { "enum": ["Sync"], "type": "string" }, "messageTimestamp": { "$ref": "https://identity.foundation/dwn/json-schemas/defs.json#/$defs/date-time" }, "action": { "enum": ["root", "subtree", "leaves"], "type": "string" }, "protocol": { "type": "string" }, "prefix": { "type": "string", "pattern": "^[01]*$" }, "permissionGrantId": { "type": "string" } }, "allOf": [{ "if": { "properties": { "action": { "const": "subtree" } } }, "then": { "required": ["prefix"] } }, { "if": { "properties": { "action": { "const": "leaves" } } }, "then": { "required": ["prefix"] } }] } } };
6777
+ const schema86 = { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://identity.foundation/dwn/json-schemas/messages-sync.json", "type": "object", "additionalProperties": false, "required": ["authorization", "descriptor"], "properties": { "authorization": { "$ref": "https://identity.foundation/dwn/json-schemas/authorization.json" }, "descriptor": { "type": "object", "additionalProperties": false, "required": ["interface", "method", "messageTimestamp", "action"], "properties": { "interface": { "enum": ["Messages"], "type": "string" }, "method": { "enum": ["Sync"], "type": "string" }, "messageTimestamp": { "$ref": "https://identity.foundation/dwn/json-schemas/defs.json#/$defs/date-time" }, "action": { "enum": ["root", "subtree", "leaves", "diff"], "type": "string" }, "protocol": { "type": "string" }, "prefix": { "type": "string", "pattern": "^[01]*$" }, "permissionGrantId": { "type": "string" }, "hashes": { "type": "object", "additionalProperties": { "type": "string" }, "description": "Map of { bitPrefix: hexHash } for the 'diff' action." }, "depth": { "type": "integer", "minimum": 1, "maximum": 256, "description": "Bit depth at which the client computed its subtree hashes." } }, "allOf": [{ "if": { "properties": { "action": { "const": "subtree" } } }, "then": { "required": ["prefix"] } }, { "if": { "properties": { "action": { "const": "leaves" } } }, "then": { "required": ["prefix"] } }, { "if": { "properties": { "action": { "const": "diff" } } }, "then": { "required": ["hashes", "depth"] } }] } } };
6778
6778
  const pattern37 = new RegExp("^[01]*$", "u");
6779
6779
  function validate62(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { /*# sourceURL="https://identity.foundation/dwn/json-schemas/messages-sync.json" */ ; let vErrors = null; let errors = 0; const evaluated0 = validate62.evaluated; if (evaluated0.dynamicProps) {
6780
6780
  evaluated0.props = undefined;
@@ -6919,65 +6919,120 @@ function validate62(data, { instancePath = "", parentData, parentDataProperty, r
6919
6919
  return false;
6920
6920
  }
6921
6921
  var valid1 = _errs10 === errors;
6922
+ if (valid1) {
6923
+ const _errs15 = errors;
6924
+ const _errs16 = errors;
6925
+ let valid6 = true;
6926
+ const _errs17 = errors;
6927
+ if (data1 && typeof data1 == "object" && !Array.isArray(data1)) {
6928
+ if (data1.action !== undefined) {
6929
+ if ("diff" !== data1.action) {
6930
+ const err4 = {};
6931
+ if (vErrors === null) {
6932
+ vErrors = [err4];
6933
+ }
6934
+ else {
6935
+ vErrors.push(err4);
6936
+ }
6937
+ errors++;
6938
+ }
6939
+ }
6940
+ }
6941
+ var _valid2 = _errs17 === errors;
6942
+ errors = _errs16;
6943
+ if (vErrors !== null) {
6944
+ if (_errs16) {
6945
+ vErrors.length = _errs16;
6946
+ }
6947
+ else {
6948
+ vErrors = null;
6949
+ }
6950
+ }
6951
+ if (_valid2) {
6952
+ const _errs19 = errors;
6953
+ if (data1 && typeof data1 == "object" && !Array.isArray(data1)) {
6954
+ let missing3;
6955
+ if (((data1.hashes === undefined) && (missing3 = "hashes")) || ((data1.depth === undefined) && (missing3 = "depth"))) {
6956
+ validate62.errors = [{ instancePath: instancePath + "/descriptor", schemaPath: "#/properties/descriptor/allOf/2/then/required", keyword: "required", params: { missingProperty: missing3 }, message: "must have required property '" + missing3 + "'" }];
6957
+ return false;
6958
+ }
6959
+ }
6960
+ var _valid2 = _errs19 === errors;
6961
+ valid6 = _valid2;
6962
+ }
6963
+ if (!valid6) {
6964
+ const err5 = { instancePath: instancePath + "/descriptor", schemaPath: "#/properties/descriptor/allOf/2/if", keyword: "if", params: { failingKeyword: "then" }, message: "must match \"then\" schema" };
6965
+ if (vErrors === null) {
6966
+ vErrors = [err5];
6967
+ }
6968
+ else {
6969
+ vErrors.push(err5);
6970
+ }
6971
+ errors++;
6972
+ validate62.errors = vErrors;
6973
+ return false;
6974
+ }
6975
+ var valid1 = _errs15 === errors;
6976
+ }
6922
6977
  }
6923
6978
  if (errors === _errs3) {
6924
6979
  if (data1 && typeof data1 == "object" && !Array.isArray(data1)) {
6925
- let missing3;
6926
- if (((((data1.interface === undefined) && (missing3 = "interface")) || ((data1.method === undefined) && (missing3 = "method"))) || ((data1.messageTimestamp === undefined) && (missing3 = "messageTimestamp"))) || ((data1.action === undefined) && (missing3 = "action"))) {
6927
- validate62.errors = [{ instancePath: instancePath + "/descriptor", schemaPath: "#/properties/descriptor/required", keyword: "required", params: { missingProperty: missing3 }, message: "must have required property '" + missing3 + "'" }];
6980
+ let missing4;
6981
+ if (((((data1.interface === undefined) && (missing4 = "interface")) || ((data1.method === undefined) && (missing4 = "method"))) || ((data1.messageTimestamp === undefined) && (missing4 = "messageTimestamp"))) || ((data1.action === undefined) && (missing4 = "action"))) {
6982
+ validate62.errors = [{ instancePath: instancePath + "/descriptor", schemaPath: "#/properties/descriptor/required", keyword: "required", params: { missingProperty: missing4 }, message: "must have required property '" + missing4 + "'" }];
6928
6983
  return false;
6929
6984
  }
6930
6985
  else {
6931
- const _errs15 = errors;
6986
+ const _errs20 = errors;
6932
6987
  for (const key1 in data1) {
6933
- if (!(((((((key1 === "interface") || (key1 === "method")) || (key1 === "messageTimestamp")) || (key1 === "action")) || (key1 === "protocol")) || (key1 === "prefix")) || (key1 === "permissionGrantId"))) {
6988
+ if (!(func2.call(schema86.properties.descriptor.properties, key1))) {
6934
6989
  validate62.errors = [{ instancePath: instancePath + "/descriptor", schemaPath: "#/properties/descriptor/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key1 }, message: "must NOT have additional properties" }];
6935
6990
  return false;
6936
6991
  break;
6937
6992
  }
6938
6993
  }
6939
- if (_errs15 === errors) {
6994
+ if (_errs20 === errors) {
6940
6995
  if (data1.interface !== undefined) {
6941
- let data4 = data1.interface;
6942
- const _errs16 = errors;
6943
- if (typeof data4 !== "string") {
6996
+ let data5 = data1.interface;
6997
+ const _errs21 = errors;
6998
+ if (typeof data5 !== "string") {
6944
6999
  validate62.errors = [{ instancePath: instancePath + "/descriptor/interface", schemaPath: "#/properties/descriptor/properties/interface/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
6945
7000
  return false;
6946
7001
  }
6947
- if (!(data4 === "Messages")) {
7002
+ if (!(data5 === "Messages")) {
6948
7003
  validate62.errors = [{ instancePath: instancePath + "/descriptor/interface", schemaPath: "#/properties/descriptor/properties/interface/enum", keyword: "enum", params: { allowedValues: schema86.properties.descriptor.properties.interface.enum }, message: "must be equal to one of the allowed values" }];
6949
7004
  return false;
6950
7005
  }
6951
- var valid6 = _errs16 === errors;
7006
+ var valid8 = _errs21 === errors;
6952
7007
  }
6953
7008
  else {
6954
- var valid6 = true;
7009
+ var valid8 = true;
6955
7010
  }
6956
- if (valid6) {
7011
+ if (valid8) {
6957
7012
  if (data1.method !== undefined) {
6958
- let data5 = data1.method;
6959
- const _errs18 = errors;
6960
- if (typeof data5 !== "string") {
7013
+ let data6 = data1.method;
7014
+ const _errs23 = errors;
7015
+ if (typeof data6 !== "string") {
6961
7016
  validate62.errors = [{ instancePath: instancePath + "/descriptor/method", schemaPath: "#/properties/descriptor/properties/method/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
6962
7017
  return false;
6963
7018
  }
6964
- if (!(data5 === "Sync")) {
7019
+ if (!(data6 === "Sync")) {
6965
7020
  validate62.errors = [{ instancePath: instancePath + "/descriptor/method", schemaPath: "#/properties/descriptor/properties/method/enum", keyword: "enum", params: { allowedValues: schema86.properties.descriptor.properties.method.enum }, message: "must be equal to one of the allowed values" }];
6966
7021
  return false;
6967
7022
  }
6968
- var valid6 = _errs18 === errors;
7023
+ var valid8 = _errs23 === errors;
6969
7024
  }
6970
7025
  else {
6971
- var valid6 = true;
7026
+ var valid8 = true;
6972
7027
  }
6973
- if (valid6) {
7028
+ if (valid8) {
6974
7029
  if (data1.messageTimestamp !== undefined) {
6975
- let data6 = data1.messageTimestamp;
6976
- const _errs20 = errors;
6977
- const _errs21 = errors;
6978
- if (errors === _errs21) {
6979
- if (typeof data6 === "string") {
6980
- if (!pattern14.test(data6)) {
7030
+ let data7 = data1.messageTimestamp;
7031
+ const _errs25 = errors;
7032
+ const _errs26 = errors;
7033
+ if (errors === _errs26) {
7034
+ if (typeof data7 === "string") {
7035
+ if (!pattern14.test(data7)) {
6981
7036
  validate62.errors = [{ instancePath: instancePath + "/descriptor/messageTimestamp", schemaPath: "https://identity.foundation/dwn/json-schemas/defs.json#/$defs/date-time/pattern", keyword: "pattern", params: { pattern: "^\\d{4}-[0-1]\\d-[0-3]\\dT(?:[0-2]\\d:[0-5]\\d:[0-5]\\d|23:59:60)\\.\\d{6}Z$" }, message: "must match pattern \"" + "^\\d{4}-[0-1]\\d-[0-3]\\dT(?:[0-2]\\d:[0-5]\\d:[0-5]\\d|23:59:60)\\.\\d{6}Z$" + "\"" }];
6982
7037
  return false;
6983
7038
  }
@@ -6987,47 +7042,47 @@ function validate62(data, { instancePath = "", parentData, parentDataProperty, r
6987
7042
  return false;
6988
7043
  }
6989
7044
  }
6990
- var valid6 = _errs20 === errors;
7045
+ var valid8 = _errs25 === errors;
6991
7046
  }
6992
7047
  else {
6993
- var valid6 = true;
7048
+ var valid8 = true;
6994
7049
  }
6995
- if (valid6) {
7050
+ if (valid8) {
6996
7051
  if (data1.action !== undefined) {
6997
- let data7 = data1.action;
6998
- const _errs23 = errors;
6999
- if (typeof data7 !== "string") {
7052
+ let data8 = data1.action;
7053
+ const _errs28 = errors;
7054
+ if (typeof data8 !== "string") {
7000
7055
  validate62.errors = [{ instancePath: instancePath + "/descriptor/action", schemaPath: "#/properties/descriptor/properties/action/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
7001
7056
  return false;
7002
7057
  }
7003
- if (!(((data7 === "root") || (data7 === "subtree")) || (data7 === "leaves"))) {
7058
+ if (!((((data8 === "root") || (data8 === "subtree")) || (data8 === "leaves")) || (data8 === "diff"))) {
7004
7059
  validate62.errors = [{ instancePath: instancePath + "/descriptor/action", schemaPath: "#/properties/descriptor/properties/action/enum", keyword: "enum", params: { allowedValues: schema86.properties.descriptor.properties.action.enum }, message: "must be equal to one of the allowed values" }];
7005
7060
  return false;
7006
7061
  }
7007
- var valid6 = _errs23 === errors;
7062
+ var valid8 = _errs28 === errors;
7008
7063
  }
7009
7064
  else {
7010
- var valid6 = true;
7065
+ var valid8 = true;
7011
7066
  }
7012
- if (valid6) {
7067
+ if (valid8) {
7013
7068
  if (data1.protocol !== undefined) {
7014
- const _errs25 = errors;
7069
+ const _errs30 = errors;
7015
7070
  if (typeof data1.protocol !== "string") {
7016
7071
  validate62.errors = [{ instancePath: instancePath + "/descriptor/protocol", schemaPath: "#/properties/descriptor/properties/protocol/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
7017
7072
  return false;
7018
7073
  }
7019
- var valid6 = _errs25 === errors;
7074
+ var valid8 = _errs30 === errors;
7020
7075
  }
7021
7076
  else {
7022
- var valid6 = true;
7077
+ var valid8 = true;
7023
7078
  }
7024
- if (valid6) {
7079
+ if (valid8) {
7025
7080
  if (data1.prefix !== undefined) {
7026
- let data9 = data1.prefix;
7027
- const _errs27 = errors;
7028
- if (errors === _errs27) {
7029
- if (typeof data9 === "string") {
7030
- if (!pattern37.test(data9)) {
7081
+ let data10 = data1.prefix;
7082
+ const _errs32 = errors;
7083
+ if (errors === _errs32) {
7084
+ if (typeof data10 === "string") {
7085
+ if (!pattern37.test(data10)) {
7031
7086
  validate62.errors = [{ instancePath: instancePath + "/descriptor/prefix", schemaPath: "#/properties/descriptor/properties/prefix/pattern", keyword: "pattern", params: { pattern: "^[01]*$" }, message: "must match pattern \"" + "^[01]*$" + "\"" }];
7032
7087
  return false;
7033
7088
  }
@@ -7037,22 +7092,79 @@ function validate62(data, { instancePath = "", parentData, parentDataProperty, r
7037
7092
  return false;
7038
7093
  }
7039
7094
  }
7040
- var valid6 = _errs27 === errors;
7095
+ var valid8 = _errs32 === errors;
7041
7096
  }
7042
7097
  else {
7043
- var valid6 = true;
7098
+ var valid8 = true;
7044
7099
  }
7045
- if (valid6) {
7100
+ if (valid8) {
7046
7101
  if (data1.permissionGrantId !== undefined) {
7047
- const _errs29 = errors;
7102
+ const _errs34 = errors;
7048
7103
  if (typeof data1.permissionGrantId !== "string") {
7049
7104
  validate62.errors = [{ instancePath: instancePath + "/descriptor/permissionGrantId", schemaPath: "#/properties/descriptor/properties/permissionGrantId/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
7050
7105
  return false;
7051
7106
  }
7052
- var valid6 = _errs29 === errors;
7107
+ var valid8 = _errs34 === errors;
7053
7108
  }
7054
7109
  else {
7055
- var valid6 = true;
7110
+ var valid8 = true;
7111
+ }
7112
+ if (valid8) {
7113
+ if (data1.hashes !== undefined) {
7114
+ let data12 = data1.hashes;
7115
+ const _errs36 = errors;
7116
+ if (errors === _errs36) {
7117
+ if (data12 && typeof data12 == "object" && !Array.isArray(data12)) {
7118
+ for (const key2 in data12) {
7119
+ const _errs39 = errors;
7120
+ if (typeof data12[key2] !== "string") {
7121
+ validate62.errors = [{ instancePath: instancePath + "/descriptor/hashes/" + key2.replace(/~/g, "~0").replace(/\//g, "~1"), schemaPath: "#/properties/descriptor/properties/hashes/additionalProperties/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
7122
+ return false;
7123
+ }
7124
+ var valid10 = _errs39 === errors;
7125
+ if (!valid10) {
7126
+ break;
7127
+ }
7128
+ }
7129
+ }
7130
+ else {
7131
+ validate62.errors = [{ instancePath: instancePath + "/descriptor/hashes", schemaPath: "#/properties/descriptor/properties/hashes/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
7132
+ return false;
7133
+ }
7134
+ }
7135
+ var valid8 = _errs36 === errors;
7136
+ }
7137
+ else {
7138
+ var valid8 = true;
7139
+ }
7140
+ if (valid8) {
7141
+ if (data1.depth !== undefined) {
7142
+ let data14 = data1.depth;
7143
+ const _errs41 = errors;
7144
+ if (!(((typeof data14 == "number") && (!(data14 % 1) && !isNaN(data14))) && (isFinite(data14)))) {
7145
+ validate62.errors = [{ instancePath: instancePath + "/descriptor/depth", schemaPath: "#/properties/descriptor/properties/depth/type", keyword: "type", params: { type: "integer" }, message: "must be integer" }];
7146
+ return false;
7147
+ }
7148
+ if (errors === _errs41) {
7149
+ if ((typeof data14 == "number") && (isFinite(data14))) {
7150
+ if (data14 > 256 || isNaN(data14)) {
7151
+ validate62.errors = [{ instancePath: instancePath + "/descriptor/depth", schemaPath: "#/properties/descriptor/properties/depth/maximum", keyword: "maximum", params: { comparison: "<=", limit: 256 }, message: "must be <= 256" }];
7152
+ return false;
7153
+ }
7154
+ else {
7155
+ if (data14 < 1 || isNaN(data14)) {
7156
+ validate62.errors = [{ instancePath: instancePath + "/descriptor/depth", schemaPath: "#/properties/descriptor/properties/depth/minimum", keyword: "minimum", params: { comparison: ">=", limit: 1 }, message: "must be >= 1" }];
7157
+ return false;
7158
+ }
7159
+ }
7160
+ }
7161
+ }
7162
+ var valid8 = _errs41 === errors;
7163
+ }
7164
+ else {
7165
+ var valid8 = true;
7166
+ }
7167
+ }
7056
7168
  }
7057
7169
  }
7058
7170
  }