@atcute/cbor 1.0.6 → 1.0.7

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/dist/bytes.js CHANGED
@@ -1,11 +1,11 @@
1
- import { decode, encode } from './base64.js';
1
+ import { fromBase64, toBase64 } from '@atcute/multibase';
2
2
  export class BytesWrapper {
3
3
  buf;
4
4
  constructor(buf) {
5
5
  this.buf = buf;
6
6
  }
7
7
  get $bytes() {
8
- return encode(this.buf);
8
+ return toBase64(this.buf);
9
9
  }
10
10
  toJSON() {
11
11
  return { $bytes: this.$bytes };
@@ -18,6 +18,6 @@ export const fromBytes = (bytes) => {
18
18
  if (bytes instanceof BytesWrapper) {
19
19
  return bytes.buf;
20
20
  }
21
- return decode(bytes.$bytes);
21
+ return fromBase64(bytes.$bytes);
22
22
  };
23
23
  //# sourceMappingURL=bytes.js.map
package/dist/bytes.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bytes.js","sourceRoot":"","sources":["../lib/bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAM7C,MAAM,OAAO,YAAY;IACL;IAAnB,YAAmB,GAAe;QAAf,QAAG,GAAH,GAAG,CAAY;IAAG,CAAC;IAEtC,IAAI,MAAM;QACT,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAED,MAAM;QACL,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC;CACD;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAe,EAAS,EAAE;IACjD,OAAO,IAAI,YAAY,CAAC,GAAG,CAAC,CAAC;AAC9B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAY,EAAc,EAAE;IACrD,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;QACnC,OAAO,KAAK,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAC7B,CAAC,CAAC"}
1
+ {"version":3,"file":"bytes.js","sourceRoot":"","sources":["../lib/bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAMzD,MAAM,OAAO,YAAY;IACL;IAAnB,YAAmB,GAAe;QAAf,QAAG,GAAH,GAAG,CAAY;IAAG,CAAC;IAEtC,IAAI,MAAM;QACT,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,MAAM;QACL,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC;CACD;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAe,EAAS,EAAE;IACjD,OAAO,IAAI,YAAY,CAAC,GAAG,CAAC,CAAC;AAC9B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAY,EAAc,EAAE;IACrD,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;QACnC,OAAO,KAAK,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,OAAO,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC,CAAC"}
package/dist/cid-link.js CHANGED
@@ -1,5 +1,5 @@
1
- import * as base32 from '@atcute/base32';
2
1
  import { decode, parse } from '@atcute/cid';
2
+ import { toBase32 } from '@atcute/multibase';
3
3
  export class CIDLinkWrapper {
4
4
  $bytes;
5
5
  constructor($bytes) {
@@ -9,7 +9,7 @@ export class CIDLinkWrapper {
9
9
  return decode(this.$bytes);
10
10
  }
11
11
  get $link() {
12
- return 'b' + base32.encode(this.$bytes);
12
+ return 'b' + toBase32(this.$bytes);
13
13
  }
14
14
  toJSON() {
15
15
  return { $link: this.$link };
@@ -1 +1 @@
1
- {"version":3,"file":"cid-link.js","sourceRoot":"","sources":["../lib/cid-link.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAY,MAAM,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAMtD,MAAM,OAAO,cAAc;IACP;IAAnB,YAAmB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAEzC,IAAI,IAAI;QACP,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAED,IAAI,KAAK;QACR,OAAO,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,MAAM;QACL,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;CACD;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAuB,EAAW,EAAE;IAC7D,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;QACjC,OAAO,IAAI,cAAc,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,IAAI,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAa,EAAO,EAAE;IACjD,IAAI,IAAI,YAAY,cAAc,EAAE,CAAC;QACpC,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC,CAAC"}
1
+ {"version":3,"file":"cid-link.js","sourceRoot":"","sources":["../lib/cid-link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAM7C,MAAM,OAAO,cAAc;IACP;IAAnB,YAAmB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAEzC,IAAI,IAAI;QACP,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAED,IAAI,KAAK;QACR,OAAO,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAED,MAAM;QACL,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;CACD;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAuB,EAAW,EAAE;IAC7D,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;QACjC,OAAO,IAAI,cAAc,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,IAAI,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAa,EAAO,EAAE;IACjD,IAAI,IAAI,YAAY,cAAc,EAAE,CAAC;QACpC,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC,CAAC"}
package/lib/bytes.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { decode, encode } from './base64.js';
1
+ import { fromBase64, toBase64 } from '@atcute/multibase';
2
2
 
3
3
  export interface Bytes {
4
4
  $bytes: string;
@@ -8,7 +8,7 @@ export class BytesWrapper implements Bytes {
8
8
  constructor(public buf: Uint8Array) {}
9
9
 
10
10
  get $bytes(): string {
11
- return encode(this.buf);
11
+ return toBase64(this.buf);
12
12
  }
13
13
 
14
14
  toJSON(): Bytes {
@@ -25,5 +25,5 @@ export const fromBytes = (bytes: Bytes): Uint8Array => {
25
25
  return bytes.buf;
26
26
  }
27
27
 
28
- return decode(bytes.$bytes);
28
+ return fromBase64(bytes.$bytes);
29
29
  };
package/lib/cid-link.ts CHANGED
@@ -1,5 +1,5 @@
1
- import * as base32 from '@atcute/base32';
2
1
  import { type CID, decode, parse } from '@atcute/cid';
2
+ import { toBase32 } from '@atcute/multibase';
3
3
 
4
4
  export interface CIDLink {
5
5
  $link: string;
@@ -13,7 +13,7 @@ export class CIDLinkWrapper implements CIDLink {
13
13
  }
14
14
 
15
15
  get $link(): string {
16
- return 'b' + base32.encode(this.$bytes);
16
+ return 'b' + toBase32(this.$bytes);
17
17
  }
18
18
 
19
19
  toJSON(): CIDLink {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@atcute/cbor",
4
- "version": "1.0.6",
4
+ "version": "1.0.7",
5
5
  "description": "DAG-CBOR codec that deals in AT Protocol's HTTP wire format",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -24,8 +24,8 @@
24
24
  "mitata": "^1.0.10"
25
25
  },
26
26
  "dependencies": {
27
- "@atcute/base32": "^1.0.1",
28
- "@atcute/cid": "^1.0.2"
27
+ "@atcute/cid": "^1.0.3",
28
+ "@atcute/multibase": "^1.0.0"
29
29
  },
30
30
  "scripts": {
31
31
  "build": "tsc --project tsconfig.build.json",
package/dist/base64.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare const decode: (str: string) => Uint8Array;
2
- export declare const encode: (data: Uint8Array) => string;
package/dist/base64.js DELETED
@@ -1,72 +0,0 @@
1
- const BASE64_CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
2
- const BASE64_BITS = 6;
3
- const BASE64_CODES = /*#__PURE__*/ (() => {
4
- const codes = {};
5
- for (let i = 0, ilen = BASE64_CHARSET.length; i < ilen; i++) {
6
- codes[BASE64_CHARSET[i]] = i;
7
- }
8
- return codes;
9
- })();
10
- export const decode = (str) => {
11
- // Calculate padding
12
- // let end = str.length;
13
- // while (str[end - 1] === '=') {
14
- // --end;
15
- // }
16
- const end = str.length;
17
- // Allocate
18
- const out = new Uint8Array(((end * BASE64_BITS) / 8) | 0);
19
- // Parse
20
- let bits = 0; // Number of bits currently in the buffer
21
- let buffer = 0; // Bits waiting to be written out, MSB first
22
- let written = 0; // Next byte to write
23
- for (let i = 0; i < end; ++i) {
24
- // Read one character from the string:
25
- const value = BASE64_CODES[str[i]];
26
- if (value === undefined) {
27
- throw new SyntaxError(`invalid base64 string`);
28
- }
29
- // Append the bits to the buffer:
30
- buffer = (buffer << BASE64_BITS) | value;
31
- bits += BASE64_BITS;
32
- // Write out some bits if the buffer has a byte's worth:
33
- if (bits >= 8) {
34
- bits -= 8;
35
- out[written++] = 0xff & (buffer >> bits);
36
- }
37
- }
38
- // Verify
39
- if (bits >= BASE64_BITS || (0xff & (buffer << (8 - bits))) !== 0) {
40
- throw new SyntaxError('unexpected end of data');
41
- }
42
- return out;
43
- };
44
- export const encode = (data) => {
45
- // const pad = BASE64_CHARSET[BASE64_CHARSET.length - 1] === '=';
46
- const mask = (1 << BASE64_BITS) - 1;
47
- let out = '';
48
- let bits = 0; // Number of bits currently in the buffer
49
- let buffer = 0; // Bits waiting to be written out, MSB first
50
- for (let i = 0; i < data.length; ++i) {
51
- // Slurp data into the buffer:
52
- buffer = (buffer << 8) | data[i];
53
- bits += 8;
54
- // Write out as much as we can:
55
- while (bits > BASE64_BITS) {
56
- bits -= BASE64_BITS;
57
- out += BASE64_CHARSET[mask & (buffer >> bits)];
58
- }
59
- }
60
- // Partial character:
61
- if (bits !== 0) {
62
- out += BASE64_CHARSET[mask & (buffer << (BASE64_BITS - bits))];
63
- }
64
- // Add padding characters until we hit a byte boundary:
65
- // if (pad) {
66
- // while (((out.length * BASE64_BITS) & 7) !== 0) {
67
- // out += '=';
68
- // }
69
- // }
70
- return out;
71
- };
72
- //# sourceMappingURL=base64.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base64.js","sourceRoot":"","sources":["../lib/base64.ts"],"names":[],"mappings":"AAAA,MAAM,cAAc,GAAG,kEAAkE,CAAC;AAC1F,MAA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AC;QAChB,GAAG,IAAI,cAAc,CAAC,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,uDAAuD;IACvD,aAAa;IACb,oDAAoD;IACpD,gBAAgB;IAChB,KAAK;IACL,IAAI;IAEJ,OAAO,GAAG,CAAC;AACZ,CAAC,CAAC"}
package/lib/base64.ts DELETED
@@ -1,89 +0,0 @@
1
- const BASE64_CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
2
- const BASE64_BITS = 6;
3
-
4
- const BASE64_CODES: Record<string, number> = /*#__PURE__*/ (() => {
5
- const codes: Record<string, number> = {};
6
- for (let i = 0, ilen = BASE64_CHARSET.length; i < ilen; i++) {
7
- codes[BASE64_CHARSET[i]] = i;
8
- }
9
-
10
- return codes;
11
- })();
12
-
13
- export const decode = (str: string): Uint8Array => {
14
- // Calculate padding
15
- // let end = str.length;
16
- // while (str[end - 1] === '=') {
17
- // --end;
18
- // }
19
-
20
- const end = str.length;
21
-
22
- // Allocate
23
- const out = new Uint8Array(((end * BASE64_BITS) / 8) | 0);
24
-
25
- // Parse
26
- let bits = 0; // Number of bits currently in the buffer
27
- let buffer = 0; // Bits waiting to be written out, MSB first
28
- let written = 0; // Next byte to write
29
-
30
- for (let i = 0; i < end; ++i) {
31
- // Read one character from the string:
32
- const value = BASE64_CODES[str[i]];
33
- if (value === undefined) {
34
- throw new SyntaxError(`invalid base64 string`);
35
- }
36
-
37
- // Append the bits to the buffer:
38
- buffer = (buffer << BASE64_BITS) | value;
39
- bits += BASE64_BITS;
40
-
41
- // Write out some bits if the buffer has a byte's worth:
42
- if (bits >= 8) {
43
- bits -= 8;
44
- out[written++] = 0xff & (buffer >> bits);
45
- }
46
- }
47
-
48
- // Verify
49
- if (bits >= BASE64_BITS || (0xff & (buffer << (8 - bits))) !== 0) {
50
- throw new SyntaxError('unexpected end of data');
51
- }
52
-
53
- return out;
54
- };
55
-
56
- export const encode = (data: Uint8Array): string => {
57
- // const pad = BASE64_CHARSET[BASE64_CHARSET.length - 1] === '=';
58
- const mask = (1 << BASE64_BITS) - 1;
59
- let out = '';
60
-
61
- let bits = 0; // Number of bits currently in the buffer
62
- let buffer = 0; // Bits waiting to be written out, MSB first
63
-
64
- for (let i = 0; i < data.length; ++i) {
65
- // Slurp data into the buffer:
66
- buffer = (buffer << 8) | data[i];
67
- bits += 8;
68
-
69
- // Write out as much as we can:
70
- while (bits > BASE64_BITS) {
71
- bits -= BASE64_BITS;
72
- out += BASE64_CHARSET[mask & (buffer >> bits)];
73
- }
74
- }
75
-
76
- // Partial character:
77
- if (bits !== 0) {
78
- out += BASE64_CHARSET[mask & (buffer << (BASE64_BITS - bits))];
79
- }
80
-
81
- // Add padding characters until we hit a byte boundary:
82
- // if (pad) {
83
- // while (((out.length * BASE64_BITS) & 7) !== 0) {
84
- // out += '=';
85
- // }
86
- // }
87
-
88
- return out;
89
- };