@icp-sdk/core 5.3.1 → 6.0.0
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/lib/cjs/agent/actor.d.ts +7 -3
- package/lib/cjs/agent/actor.d.ts.map +1 -1
- package/lib/cjs/agent/actor.js +18 -5
- package/lib/cjs/agent/actor.js.map +1 -1
- package/lib/cjs/agent/agent/api.d.ts +35 -6
- package/lib/cjs/agent/agent/api.d.ts.map +1 -1
- package/lib/cjs/agent/agent/api.js.map +1 -1
- package/lib/cjs/agent/agent/http/index.d.ts +11 -25
- package/lib/cjs/agent/agent/http/index.d.ts.map +1 -1
- package/lib/cjs/agent/agent/http/index.js +198 -173
- package/lib/cjs/agent/agent/http/index.js.map +1 -1
- package/lib/cjs/agent/auth.d.ts +6 -5
- package/lib/cjs/agent/auth.d.ts.map +1 -1
- package/lib/cjs/agent/auth.js +3 -3
- package/lib/cjs/agent/auth.js.map +1 -1
- package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -1
- package/lib/cjs/agent/canisterStatus/index.js +10 -10
- package/lib/cjs/agent/canisterStatus/index.js.map +1 -1
- package/lib/cjs/agent/cbor.d.ts +2 -1
- package/lib/cjs/agent/cbor.d.ts.map +1 -1
- package/lib/cjs/agent/cbor.js +4 -1
- package/lib/cjs/agent/cbor.js.map +1 -1
- package/lib/cjs/agent/certificate.d.ts +5 -4
- package/lib/cjs/agent/certificate.d.ts.map +1 -1
- package/lib/cjs/agent/certificate.js +14 -18
- package/lib/cjs/agent/certificate.js.map +1 -1
- package/lib/cjs/agent/der.d.ts +3 -2
- package/lib/cjs/agent/der.d.ts.map +1 -1
- package/lib/cjs/agent/der.js.map +1 -1
- package/lib/cjs/agent/errors.d.ts +7 -1
- package/lib/cjs/agent/errors.d.ts.map +1 -1
- package/lib/cjs/agent/errors.js +34 -16
- package/lib/cjs/agent/errors.js.map +1 -1
- package/lib/cjs/agent/polling/index.d.ts +3 -4
- package/lib/cjs/agent/polling/index.d.ts.map +1 -1
- package/lib/cjs/agent/polling/index.js +17 -10
- package/lib/cjs/agent/polling/index.js.map +1 -1
- package/lib/cjs/agent/polling/strategy.d.ts.map +1 -1
- package/lib/cjs/agent/polling/strategy.js +6 -6
- package/lib/cjs/agent/polling/strategy.js.map +1 -1
- package/lib/cjs/agent/polling/types.d.ts +3 -4
- package/lib/cjs/agent/polling/types.d.ts.map +1 -1
- package/lib/cjs/agent/public_key.d.ts +3 -2
- package/lib/cjs/agent/public_key.d.ts.map +1 -1
- package/lib/cjs/agent/public_key.js +2 -2
- package/lib/cjs/agent/public_key.js.map +1 -1
- package/lib/cjs/agent/request_id.js +10 -10
- package/lib/cjs/agent/request_id.js.map +1 -1
- package/lib/cjs/agent/subnetStatus/index.js +7 -7
- package/lib/cjs/agent/subnetStatus/index.js.map +1 -1
- package/lib/cjs/agent/utils/bls.d.ts.map +1 -1
- package/lib/cjs/agent/utils/bls.js +7 -6
- package/lib/cjs/agent/utils/bls.js.map +1 -1
- package/lib/cjs/agent/utils/readState.d.ts +2 -2
- package/lib/cjs/agent/utils/readState.d.ts.map +1 -1
- package/lib/cjs/agent/utils/readState.js +4 -4
- package/lib/cjs/agent/utils/readState.js.map +1 -1
- package/lib/cjs/agent/utils/target.d.ts +15 -0
- package/lib/cjs/agent/utils/target.d.ts.map +1 -0
- package/lib/cjs/agent/utils/target.js +27 -0
- package/lib/cjs/agent/utils/target.js.map +1 -0
- package/lib/cjs/candid/utils/buffer.d.ts +2 -1
- package/lib/cjs/candid/utils/buffer.d.ts.map +1 -1
- package/lib/cjs/candid/utils/buffer.js +5 -2
- package/lib/cjs/candid/utils/buffer.js.map +1 -1
- package/lib/cjs/identity/identity/attributes.d.ts +6 -2
- package/lib/cjs/identity/identity/attributes.d.ts.map +1 -1
- package/lib/cjs/identity/identity/attributes.js +9 -1
- package/lib/cjs/identity/identity/attributes.js.map +1 -1
- package/lib/cjs/identity/identity/delegation.d.ts +10 -3
- package/lib/cjs/identity/identity/delegation.d.ts.map +1 -1
- package/lib/cjs/identity/identity/delegation.js +25 -12
- package/lib/cjs/identity/identity/delegation.js.map +1 -1
- package/lib/cjs/identity/identity/ecdsa.d.ts +2 -2
- package/lib/cjs/identity/identity/ecdsa.d.ts.map +1 -1
- package/lib/cjs/identity/identity/ecdsa.js +3 -2
- package/lib/cjs/identity/identity/ecdsa.js.map +1 -1
- package/lib/cjs/identity/identity/ed25519.d.ts +3 -2
- package/lib/cjs/identity/identity/ed25519.d.ts.map +1 -1
- package/lib/cjs/identity/identity/ed25519.js +18 -15
- package/lib/cjs/identity/identity/ed25519.js.map +1 -1
- package/lib/cjs/identity/identity/webauthn.d.ts +4 -3
- package/lib/cjs/identity/identity/webauthn.d.ts.map +1 -1
- package/lib/cjs/identity/identity/webauthn.js +12 -11
- package/lib/cjs/identity/identity/webauthn.js.map +1 -1
- package/lib/cjs/identity/secp256k1/der.d.ts +2 -1
- package/lib/cjs/identity/secp256k1/der.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/der.js.map +1 -1
- package/lib/cjs/identity/secp256k1/pem.d.ts +4 -3
- package/lib/cjs/identity/secp256k1/pem.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/pem.js +2 -2
- package/lib/cjs/identity/secp256k1/pem.js.map +1 -1
- package/lib/cjs/identity/secp256k1/secp256k1.d.ts +5 -4
- package/lib/cjs/identity/secp256k1/secp256k1.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/secp256k1.js +17 -20
- package/lib/cjs/identity/secp256k1/secp256k1.js.map +1 -1
- package/lib/cjs/principal/principal.js +5 -5
- package/lib/cjs/principal/principal.js.map +1 -1
- package/lib/esm/agent/actor.d.ts +7 -3
- package/lib/esm/agent/actor.d.ts.map +1 -1
- package/lib/esm/agent/actor.js +18 -5
- package/lib/esm/agent/actor.js.map +1 -1
- package/lib/esm/agent/agent/api.d.ts +35 -6
- package/lib/esm/agent/agent/api.d.ts.map +1 -1
- package/lib/esm/agent/agent/api.js.map +1 -1
- package/lib/esm/agent/agent/http/index.d.ts +11 -25
- package/lib/esm/agent/agent/http/index.d.ts.map +1 -1
- package/lib/esm/agent/agent/http/index.js +191 -166
- package/lib/esm/agent/agent/http/index.js.map +1 -1
- package/lib/esm/agent/auth.d.ts +6 -5
- package/lib/esm/agent/auth.d.ts.map +1 -1
- package/lib/esm/agent/auth.js +1 -1
- package/lib/esm/agent/auth.js.map +1 -1
- package/lib/esm/agent/canister-env/index.js +1 -1
- package/lib/esm/agent/canister-env/index.js.map +1 -1
- package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -1
- package/lib/esm/agent/canisterStatus/index.js +2 -2
- package/lib/esm/agent/canisterStatus/index.js.map +1 -1
- package/lib/esm/agent/cbor.d.ts +2 -1
- package/lib/esm/agent/cbor.d.ts.map +1 -1
- package/lib/esm/agent/cbor.js +4 -1
- package/lib/esm/agent/cbor.js.map +1 -1
- package/lib/esm/agent/certificate.d.ts +5 -4
- package/lib/esm/agent/certificate.d.ts.map +1 -1
- package/lib/esm/agent/certificate.js +5 -9
- package/lib/esm/agent/certificate.js.map +1 -1
- package/lib/esm/agent/der.d.ts +3 -2
- package/lib/esm/agent/der.d.ts.map +1 -1
- package/lib/esm/agent/der.js.map +1 -1
- package/lib/esm/agent/errors.d.ts +7 -1
- package/lib/esm/agent/errors.d.ts.map +1 -1
- package/lib/esm/agent/errors.js +18 -1
- package/lib/esm/agent/errors.js.map +1 -1
- package/lib/esm/agent/polling/index.d.ts +3 -4
- package/lib/esm/agent/polling/index.d.ts.map +1 -1
- package/lib/esm/agent/polling/index.js +15 -8
- package/lib/esm/agent/polling/index.js.map +1 -1
- package/lib/esm/agent/polling/strategy.d.ts.map +1 -1
- package/lib/esm/agent/polling/strategy.js +6 -6
- package/lib/esm/agent/polling/strategy.js.map +1 -1
- package/lib/esm/agent/polling/types.d.ts +3 -4
- package/lib/esm/agent/polling/types.d.ts.map +1 -1
- package/lib/esm/agent/public_key.d.ts +3 -2
- package/lib/esm/agent/public_key.d.ts.map +1 -1
- package/lib/esm/agent/public_key.js +2 -2
- package/lib/esm/agent/public_key.js.map +1 -1
- package/lib/esm/agent/request_id.js +2 -2
- package/lib/esm/agent/request_id.js.map +1 -1
- package/lib/esm/agent/subnetStatus/index.js +1 -1
- package/lib/esm/agent/subnetStatus/index.js.map +1 -1
- package/lib/esm/agent/utils/bls.d.ts.map +1 -1
- package/lib/esm/agent/utils/bls.js +7 -6
- package/lib/esm/agent/utils/bls.js.map +1 -1
- package/lib/esm/agent/utils/readState.d.ts +2 -2
- package/lib/esm/agent/utils/readState.d.ts.map +1 -1
- package/lib/esm/agent/utils/readState.js +1 -1
- package/lib/esm/agent/utils/readState.js.map +1 -1
- package/lib/esm/agent/utils/target.d.ts +15 -0
- package/lib/esm/agent/utils/target.d.ts.map +1 -0
- package/lib/esm/agent/utils/target.js +23 -0
- package/lib/esm/agent/utils/target.js.map +1 -0
- package/lib/esm/candid/utils/buffer.d.ts +2 -1
- package/lib/esm/candid/utils/buffer.d.ts.map +1 -1
- package/lib/esm/candid/utils/buffer.js +5 -2
- package/lib/esm/candid/utils/buffer.js.map +1 -1
- package/lib/esm/identity/identity/attributes.d.ts +6 -2
- package/lib/esm/identity/identity/attributes.d.ts.map +1 -1
- package/lib/esm/identity/identity/attributes.js +9 -1
- package/lib/esm/identity/identity/attributes.js.map +1 -1
- package/lib/esm/identity/identity/delegation.d.ts +10 -3
- package/lib/esm/identity/identity/delegation.d.ts.map +1 -1
- package/lib/esm/identity/identity/delegation.js +22 -9
- package/lib/esm/identity/identity/delegation.js.map +1 -1
- package/lib/esm/identity/identity/ecdsa.d.ts +2 -2
- package/lib/esm/identity/identity/ecdsa.d.ts.map +1 -1
- package/lib/esm/identity/identity/ecdsa.js +3 -2
- package/lib/esm/identity/identity/ecdsa.js.map +1 -1
- package/lib/esm/identity/identity/ed25519.d.ts +3 -2
- package/lib/esm/identity/identity/ed25519.d.ts.map +1 -1
- package/lib/esm/identity/identity/ed25519.js +10 -7
- package/lib/esm/identity/identity/ed25519.js.map +1 -1
- package/lib/esm/identity/identity/webauthn.d.ts +4 -3
- package/lib/esm/identity/identity/webauthn.d.ts.map +1 -1
- package/lib/esm/identity/identity/webauthn.js +8 -7
- package/lib/esm/identity/identity/webauthn.js.map +1 -1
- package/lib/esm/identity/secp256k1/der.d.ts +2 -1
- package/lib/esm/identity/secp256k1/der.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/der.js.map +1 -1
- package/lib/esm/identity/secp256k1/pem.d.ts +4 -3
- package/lib/esm/identity/secp256k1/pem.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/pem.js +2 -2
- package/lib/esm/identity/secp256k1/pem.js.map +1 -1
- package/lib/esm/identity/secp256k1/secp256k1.d.ts +5 -4
- package/lib/esm/identity/secp256k1/secp256k1.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/secp256k1.js +10 -13
- package/lib/esm/identity/secp256k1/secp256k1.js.map +1 -1
- package/lib/esm/principal/principal.js +2 -2
- package/lib/esm/principal/principal.js.map +1 -1
- package/package.json +20 -10
- package/src/agent/actor.ts +0 -524
- package/src/agent/agent/api.ts +0 -292
- package/src/agent/agent/http/expiry.ts +0 -107
- package/src/agent/agent/http/index.ts +0 -1727
- package/src/agent/agent/http/transforms.ts +0 -54
- package/src/agent/agent/http/types.ts +0 -145
- package/src/agent/agent/index.ts +0 -4
- package/src/agent/auth.ts +0 -147
- package/src/agent/canister-env/index.ts +0 -192
- package/src/agent/canisterStatus/index.ts +0 -260
- package/src/agent/cbor.ts +0 -63
- package/src/agent/certificate.ts +0 -1058
- package/src/agent/constants.ts +0 -24
- package/src/agent/der.ts +0 -191
- package/src/agent/errors.ts +0 -962
- package/src/agent/fetch_candid.ts +0 -37
- package/src/agent/index.ts +0 -130
- package/src/agent/observable.ts +0 -49
- package/src/agent/polling/backoff.ts +0 -129
- package/src/agent/polling/index.ts +0 -238
- package/src/agent/polling/strategy.ts +0 -140
- package/src/agent/polling/types.ts +0 -28
- package/src/agent/public_key.ts +0 -65
- package/src/agent/request_id.ts +0 -99
- package/src/agent/subnetStatus/index.ts +0 -263
- package/src/agent/utils/bls.ts +0 -18
- package/src/agent/utils/buffer.ts +0 -64
- package/src/agent/utils/certificateReject.ts +0 -25
- package/src/agent/utils/createExpirableStore.ts +0 -31
- package/src/agent/utils/expirableStore.ts +0 -47
- package/src/agent/utils/inMemoryExpirableStore.ts +0 -49
- package/src/agent/utils/indexedDBExpirableStore.ts +0 -191
- package/src/agent/utils/leb.ts +0 -14
- package/src/agent/utils/random.ts +0 -30
- package/src/agent/utils/readState.ts +0 -180
- package/src/candid/candid-core.ts +0 -274
- package/src/candid/candid-ui.ts +0 -281
- package/src/candid/idl.ts +0 -2654
- package/src/candid/index.ts +0 -35
- package/src/candid/types.ts +0 -7
- package/src/candid/utils/bigint-math.ts +0 -26
- package/src/candid/utils/buffer.ts +0 -221
- package/src/candid/utils/hash.ts +0 -31
- package/src/candid/utils/leb128.ts +0 -233
- package/src/identity/identity/attributes.ts +0 -84
- package/src/identity/identity/delegation.ts +0 -411
- package/src/identity/identity/ecdsa.ts +0 -162
- package/src/identity/identity/ed25519.ts +0 -246
- package/src/identity/identity/partial.ts +0 -60
- package/src/identity/identity/webauthn.ts +0 -265
- package/src/identity/index.ts +0 -44
- package/src/identity/secp256k1/der.ts +0 -177
- package/src/identity/secp256k1/index.ts +0 -52
- package/src/identity/secp256k1/pem.ts +0 -39
- package/src/identity/secp256k1/secp256k1.ts +0 -276
- package/src/index.ts +0 -3
- package/src/principal/index.ts +0 -19
- package/src/principal/principal.ts +0 -181
- package/src/principal/utils/base32.ts +0 -101
- package/src/principal/utils/getCrc.ts +0 -52
package/src/agent/constants.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// Default delta for ingress expiry is 5 minutes.
|
|
2
|
-
export const DEFAULT_INGRESS_EXPIRY_DELTA_IN_MSECS = 5 * 60 * 1000;
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The `\x0Dic-state-root` domain separator used in the root hash of IC certificates.
|
|
6
|
-
*/
|
|
7
|
-
export const IC_STATE_ROOT_DOMAIN_SEPARATOR = new TextEncoder().encode('\x0Dic-state-root');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The `\x0Aic-request` domain separator used in the signature of IC requests.
|
|
11
|
-
*/
|
|
12
|
-
export const IC_REQUEST_DOMAIN_SEPARATOR = new TextEncoder().encode('\x0Aic-request');
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* The `\x0Bic-response` domain separator used in the signature of IC responses.
|
|
16
|
-
*/
|
|
17
|
-
export const IC_RESPONSE_DOMAIN_SEPARATOR = new TextEncoder().encode('\x0Bic-response');
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The `\x1Aic-request-auth-delegation` domain separator used in the signature of delegations.
|
|
21
|
-
*/
|
|
22
|
-
export const IC_REQUEST_AUTH_DELEGATION_DOMAIN_SEPARATOR = new TextEncoder().encode(
|
|
23
|
-
'\x1Aic-request-auth-delegation',
|
|
24
|
-
);
|
package/src/agent/der.ts
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DerDecodeErrorCode,
|
|
3
|
-
DerDecodeLengthMismatchErrorCode,
|
|
4
|
-
DerEncodeErrorCode,
|
|
5
|
-
InputError,
|
|
6
|
-
} from './errors.ts';
|
|
7
|
-
import { uint8Equals } from './utils/buffer.ts';
|
|
8
|
-
|
|
9
|
-
export const encodeLenBytes = (len: number): number => {
|
|
10
|
-
if (len <= 0x7f) {
|
|
11
|
-
return 1;
|
|
12
|
-
}
|
|
13
|
-
if (len <= 0xff) {
|
|
14
|
-
return 2;
|
|
15
|
-
}
|
|
16
|
-
if (len <= 0xffff) {
|
|
17
|
-
return 3;
|
|
18
|
-
}
|
|
19
|
-
if (len <= 0xffffff) {
|
|
20
|
-
return 4;
|
|
21
|
-
}
|
|
22
|
-
throw InputError.fromCode(new DerEncodeErrorCode('Length too long (> 4 bytes)'));
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const encodeLen = (buf: Uint8Array, offset: number, len: number): number => {
|
|
26
|
-
if (len <= 0x7f) {
|
|
27
|
-
buf[offset] = len;
|
|
28
|
-
return 1;
|
|
29
|
-
}
|
|
30
|
-
if (len <= 0xff) {
|
|
31
|
-
buf[offset] = 0x81;
|
|
32
|
-
buf[offset + 1] = len;
|
|
33
|
-
return 2;
|
|
34
|
-
}
|
|
35
|
-
if (len <= 0xffff) {
|
|
36
|
-
buf[offset] = 0x82;
|
|
37
|
-
buf[offset + 1] = len >> 8;
|
|
38
|
-
buf[offset + 2] = len;
|
|
39
|
-
return 3;
|
|
40
|
-
}
|
|
41
|
-
if (len <= 0xffffff) {
|
|
42
|
-
buf[offset] = 0x83;
|
|
43
|
-
buf[offset + 1] = len >> 16;
|
|
44
|
-
buf[offset + 2] = len >> 8;
|
|
45
|
-
buf[offset + 3] = len;
|
|
46
|
-
return 4;
|
|
47
|
-
}
|
|
48
|
-
throw InputError.fromCode(new DerEncodeErrorCode('Length too long (> 4 bytes)'));
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const decodeLenBytes = (buf: Uint8Array, offset: number): number => {
|
|
52
|
-
if (buf[offset] < 0x80) {
|
|
53
|
-
return 1;
|
|
54
|
-
}
|
|
55
|
-
if (buf[offset] === 0x80) {
|
|
56
|
-
throw InputError.fromCode(new DerDecodeErrorCode('Invalid length 0'));
|
|
57
|
-
}
|
|
58
|
-
if (buf[offset] === 0x81) {
|
|
59
|
-
return 2;
|
|
60
|
-
}
|
|
61
|
-
if (buf[offset] === 0x82) {
|
|
62
|
-
return 3;
|
|
63
|
-
}
|
|
64
|
-
if (buf[offset] === 0x83) {
|
|
65
|
-
return 4;
|
|
66
|
-
}
|
|
67
|
-
throw InputError.fromCode(new DerDecodeErrorCode('Length too long (> 4 bytes)'));
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export const decodeLen = (buf: Uint8Array, offset: number): number => {
|
|
71
|
-
const lenBytes = decodeLenBytes(buf, offset);
|
|
72
|
-
if (lenBytes === 1) {
|
|
73
|
-
return buf[offset];
|
|
74
|
-
}
|
|
75
|
-
if (lenBytes === 2) {
|
|
76
|
-
return buf[offset + 1];
|
|
77
|
-
}
|
|
78
|
-
if (lenBytes === 3) {
|
|
79
|
-
return (buf[offset + 1] << 8) + buf[offset + 2];
|
|
80
|
-
}
|
|
81
|
-
if (lenBytes === 4) {
|
|
82
|
-
return (buf[offset + 1] << 16) + (buf[offset + 2] << 8) + buf[offset + 3];
|
|
83
|
-
}
|
|
84
|
-
throw InputError.fromCode(new DerDecodeErrorCode('Length too long (> 4 bytes)'));
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* A DER encoded `SEQUENCE(OID)` for DER-encoded-COSE
|
|
89
|
-
*/
|
|
90
|
-
export const DER_COSE_OID = Uint8Array.from([
|
|
91
|
-
...[0x30, 0x0c], // SEQUENCE
|
|
92
|
-
...[0x06, 0x0a], // OID with 10 bytes
|
|
93
|
-
...[0x2b, 0x06, 0x01, 0x04, 0x01, 0x83, 0xb8, 0x43, 0x01, 0x01], // DER encoded COSE
|
|
94
|
-
]);
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* A DER encoded `SEQUENCE(OID)` for the Ed25519 algorithm
|
|
98
|
-
*/
|
|
99
|
-
export const ED25519_OID = Uint8Array.from([
|
|
100
|
-
...[0x30, 0x05], // SEQUENCE
|
|
101
|
-
...[0x06, 0x03], // OID with 3 bytes
|
|
102
|
-
...[0x2b, 0x65, 0x70], // id-Ed25519 OID
|
|
103
|
-
]);
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* A DER encoded `SEQUENCE(OID)` for secp256k1 with the ECDSA algorithm
|
|
107
|
-
*/
|
|
108
|
-
export const SECP256K1_OID = Uint8Array.from([
|
|
109
|
-
...[0x30, 0x10], // SEQUENCE
|
|
110
|
-
...[0x06, 0x07], // OID with 7 bytes
|
|
111
|
-
...[0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01], // OID ECDSA
|
|
112
|
-
...[0x06, 0x05], // OID with 5 bytes
|
|
113
|
-
...[0x2b, 0x81, 0x04, 0x00, 0x0a], // OID secp256k1
|
|
114
|
-
]);
|
|
115
|
-
|
|
116
|
-
export const BLS12_381_G2_OID = Uint8Array.from([
|
|
117
|
-
...[0x30, 0x1d], // SEQUENCE, length 29 bytes
|
|
118
|
-
// Algorithm OID
|
|
119
|
-
...[0x06, 0x0d],
|
|
120
|
-
...[0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xdc, 0x7c, 0x05, 0x03, 0x01, 0x02, 0x01],
|
|
121
|
-
// Curve OID
|
|
122
|
-
...[0x06, 0x0c],
|
|
123
|
-
...[0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xdc, 0x7c, 0x05, 0x03, 0x02, 0x01],
|
|
124
|
-
]);
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Wraps the given `payload` in a DER encoding tagged with the given encoded `oid` like so:
|
|
128
|
-
* `SEQUENCE(oid, BITSTRING(payload))`
|
|
129
|
-
* @param payload The payload to encode as the bit string
|
|
130
|
-
* @param oid The DER encoded (and SEQUENCE wrapped!) OID to tag the payload with
|
|
131
|
-
*/
|
|
132
|
-
export function wrapDER(payload: Uint8Array, oid: Uint8Array): Uint8Array {
|
|
133
|
-
// The Bit String header needs to include the unused bit count byte in its length
|
|
134
|
-
const bitStringHeaderLength = 2 + encodeLenBytes(payload.byteLength + 1);
|
|
135
|
-
const len = oid.byteLength + bitStringHeaderLength + payload.byteLength;
|
|
136
|
-
let offset = 0;
|
|
137
|
-
const buf = new Uint8Array(1 + encodeLenBytes(len) + len);
|
|
138
|
-
// Sequence
|
|
139
|
-
buf[offset++] = 0x30;
|
|
140
|
-
// Sequence Length
|
|
141
|
-
offset += encodeLen(buf, offset, len);
|
|
142
|
-
|
|
143
|
-
// OID
|
|
144
|
-
buf.set(oid, offset);
|
|
145
|
-
offset += oid.byteLength;
|
|
146
|
-
|
|
147
|
-
// Bit String Header
|
|
148
|
-
buf[offset++] = 0x03;
|
|
149
|
-
offset += encodeLen(buf, offset, payload.byteLength + 1);
|
|
150
|
-
// 0 padding
|
|
151
|
-
buf[offset++] = 0x00;
|
|
152
|
-
buf.set(new Uint8Array(payload), offset);
|
|
153
|
-
|
|
154
|
-
return buf;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Extracts a payload from the given `derEncoded` data, and checks that it was tagged with the given `oid`.
|
|
159
|
-
*
|
|
160
|
-
* `derEncoded = SEQUENCE(oid, BITSTRING(payload))`
|
|
161
|
-
* @param derEncoded The DER encoded and tagged data
|
|
162
|
-
* @param oid The DER encoded (and SEQUENCE wrapped!) expected OID
|
|
163
|
-
* @returns The unwrapped payload
|
|
164
|
-
*/
|
|
165
|
-
export const unwrapDER = (derEncoded: Uint8Array, oid: Uint8Array): Uint8Array => {
|
|
166
|
-
let offset = 0;
|
|
167
|
-
const expect = (n: number, msg: string) => {
|
|
168
|
-
if (buf[offset++] !== n) {
|
|
169
|
-
throw InputError.fromCode(new DerDecodeErrorCode(`Expected ${msg} at offset ${offset}`));
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
const buf = new Uint8Array(derEncoded);
|
|
174
|
-
expect(0x30, 'sequence');
|
|
175
|
-
offset += decodeLenBytes(buf, offset);
|
|
176
|
-
|
|
177
|
-
if (!uint8Equals(buf.slice(offset, offset + oid.byteLength), oid)) {
|
|
178
|
-
throw InputError.fromCode(new DerDecodeErrorCode('Not the expected OID.'));
|
|
179
|
-
}
|
|
180
|
-
offset += oid.byteLength;
|
|
181
|
-
|
|
182
|
-
expect(0x03, 'bit string');
|
|
183
|
-
const payloadLen = decodeLen(buf, offset) - 1; // Subtracting 1 to account for the 0 padding
|
|
184
|
-
offset += decodeLenBytes(buf, offset);
|
|
185
|
-
expect(0x00, '0 padding');
|
|
186
|
-
const result = buf.slice(offset);
|
|
187
|
-
if (payloadLen !== result.length) {
|
|
188
|
-
throw InputError.fromCode(new DerDecodeLengthMismatchErrorCode(payloadLen, result.length));
|
|
189
|
-
}
|
|
190
|
-
return result;
|
|
191
|
-
};
|