wao 0.16.3 → 0.16.5

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.
@@ -1007,7 +1007,7 @@ var Adaptor = /*#__PURE__*/function () {
1007
1007
  });
1008
1008
  case 11:
1009
1009
  slot = message;
1010
- if (!/^--[0-9a-zA-Z_-]{43,44}$/.test(message)) {
1010
+ if (!/^[0-9a-zA-Z_-]{43,44}$/.test(message)) {
1011
1011
  message = (_this$mem$env$process = this.mem.env[process]) === null || _this$mem$env$process === void 0 || (_this$mem$env$process = _this$mem$env$process.results) === null || _this$mem$env$process === void 0 ? void 0 : _this$mem$env$process[slot];
1012
1012
  }
1013
1013
  if (!(0, _ramda.isNil)(message)) {
@@ -1034,14 +1034,10 @@ var Adaptor = /*#__PURE__*/function () {
1034
1034
  });
1035
1035
  case 21:
1036
1036
  res2 = _context24.sent;
1037
- if (!(0, _ramda.isNil)(message)) {
1038
- _context24.next = 24;
1039
- break;
1040
- }
1041
1037
  return _context24.abrupt("return", {
1042
1038
  json: res2
1043
1039
  });
1044
- case 24:
1040
+ case 23:
1045
1041
  case "end":
1046
1042
  return _context24.stop();
1047
1043
  }
@@ -1219,65 +1215,77 @@ var Adaptor = /*#__PURE__*/function () {
1219
1215
  while (1) switch (_context30.prev = _context30.next) {
1220
1216
  case 0:
1221
1217
  query = _ref14.query, params = _ref14.params, body = _ref14.body, headers = _ref14.headers, method = _ref14.method;
1222
- _context30.next = 3;
1218
+ if (body.type === "Buffer" && Array.isArray(body.data)) {
1219
+ body = new Uint8Array(body.data);
1220
+ }
1221
+ valid = false; // todo: cannot verify node -> broser items
1222
+ _context30.prev = 3;
1223
+ _context30.next = 6;
1223
1224
  return _arbundles.DataItem.verify(body);
1224
- case 3:
1225
+ case 6:
1225
1226
  valid = _context30.sent;
1227
+ _context30.next = 12;
1228
+ break;
1229
+ case 9:
1230
+ _context30.prev = 9;
1231
+ _context30.t0 = _context30["catch"](3);
1232
+ console.log(_context30.t0);
1233
+ case 12:
1226
1234
  type = null;
1227
1235
  item = null;
1228
- if (valid) item = new _arbundles.DataItem(body);
1236
+ if (valid || true) item = new _arbundles.DataItem(body);
1229
1237
  _tags = (0, _utils.tags)(item.tags);
1230
1238
  err = null;
1231
1239
  if (!(_tags.Type === "Process")) {
1232
- _context30.next = 16;
1240
+ _context30.next = 24;
1233
1241
  break;
1234
1242
  }
1235
- _context30.next = 12;
1243
+ _context30.next = 20;
1236
1244
  return this.spawn({
1237
1245
  item: item,
1238
1246
  module: _tags.Module,
1239
1247
  scheduler: _tags.Scheduler
1240
1248
  });
1241
- case 12:
1249
+ case 20:
1242
1250
  res = _context30.sent;
1243
1251
  if (!res) err = "bad requrest";
1244
- _context30.next = 22;
1252
+ _context30.next = 30;
1245
1253
  break;
1246
- case 16:
1254
+ case 24:
1247
1255
  if (!(_tags.Type === "Message")) {
1248
- _context30.next = 21;
1256
+ _context30.next = 29;
1249
1257
  break;
1250
1258
  }
1251
- _context30.next = 19;
1259
+ _context30.next = 27;
1252
1260
  return this.message({
1253
1261
  item: item,
1254
1262
  process: item.target
1255
1263
  });
1256
- case 19:
1257
- _context30.next = 22;
1264
+ case 27:
1265
+ _context30.next = 30;
1258
1266
  break;
1259
- case 21:
1267
+ case 29:
1260
1268
  err = true;
1261
- case 22:
1269
+ case 30:
1262
1270
  if (!err) {
1263
- _context30.next = 26;
1271
+ _context30.next = 34;
1264
1272
  break;
1265
1273
  }
1266
1274
  return _context30.abrupt("return", {
1267
1275
  status: 400,
1268
1276
  error: err
1269
1277
  });
1270
- case 26:
1278
+ case 34:
1271
1279
  return _context30.abrupt("return", {
1272
1280
  json: {
1273
1281
  id: item.id
1274
1282
  }
1275
1283
  });
1276
- case 27:
1284
+ case 35:
1277
1285
  case "end":
1278
1286
  return _context30.stop();
1279
1287
  }
1280
- }, _callee30, this);
1288
+ }, _callee30, this, [[3, 9]]);
1281
1289
  }));
1282
1290
  function mu_post_root(_x31) {
1283
1291
  return _mu_post_root.apply(this, arguments);
@@ -682,16 +682,21 @@ var _default = exports["default"] = function _default() {
682
682
  return mem.get("msgs", opt.message);
683
683
  case 7:
684
684
  _opt = _context4.sent;
685
- hash = genHashChain(p.hash, opt.message);
685
+ hash = p.hash;
686
+ try {
687
+ hash = genHashChain(p.hash, opt.message);
688
+ } catch (e) {
689
+ console.log(e);
690
+ }
686
691
  p.hash = hash;
687
692
  _context4.t0 = _utils.buildTags;
688
693
  _context4.t1 = _ramda.mergeLeft;
689
694
  _context4.t2 = (0, _utils.tags)((_opt$tags2 = opt.tags) !== null && _opt$tags2 !== void 0 ? _opt$tags2 : []);
690
695
  _context4.t3 = Date.now();
691
696
  _context4.t4 = p.epochs.length;
692
- _context4.next = 17;
697
+ _context4.next = 18;
693
698
  return mem.get("height");
694
- case 17:
699
+ case 18:
695
700
  _context4.t5 = _context4.sent;
696
701
  _context4.t6 = opt.process;
697
702
  _context4.t7 = opt.message;
@@ -712,81 +717,81 @@ var _default = exports["default"] = function _default() {
712
717
  _context4.t10 = (0, _context4.t1)(_context4.t2, _context4.t9);
713
718
  opt.tags = (0, _context4.t0)(null, _context4.t10);
714
719
  p.epochs.push([opt.message]);
715
- _context4.next = 27;
720
+ _context4.next = 28;
716
721
  return ar.dataitem({
717
722
  data: opt.data,
718
723
  signer: opt.signer,
719
724
  tags: (0, _utils.tags)(opt.tags),
720
725
  target: opt.process
721
726
  });
722
- case 27:
727
+ case 28:
723
728
  _yield$ar$dataitem2 = _context4.sent;
724
729
  id = _yield$ar$dataitem2.id;
725
730
  owner = _yield$ar$dataitem2.owner;
726
731
  item = _yield$ar$dataitem2.item;
727
732
  if (!opt.message_item) {
728
- _context4.next = 36;
733
+ _context4.next = 37;
729
734
  break;
730
735
  }
731
- _context4.next = 34;
736
+ _context4.next = 35;
732
737
  return ar.postItems([opt.message_item, item], su.jwk);
733
- case 34:
734
- _context4.next = 38;
738
+ case 35:
739
+ _context4.next = 39;
735
740
  break;
736
- case 36:
737
- _context4.next = 38;
741
+ case 37:
742
+ _context4.next = 39;
738
743
  return ar.postItems(item, su.jwk);
739
- case 38:
740
- _context4.prev = 38;
744
+ case 39:
745
+ _context4.prev = 39;
741
746
  data = (_opt$data2 = _opt.data) !== null && _opt$data2 !== void 0 ? _opt$data2 : "";
742
747
  _tags = _opt.tags;
743
748
  from = (_ref10 = (_opt$from = _opt.from) !== null && _opt$from !== void 0 ? _opt$from : opt.from) !== null && _ref10 !== void 0 ? _ref10 : owner;
744
749
  if (!_opt.item) {
745
- _context4.next = 59;
750
+ _context4.next = 60;
746
751
  break;
747
752
  }
748
- _context4.prev = 43;
753
+ _context4.prev = 44;
749
754
  data = _base64url["default"].decode(_opt.item.data);
750
755
  _tags = _opt.item.tags;
751
756
  if (from) {
752
- _context4.next = 54;
757
+ _context4.next = 55;
753
758
  break;
754
759
  }
755
760
  raw_owner = _opt.item.rawOwner;
756
761
  _context4.t11 = Buffer;
757
- _context4.next = 51;
762
+ _context4.next = 52;
758
763
  return _crypto["default"].subtle.digest("SHA-256", raw_owner);
759
- case 51:
764
+ case 52:
760
765
  _context4.t12 = _context4.sent;
761
766
  hashBuffer = _context4.t11.from.call(_context4.t11, _context4.t12);
762
767
  from = _base64url["default"].encode(hashBuffer);
763
- case 54:
764
- _context4.next = 59;
768
+ case 55:
769
+ _context4.next = 60;
765
770
  break;
766
- case 56:
767
- _context4.prev = 56;
768
- _context4.t13 = _context4["catch"](43);
771
+ case 57:
772
+ _context4.prev = 57;
773
+ _context4.t13 = _context4["catch"](44);
769
774
  console.log(_context4.t13);
770
- case 59:
771
- _context4.next = 61;
775
+ case 60:
776
+ _context4.next = 62;
772
777
  return genMsg(opt.message, p, data, _tags, from, mu.addr);
773
- case 61:
778
+ case 62:
774
779
  msg = _context4.sent;
775
- _context4.next = 64;
780
+ _context4.next = 65;
776
781
  return genEnv({
777
782
  pid: p.id,
778
783
  owner: p.owner,
779
784
  module: p.module
780
785
  });
781
- case 64:
786
+ case 65:
782
787
  _env = _context4.sent;
783
788
  if (p.handle) {
784
- _context4.next = 97;
789
+ _context4.next = 98;
785
790
  break;
786
791
  }
787
- _context4.next = 68;
792
+ _context4.next = 69;
788
793
  return mem.getWasm(p.modulea);
789
- case 68:
794
+ case 69:
790
795
  _yield$mem$getWasm2 = _context4.sent;
791
796
  format = _yield$mem$getWasm2.format;
792
797
  mod = _yield$mem$getWasm2.mod;
@@ -796,31 +801,31 @@ var _default = exports["default"] = function _default() {
796
801
  _context4.t15 = wasm;
797
802
  _context4.t16 = format;
798
803
  _context4.t17 = wdrive;
799
- _context4.next = 79;
804
+ _context4.next = 80;
800
805
  return mem.getTx(p.id);
801
- case 79:
806
+ case 80:
802
807
  _context4.t19 = _yield$mem$getTx3 = _context4.sent;
803
808
  _context4.t18 = _context4.t19 === null;
804
809
  if (_context4.t18) {
805
- _context4.next = 83;
810
+ _context4.next = 84;
806
811
  break;
807
812
  }
808
813
  _context4.t18 = _yield$mem$getTx3 === void 0;
809
- case 83:
814
+ case 84:
810
815
  if (!_context4.t18) {
811
- _context4.next = 87;
816
+ _context4.next = 88;
812
817
  break;
813
818
  }
814
819
  _context4.t20 = void 0;
815
- _context4.next = 88;
820
+ _context4.next = 89;
816
821
  break;
817
- case 87:
818
- _context4.t20 = _yield$mem$getTx3.item;
819
822
  case 88:
823
+ _context4.t20 = _yield$mem$getTx3.item;
824
+ case 89:
820
825
  _context4.t21 = _context4.t20;
821
- _context4.next = 91;
826
+ _context4.next = 92;
822
827
  return mem.getTx(mod);
823
- case 91:
828
+ case 92:
824
829
  _context4.t22 = _context4.sent;
825
830
  _context4.t23 = {
826
831
  format: _context4.t16,
@@ -828,50 +833,50 @@ var _default = exports["default"] = function _default() {
828
833
  spawn: _context4.t21,
829
834
  module: _context4.t22
830
835
  };
831
- _context4.next = 95;
836
+ _context4.next = 96;
832
837
  return (0, _context4.t14)(_context4.t15, _context4.t23);
833
- case 95:
838
+ case 96:
834
839
  p.handle = _context4.sent;
835
840
  mem.env[opt.process].handle = p.handle;
836
- case 97:
841
+ case 98:
837
842
  if (p.compressed) {
838
843
  start = Date.now();
839
- p.memory = mem.waosm.decompress(p.memory, p.original_size);
844
+ p.memory = mem.decompress(p.memory, p.original_size);
840
845
  p.compressed = false;
841
846
  }
842
- _context4.next = 100;
847
+ _context4.next = 101;
843
848
  return p.handle(p.memory, msg, _env);
844
- case 100:
849
+ case 101:
845
850
  res = _context4.sent;
846
851
  p.memory = res.Memory;
847
852
  delete res.Memory;
848
853
  p.results.push(opt.message);
849
- _context4.next = 106;
854
+ _context4.next = 107;
850
855
  return mem.set(p, "env", opt.process);
851
- case 106:
856
+ case 107:
852
857
  _msg = _objectSpread(_objectSpread({}, (0, _ramda.dissoc)("signer", _opt)), {}, {
853
858
  res: res
854
859
  });
855
- _context4.next = 109;
860
+ _context4.next = 110;
856
861
  return mem.set(_msg, "msgs", opt.message);
857
- case 109:
862
+ case 110:
858
863
  _iterator3 = _createForOfIteratorHelper((_res$Messages = res.Messages) !== null && _res$Messages !== void 0 ? _res$Messages : []);
859
- _context4.prev = 110;
864
+ _context4.prev = 111;
860
865
  _iterator3.s();
861
- case 112:
866
+ case 113:
862
867
  if ((_step3 = _iterator3.n()).done) {
863
- _context4.next = 121;
868
+ _context4.next = 122;
864
869
  break;
865
870
  }
866
871
  v = _step3.value;
867
- _context4.next = 116;
872
+ _context4.next = 117;
868
873
  return mem.get("env", v.Target);
869
- case 116:
874
+ case 117:
870
875
  if (!_context4.sent) {
871
- _context4.next = 119;
876
+ _context4.next = 120;
872
877
  break;
873
878
  }
874
- _context4.next = 119;
879
+ _context4.next = 120;
875
880
  return message({
876
881
  "for": opt.message,
877
882
  process: v.Target,
@@ -880,32 +885,32 @@ var _default = exports["default"] = function _default() {
880
885
  signer: mu.signer,
881
886
  from: opt.process
882
887
  });
883
- case 119:
884
- _context4.next = 112;
888
+ case 120:
889
+ _context4.next = 113;
885
890
  break;
886
- case 121:
887
- _context4.next = 126;
891
+ case 122:
892
+ _context4.next = 127;
888
893
  break;
889
- case 123:
890
- _context4.prev = 123;
891
- _context4.t24 = _context4["catch"](110);
894
+ case 124:
895
+ _context4.prev = 124;
896
+ _context4.t24 = _context4["catch"](111);
892
897
  _iterator3.e(_context4.t24);
893
- case 126:
894
- _context4.prev = 126;
898
+ case 127:
899
+ _context4.prev = 127;
895
900
  _iterator3.f();
896
- return _context4.finish(126);
897
- case 129:
901
+ return _context4.finish(127);
902
+ case 130:
898
903
  _iterator4 = _createForOfIteratorHelper((_res$Spawns = res.Spawns) !== null && _res$Spawns !== void 0 ? _res$Spawns : []);
899
- _context4.prev = 130;
904
+ _context4.prev = 131;
900
905
  _iterator4.s();
901
- case 132:
906
+ case 133:
902
907
  if ((_step4 = _iterator4.n()).done) {
903
- _context4.next = 139;
908
+ _context4.next = 140;
904
909
  break;
905
910
  }
906
911
  _v = _step4.value;
907
912
  __tags = (0, _utils.tags)(_v.Tags);
908
- _context4.next = 137;
913
+ _context4.next = 138;
909
914
  return spawn({
910
915
  "for": opt.message,
911
916
  module: __tags.Module,
@@ -915,87 +920,87 @@ var _default = exports["default"] = function _default() {
915
920
  from: __tags["From-Process"],
916
921
  signer: mu.signer
917
922
  });
918
- case 137:
919
- _context4.next = 132;
923
+ case 138:
924
+ _context4.next = 133;
920
925
  break;
921
- case 139:
922
- _context4.next = 144;
926
+ case 140:
927
+ _context4.next = 145;
923
928
  break;
924
- case 141:
925
- _context4.prev = 141;
926
- _context4.t25 = _context4["catch"](130);
929
+ case 142:
930
+ _context4.prev = 142;
931
+ _context4.t25 = _context4["catch"](131);
927
932
  _iterator4.e(_context4.t25);
928
- case 144:
929
- _context4.prev = 144;
933
+ case 145:
934
+ _context4.prev = 145;
930
935
  _iterator4.f();
931
- return _context4.finish(144);
932
- case 147:
936
+ return _context4.finish(145);
937
+ case 148:
933
938
  _iterator5 = _createForOfIteratorHelper((_res$Assignments = res.Assignments) !== null && _res$Assignments !== void 0 ? _res$Assignments : []);
934
- _context4.prev = 148;
939
+ _context4.prev = 149;
935
940
  _iterator5.s();
936
- case 150:
941
+ case 151:
937
942
  if ((_step5 = _iterator5.n()).done) {
938
- _context4.next = 171;
943
+ _context4.next = 172;
939
944
  break;
940
945
  }
941
946
  _v2 = _step5.value;
942
947
  _iterator6 = _createForOfIteratorHelper(_v2.Processes);
943
- _context4.prev = 153;
948
+ _context4.prev = 154;
944
949
  _iterator6.s();
945
- case 155:
950
+ case 156:
946
951
  if ((_step6 = _iterator6.n()).done) {
947
- _context4.next = 161;
952
+ _context4.next = 162;
948
953
  break;
949
954
  }
950
955
  v2 = _step6.value;
951
- _context4.next = 159;
956
+ _context4.next = 160;
952
957
  return _assign({
953
958
  message: _v2.Message,
954
959
  process: v2,
955
960
  from: opt.process,
956
961
  signer: mu.signer
957
962
  });
958
- case 159:
959
- _context4.next = 155;
963
+ case 160:
964
+ _context4.next = 156;
960
965
  break;
961
- case 161:
962
- _context4.next = 166;
966
+ case 162:
967
+ _context4.next = 167;
963
968
  break;
964
- case 163:
965
- _context4.prev = 163;
966
- _context4.t26 = _context4["catch"](153);
969
+ case 164:
970
+ _context4.prev = 164;
971
+ _context4.t26 = _context4["catch"](154);
967
972
  _iterator6.e(_context4.t26);
968
- case 166:
969
- _context4.prev = 166;
973
+ case 167:
974
+ _context4.prev = 167;
970
975
  _iterator6.f();
971
- return _context4.finish(166);
972
- case 169:
973
- _context4.next = 150;
976
+ return _context4.finish(167);
977
+ case 170:
978
+ _context4.next = 151;
974
979
  break;
975
- case 171:
976
- _context4.next = 176;
980
+ case 172:
981
+ _context4.next = 177;
977
982
  break;
978
- case 173:
979
- _context4.prev = 173;
980
- _context4.t27 = _context4["catch"](148);
983
+ case 174:
984
+ _context4.prev = 174;
985
+ _context4.t27 = _context4["catch"](149);
981
986
  _iterator5.e(_context4.t27);
982
- case 176:
983
- _context4.prev = 176;
987
+ case 177:
988
+ _context4.prev = 177;
984
989
  _iterator5.f();
985
- return _context4.finish(176);
986
- case 179:
990
+ return _context4.finish(177);
991
+ case 180:
987
992
  return _context4.abrupt("return", id);
988
- case 182:
989
- _context4.prev = 182;
990
- _context4.t28 = _context4["catch"](38);
993
+ case 183:
994
+ _context4.prev = 183;
995
+ _context4.t28 = _context4["catch"](39);
991
996
  console.log(_context4.t28);
992
- case 185:
993
- return _context4.abrupt("return", null);
994
997
  case 186:
998
+ return _context4.abrupt("return", null);
999
+ case 187:
995
1000
  case "end":
996
1001
  return _context4.stop();
997
1002
  }
998
- }, _callee4, null, [[38, 182], [43, 56], [110, 123, 126, 129], [130, 141, 144, 147], [148, 173, 176, 179], [153, 163, 166, 169]]);
1003
+ }, _callee4, null, [[39, 183], [44, 57], [111, 124, 127, 130], [131, 142, 145, 148], [149, 174, 177, 180], [154, 164, 167, 170]]);
999
1004
  }));
1000
1005
  return function assign(_x8) {
1001
1006
  return _ref9.apply(this, arguments);
@@ -1003,7 +1008,7 @@ var _default = exports["default"] = function _default() {
1003
1008
  }();
1004
1009
  var message = /*#__PURE__*/function () {
1005
1010
  var _ref11 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(opt) {
1006
- var id, owner, item, _opt$id2, _key, i, _yield$ar$httpmsg2, _p, new_slot, last_slot, _opt$item$id, _opt$item, _opt$owner, _id, _owner, _item, p, _opt$tags3, _yield$mem$getTx$tags3, _yield$mem$getTx4, pr, module, _yield$ar$dataitem3, _msg, _opt, _ref12, _opt$from2, _opt$http_msg$data, from, data, _tags, msg, _env, _yield$mem$getTx5, _yield$mem$getWasm3, format, mod, wasm, wdrive, start, res, _msg2, key;
1011
+ var id, owner, item, _opt$id2, _key, i, _yield$ar$httpmsg2, _p, new_slot, last_slot, _opt$item$id, _opt$item, _opt$owner, p, _opt$tags3, _yield$mem$getTx$tags3, _yield$mem$getTx4, pr, module, _yield$ar$dataitem3, _msg, _opt, _ref12, _opt$from2, _opt$http_msg$data, from, data, _tags, msg, _env, _yield$mem$getTx5, _yield$mem$getWasm3, format, mod, wasm, wdrive, start, res, _msg2, key;
1007
1012
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
1008
1013
  while (1) switch (_context5.prev = _context5.next) {
1009
1014
  case 0:
@@ -1064,9 +1069,9 @@ var _default = exports["default"] = function _default() {
1064
1069
  _context5.next = 38;
1065
1070
  break;
1066
1071
  case 35:
1067
- _id = (_opt$item$id = opt === null || opt === void 0 || (_opt$item = opt.item) === null || _opt$item === void 0 ? void 0 : _opt$item.id) !== null && _opt$item$id !== void 0 ? _opt$item$id : "";
1068
- _owner = (_opt$owner = opt.owner) !== null && _opt$owner !== void 0 ? _opt$owner : "";
1069
- _item = opt.item;
1072
+ id = (_opt$item$id = opt === null || opt === void 0 || (_opt$item = opt.item) === null || _opt$item === void 0 ? void 0 : _opt$item.id) !== null && _opt$item$id !== void 0 ? _opt$item$id : "";
1073
+ owner = (_opt$owner = opt.owner) !== null && _opt$owner !== void 0 ? _opt$owner : "";
1074
+ item = opt.item;
1070
1075
  case 38:
1071
1076
  _context5.next = 40;
1072
1077
  return mem.get("env", opt.process);
@@ -1243,7 +1248,7 @@ var _default = exports["default"] = function _default() {
1243
1248
  case 126:
1244
1249
  if (p.compressed) {
1245
1250
  start = Date.now();
1246
- p.memory = mem.waosm.decompress(p.memory, p.original_size);
1251
+ p.memory = mem.decompress(p.memory, p.original_size);
1247
1252
  p.compressed = false;
1248
1253
  }
1249
1254
  _context5.next = 129;
@@ -1772,7 +1777,7 @@ var _default = exports["default"] = function _default() {
1772
1777
  case 45:
1773
1778
  if (p.compressed) {
1774
1779
  start = Date.now();
1775
- p.memory = mem.waosm.decompress(p.memory, p.original_size);
1780
+ p.memory = mem.decompress(p.memory, p.original_size);
1776
1781
  p.compressed = false;
1777
1782
  }
1778
1783
  _context12.next = 48;
package/cjs/armem-base.js CHANGED
@@ -76,6 +76,18 @@ var ArMemBase = exports["default"] = /*#__PURE__*/function () {
76
76
  this.SU_URL = SU_URL;
77
77
  }
78
78
  return _createClass(ArMemBase, [{
79
+ key: "compress",
80
+ value: function compress(memory) {
81
+ var waosm = new this.Waosm();
82
+ return waosm.compress(memory);
83
+ }
84
+ }, {
85
+ key: "decompress",
86
+ value: function decompress(memory, size) {
87
+ var waosm = new this.Waosm();
88
+ return waosm.decompress(memory, size);
89
+ }
90
+ }, {
79
91
  key: "owner",
80
92
  value: function () {
81
93
  var _owner = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(di) {
@@ -173,10 +185,9 @@ var ArMemBase = exports["default"] = /*#__PURE__*/function () {
173
185
  }
174
186
  memory = val.memory;
175
187
  try {
176
- memory = this.waosm.compress(val.memory);
188
+ memory = this.compress(val.memory);
177
189
  } catch (e) {
178
190
  console.log(e);
179
- memory = (0, _compress.compress)(val.memory);
180
191
  }
181
192
  this[key][field].original_size = val.memory.length;
182
193
  _context3.next = 18;
@@ -328,136 +339,129 @@ var ArMemBase = exports["default"] = /*#__PURE__*/function () {
328
339
  _context5.next = 6;
329
340
  return this._init();
330
341
  case 6:
331
- this.waosm = new this.Waosm();
332
342
  if (!this.db) {
333
- _context5.next = 58;
343
+ _context5.next = 57;
334
344
  break;
335
345
  }
336
346
  _i = 0, _arr = ["height", "blocks"];
337
- case 9:
347
+ case 8:
338
348
  if (!(_i < _arr.length)) {
339
- _context5.next = 17;
349
+ _context5.next = 16;
340
350
  break;
341
351
  }
342
352
  v = _arr[_i];
343
- _context5.next = 13;
353
+ _context5.next = 12;
344
354
  return this.get(v);
345
- case 13:
355
+ case 12:
346
356
  this[v] = _context5.sent;
347
- case 14:
357
+ case 13:
348
358
  _i++;
349
- _context5.next = 9;
359
+ _context5.next = 8;
350
360
  break;
351
- case 17:
361
+ case 16:
352
362
  _i2 = 0, _arr2 = ["items", "txs", "env", "modules", "wasms", "addrmap", "blockmap", "modmap", "msgs"];
353
- case 18:
363
+ case 17:
354
364
  if (!(_i2 < _arr2.length)) {
355
- _context5.next = 56;
365
+ _context5.next = 55;
356
366
  break;
357
367
  }
358
368
  _v = _arr2[_i2];
359
369
  (_this$_v = this[_v]) !== null && _this$_v !== void 0 ? _this$_v : this[_v] = {};
360
- _context5.next = 23;
370
+ _context5.next = 22;
361
371
  return this.db.getKeys({
362
372
  start: _v,
363
373
  end: _v + "a"
364
374
  });
365
- case 23:
375
+ case 22:
366
376
  items = _context5.sent;
367
377
  _iterator = _createForOfIteratorHelper(items || []);
368
- _context5.prev = 25;
378
+ _context5.prev = 24;
369
379
  _iterator.s();
370
- case 27:
380
+ case 26:
371
381
  if ((_step = _iterator.n()).done) {
372
- _context5.next = 45;
382
+ _context5.next = 44;
373
383
  break;
374
384
  }
375
385
  v2 = _step.value;
376
386
  key = v2.split(".")[0];
377
387
  field = v2.split(".")[1];
378
388
  if (!(key === _v)) {
379
- _context5.next = 43;
389
+ _context5.next = 42;
380
390
  break;
381
391
  }
382
392
  if (!key.match(/^env/)) {
383
- _context5.next = 40;
393
+ _context5.next = 39;
384
394
  break;
385
395
  }
386
- _context5.next = 35;
396
+ _context5.next = 34;
387
397
  return this.db.get(v2);
388
- case 35:
398
+ case 34:
389
399
  v3 = _context5.sent;
390
400
  if ((0, _ramda.is)(Uint8Array, v3.memory)) {
391
- try {
392
- v3.compressed = true;
393
- //v3.memory = this.waosm.decompress(v3.memory, v3.original_size)
394
- } catch (e) {
395
- console.log(e);
396
- v3.memory = (0, _compress.decompress)(v3.memory);
397
- }
401
+ v3.compressed = true;
398
402
  }
399
403
  this[_v][field] = v3;
400
- _context5.next = 43;
401
- break;
402
- case 40:
403
404
  _context5.next = 42;
405
+ break;
406
+ case 39:
407
+ _context5.next = 41;
404
408
  return this.db.get(v2);
405
- case 42:
409
+ case 41:
406
410
  this[_v][field] = _context5.sent;
407
- case 43:
408
- _context5.next = 27;
411
+ case 42:
412
+ _context5.next = 26;
409
413
  break;
410
- case 45:
411
- _context5.next = 50;
414
+ case 44:
415
+ _context5.next = 49;
412
416
  break;
413
- case 47:
414
- _context5.prev = 47;
415
- _context5.t0 = _context5["catch"](25);
417
+ case 46:
418
+ _context5.prev = 46;
419
+ _context5.t0 = _context5["catch"](24);
416
420
  _iterator.e(_context5.t0);
417
- case 50:
418
- _context5.prev = 50;
421
+ case 49:
422
+ _context5.prev = 49;
419
423
  _iterator.f();
420
- return _context5.finish(50);
421
- case 53:
424
+ return _context5.finish(49);
425
+ case 52:
422
426
  _i2++;
423
- _context5.next = 18;
427
+ _context5.next = 17;
424
428
  break;
425
- case 56:
426
- _context5.next = 74;
429
+ case 55:
430
+ _context5.next = 73;
427
431
  break;
428
- case 58:
432
+ case 57:
429
433
  _i3 = 0, _arr3 = ["height", "blocks"];
430
- case 59:
434
+ case 58:
431
435
  if (!(_i3 < _arr3.length)) {
432
- _context5.next = 66;
436
+ _context5.next = 65;
433
437
  break;
434
438
  }
435
439
  _v2 = _arr3[_i3];
436
- _context5.next = 63;
440
+ _context5.next = 62;
437
441
  return this.set(this[_v2], _v2);
438
- case 63:
442
+ case 62:
439
443
  _i3++;
440
- _context5.next = 59;
444
+ _context5.next = 58;
441
445
  break;
442
- case 66:
446
+ case 65:
443
447
  _i4 = 0, _arr4 = ["modules", "wasms", "addrmap", "blockmap"];
444
- case 67:
448
+ case 66:
445
449
  if (!(_i4 < _arr4.length)) {
446
- _context5.next = 74;
450
+ _context5.next = 73;
447
451
  break;
448
452
  }
449
453
  _v3 = _arr4[_i4];
450
- _context5.next = 71;
454
+ _context5.next = 70;
451
455
  return this.putAll(_v3);
452
- case 71:
456
+ case 70:
453
457
  _i4++;
454
- _context5.next = 67;
458
+ _context5.next = 66;
455
459
  break;
456
- case 74:
460
+ case 73:
457
461
  case "end":
458
462
  return _context5.stop();
459
463
  }
460
- }, _callee5, this, [[25, 47, 50, 53]]);
464
+ }, _callee5, this, [[24, 46, 49, 52]]);
461
465
  }));
462
466
  function init() {
463
467
  return _init.apply(this, arguments);
@@ -324,7 +324,7 @@ class Adaptor {
324
324
  }
325
325
  }
326
326
  const slot = message
327
- if (!/^--[0-9a-zA-Z_-]{43,44}$/.test(message)) {
327
+ if (!/^[0-9a-zA-Z_-]{43,44}$/.test(message)) {
328
328
  message = this.mem.env[process]?.results?.[slot]
329
329
  }
330
330
  if (isNil(message)) {
@@ -333,7 +333,7 @@ class Adaptor {
333
333
  if (isNil(message)) return { status: 404, error: "not Found" }
334
334
  }
335
335
  const res2 = await this.result({ message, process })
336
- if (isNil(message)) return { json: res2 }
336
+ return { json: res2 }
337
337
  }
338
338
 
339
339
  async su_get_root({ query, params, body, headers, method }) {
@@ -388,10 +388,19 @@ class Adaptor {
388
388
  }
389
389
 
390
390
  async mu_post_root({ query, params, body, headers, method }) {
391
- let valid = await DataItem.verify(body)
391
+ if (body.type === "Buffer" && Array.isArray(body.data)) {
392
+ body = new Uint8Array(body.data)
393
+ }
394
+ let valid = false
395
+ // todo: cannot verify node -> broser items
396
+ try {
397
+ valid = await DataItem.verify(body)
398
+ } catch (e) {
399
+ console.log(e)
400
+ }
392
401
  let type = null
393
402
  let item = null
394
- if (valid) item = new DataItem(body)
403
+ if (valid || true) item = new DataItem(body)
395
404
  const _tags = tags(item.tags)
396
405
  let err = null
397
406
  if (_tags.Type === "Process") {
@@ -269,7 +269,12 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
269
269
  const p = await mem.get("env", opt.process)
270
270
  if (!p || !opt.process) return null
271
271
  let _opt = await mem.get("msgs", opt.message)
272
- let hash = genHashChain(p.hash, opt.message)
272
+ let hash = p.hash
273
+ try {
274
+ hash = genHashChain(p.hash, opt.message)
275
+ } catch (e) {
276
+ console.log(e)
277
+ }
273
278
  p.hash = hash
274
279
  opt.tags = buildTags(
275
280
  null,
@@ -338,7 +343,7 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
338
343
  }
339
344
  if (p.compressed) {
340
345
  const start = Date.now()
341
- p.memory = mem.waosm.decompress(p.memory, p.original_size)
346
+ p.memory = mem.decompress(p.memory, p.original_size)
342
347
  p.compressed = false
343
348
  }
344
349
  const res = await p.handle(p.memory, msg, _env)
@@ -415,9 +420,9 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
415
420
  }
416
421
  }
417
422
  } else {
418
- let id = opt?.item?.id ?? ""
419
- let owner = opt.owner ?? ""
420
- let item = opt.item
423
+ id = opt?.item?.id ?? ""
424
+ owner = opt.owner ?? ""
425
+ item = opt.item
421
426
  }
422
427
 
423
428
  const p = await mem.get("env", opt.process)
@@ -476,7 +481,7 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
476
481
  }
477
482
  if (p.compressed) {
478
483
  const start = Date.now()
479
- p.memory = mem.waosm.decompress(p.memory, p.original_size)
484
+ p.memory = mem.decompress(p.memory, p.original_size)
480
485
  p.compressed = false
481
486
  }
482
487
  const res = await p.handle(p.memory, msg, _env)
@@ -669,7 +674,7 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
669
674
  }
670
675
  if (p.compressed) {
671
676
  const start = Date.now()
672
- p.memory = mem.waosm.decompress(p.memory, p.original_size)
677
+ p.memory = mem.decompress(p.memory, p.original_size)
673
678
  p.compressed = false
674
679
  }
675
680
  const res = await p.handle(p.memory, msg, _env)
package/esm/armem-base.js CHANGED
@@ -45,6 +45,15 @@ export default class ArMemBase {
45
45
  this.scheduler = scheduler
46
46
  this.SU_URL = SU_URL
47
47
  }
48
+ compress(memory) {
49
+ const waosm = new this.Waosm()
50
+ return waosm.compress(memory)
51
+ }
52
+ decompress(memory, size) {
53
+ const waosm = new this.Waosm()
54
+ return waosm.decompress(memory, size)
55
+ }
56
+
48
57
  async owner(di) {
49
58
  return base64url.encode(
50
59
  Buffer.from(await crypto.subtle.digest("SHA-256", di.rawOwner))
@@ -72,10 +81,9 @@ export default class ArMemBase {
72
81
  if (key === "env") {
73
82
  let memory = val.memory
74
83
  try {
75
- memory = this.waosm.compress(val.memory)
84
+ memory = this.compress(val.memory)
76
85
  } catch (e) {
77
86
  console.log(e)
78
- memory = compress(val.memory)
79
87
  }
80
88
  this[key][field].original_size = val.memory.length
81
89
  await this.db.put(
@@ -162,7 +170,6 @@ export default class ArMemBase {
162
170
  if (this.isInit) return
163
171
  this.isInit = true
164
172
  if (typeof this._init === "function") await this._init()
165
- this.waosm = new this.Waosm()
166
173
  if (this.db) {
167
174
  for (const v of ["height", "blocks"]) this[v] = await this.get(v)
168
175
  for (const v of [
@@ -185,13 +192,7 @@ export default class ArMemBase {
185
192
  if (key.match(/^env/)) {
186
193
  let v3 = await this.db.get(v2)
187
194
  if (is(Uint8Array, v3.memory)) {
188
- try {
189
- v3.compressed = true
190
- //v3.memory = this.waosm.decompress(v3.memory, v3.original_size)
191
- } catch (e) {
192
- console.log(e)
193
- v3.memory = decompress(v3.memory)
194
- }
195
+ v3.compressed = true
195
196
  }
196
197
  this[v][field] = v3
197
198
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wao",
3
- "version": "0.16.3",
3
+ "version": "0.16.5",
4
4
  "bin": {
5
5
  "wao": "./cjs/cli.js",
6
6
  "wao-esm": "./esm/cli.js"