@icp-sdk/core 5.2.1 → 5.3.1

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.
@@ -0,0 +1,58 @@
1
+ import type { Identity, HttpAgentRequest } from '../../agent/index.js';
2
+ import type { Principal } from '../../principal/index.js';
3
+ /**
4
+ * Signed attributes to be included as `sender_info` in the request content.
5
+ */
6
+ export interface SignedAttributes {
7
+ data: Uint8Array;
8
+ signature: Uint8Array;
9
+ }
10
+ /**
11
+ * The canister that signed the attributes.
12
+ */
13
+ export interface Signer {
14
+ canisterId: Principal;
15
+ }
16
+ /**
17
+ * Options for creating an {@link AttributesIdentity}.
18
+ */
19
+ export interface AttributesIdentityOptions {
20
+ /** The inner identity to delegate signing to. */
21
+ inner: Identity;
22
+ /** The signed attributes to include in the request. */
23
+ attributes: SignedAttributes;
24
+ /** The canister that signed the attributes. */
25
+ signer: Signer;
26
+ }
27
+ /**
28
+ * An Identity decorator that injects `sender_info` into the request body
29
+ * before delegating to an inner identity for signing.
30
+ *
31
+ * Because `sender_info` is part of the request content, it is included in the
32
+ * representation-independent hash (`requestIdOf`) and covered by the sender's
33
+ * signature.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * const inner = DelegationIdentity.fromDelegation(key, chain);
38
+ * const identity = new AttributesIdentity({
39
+ * inner,
40
+ * attributes: { data: new Uint8Array([...]), signature: new Uint8Array([...]) },
41
+ * signer: { canisterId: Principal.fromText('aaaaa-aa') },
42
+ * });
43
+ * const agent = HttpAgent.create({ identity });
44
+ * ```
45
+ */
46
+ export declare class AttributesIdentity implements Identity {
47
+ #private;
48
+ /**
49
+ * @param options - Configuration for the identity.
50
+ * @param options.inner - The inner identity to delegate signing to.
51
+ * @param options.attributes - The signed attributes to include in the request.
52
+ * @param options.signer - The canister that signed the attributes.
53
+ */
54
+ constructor(options: AttributesIdentityOptions);
55
+ getPrincipal(): Principal;
56
+ transformRequest(request: HttpAgentRequest): Promise<unknown>;
57
+ }
58
+ //# sourceMappingURL=attributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../../../src/identity/identity/attributes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,UAAU,CAAC;IACjB,SAAS,EAAE,UAAU,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,UAAU,EAAE,SAAS,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,iDAAiD;IACjD,KAAK,EAAE,QAAQ,CAAC;IAChB,uDAAuD;IACvD,UAAU,EAAE,gBAAgB,CAAC;IAC7B,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,kBAAmB,YAAW,QAAQ;;IAKjD;;;;;OAKG;gBACS,OAAO,EAAE,yBAAyB;IAM9C,YAAY,IAAI,SAAS;IAIzB,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CAa9D"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AttributesIdentity = void 0;
4
+ /**
5
+ * An Identity decorator that injects `sender_info` into the request body
6
+ * before delegating to an inner identity for signing.
7
+ *
8
+ * Because `sender_info` is part of the request content, it is included in the
9
+ * representation-independent hash (`requestIdOf`) and covered by the sender's
10
+ * signature.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const inner = DelegationIdentity.fromDelegation(key, chain);
15
+ * const identity = new AttributesIdentity({
16
+ * inner,
17
+ * attributes: { data: new Uint8Array([...]), signature: new Uint8Array([...]) },
18
+ * signer: { canisterId: Principal.fromText('aaaaa-aa') },
19
+ * });
20
+ * const agent = HttpAgent.create({ identity });
21
+ * ```
22
+ */
23
+ class AttributesIdentity {
24
+ #inner;
25
+ #attributes;
26
+ #signer;
27
+ /**
28
+ * @param options - Configuration for the identity.
29
+ * @param options.inner - The inner identity to delegate signing to.
30
+ * @param options.attributes - The signed attributes to include in the request.
31
+ * @param options.signer - The canister that signed the attributes.
32
+ */
33
+ constructor(options) {
34
+ this.#inner = options.inner;
35
+ this.#attributes = options.attributes;
36
+ this.#signer = options.signer;
37
+ }
38
+ getPrincipal() {
39
+ return this.#inner.getPrincipal();
40
+ }
41
+ transformRequest(request) {
42
+ return this.#inner.transformRequest({
43
+ ...request,
44
+ body: {
45
+ ...request.body,
46
+ sender_info: {
47
+ signer: this.#signer.canisterId.toUint8Array(),
48
+ info: this.#attributes.data,
49
+ sig: this.#attributes.signature,
50
+ },
51
+ },
52
+ });
53
+ }
54
+ }
55
+ exports.AttributesIdentity = AttributesIdentity;
56
+ //# sourceMappingURL=attributes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.js","sourceRoot":"","sources":["../../../../src/identity/identity/attributes.ts"],"names":[],"mappings":";;;AA8BA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAa,kBAAkB;IACpB,MAAM,CAAW;IACjB,WAAW,CAAmB;IAC9B,OAAO,CAAS;IAEzB;;;;;OAKG;IACH,YAAY,OAAkC;QAC5C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;QACtC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAChC,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;IACpC,CAAC;IAED,gBAAgB,CAAC,OAAyB;QACxC,OAAO,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC;YAClC,GAAG,OAAO;YACV,IAAI,EAAE;gBACJ,GAAG,OAAO,CAAC,IAAI;gBACf,WAAW,EAAE;oBACX,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,YAAY,EAAE;oBAC9C,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;oBAC3B,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,SAAS;iBAChC;aACF;SACkB,CAAC,CAAC;IACzB,CAAC;CACF;AAlCD,gDAkCC"}
@@ -19,6 +19,10 @@
19
19
  *
20
20
  * The `PartialIdentity` is not typically used directly, but is used by the `DelegationIdentity` and `WebAuthnIdentity` classes.
21
21
  *
22
+ * ### AttributesIdentity
23
+ *
24
+ * The `AttributesIdentity` is an Identity decorator that injects `sender_info` into the request content. It wraps any other identity and adds signed attributes before the inner identity signs the request.
25
+ *
22
26
  * ### Secp256k1KeyIdentity
23
27
  *
24
28
  * See [@icp-sdk/core/identity/secp256k1](https://js.icp.build/core/latest/libs/identity-secp256k1/api/) for more information.
@@ -34,6 +38,7 @@ export * from './identity/ed25519.ts';
34
38
  export * from './identity/ecdsa.ts';
35
39
  export * from './identity/delegation.ts';
36
40
  export * from './identity/partial.ts';
41
+ export * from './identity/attributes.ts';
37
42
  export { WebAuthnIdentity } from './identity/webauthn.ts';
38
43
  export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from '../agent/index.js';
39
44
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC"}
@@ -20,6 +20,10 @@
20
20
  *
21
21
  * The `PartialIdentity` is not typically used directly, but is used by the `DelegationIdentity` and `WebAuthnIdentity` classes.
22
22
  *
23
+ * ### AttributesIdentity
24
+ *
25
+ * The `AttributesIdentity` is an Identity decorator that injects `sender_info` into the request content. It wraps any other identity and adds signed attributes before the inner identity signs the request.
26
+ *
23
27
  * ### Secp256k1KeyIdentity
24
28
  *
25
29
  * See [@icp-sdk/core/identity/secp256k1](https://js.icp.build/core/latest/libs/identity-secp256k1/api/) for more information.
@@ -51,6 +55,7 @@ __exportStar(require("./identity/ed25519.js"), exports);
51
55
  __exportStar(require("./identity/ecdsa.js"), exports);
52
56
  __exportStar(require("./identity/delegation.js"), exports);
53
57
  __exportStar(require("./identity/partial.js"), exports);
58
+ __exportStar(require("./identity/attributes.js"), exports);
54
59
  var webauthn_ts_1 = require("./identity/webauthn.js");
55
60
  Object.defineProperty(exports, "WebAuthnIdentity", { enumerable: true, get: function () { return webauthn_ts_1.WebAuthnIdentity; } });
56
61
  var _agent_1 = require("../agent/index.js");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/identity/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;;;;;;;;;;;;;;;;;AAEH,wDAAsC;AACtC,sDAAoC;AACpC,2DAAyC;AACzC,wDAAsC;AACtC,sDAA0D;AAAjD,+GAAA,gBAAgB,OAAA;AACzB,iCAAuE;AAA9D,iGAAA,OAAO,OAAA;AAAE,mGAAA,SAAS,OAAA;AAAE,sGAAA,YAAY,OAAA;AAAE,qGAAA,WAAW,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/identity/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;;;;;;;;;;;;;;;;;AAEH,wDAAsC;AACtC,sDAAoC;AACpC,2DAAyC;AACzC,wDAAsC;AACtC,2DAAyC;AACzC,sDAA0D;AAAjD,+GAAA,gBAAgB,OAAA;AACzB,iCAAuE;AAA9D,iGAAA,OAAO,OAAA;AAAE,mGAAA,SAAS,OAAA;AAAE,sGAAA,YAAY,OAAA;AAAE,qGAAA,WAAW,OAAA"}
@@ -0,0 +1,58 @@
1
+ import type { Identity, HttpAgentRequest } from '../../agent/index.js';
2
+ import type { Principal } from '../../principal/index.js';
3
+ /**
4
+ * Signed attributes to be included as `sender_info` in the request content.
5
+ */
6
+ export interface SignedAttributes {
7
+ data: Uint8Array;
8
+ signature: Uint8Array;
9
+ }
10
+ /**
11
+ * The canister that signed the attributes.
12
+ */
13
+ export interface Signer {
14
+ canisterId: Principal;
15
+ }
16
+ /**
17
+ * Options for creating an {@link AttributesIdentity}.
18
+ */
19
+ export interface AttributesIdentityOptions {
20
+ /** The inner identity to delegate signing to. */
21
+ inner: Identity;
22
+ /** The signed attributes to include in the request. */
23
+ attributes: SignedAttributes;
24
+ /** The canister that signed the attributes. */
25
+ signer: Signer;
26
+ }
27
+ /**
28
+ * An Identity decorator that injects `sender_info` into the request body
29
+ * before delegating to an inner identity for signing.
30
+ *
31
+ * Because `sender_info` is part of the request content, it is included in the
32
+ * representation-independent hash (`requestIdOf`) and covered by the sender's
33
+ * signature.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * const inner = DelegationIdentity.fromDelegation(key, chain);
38
+ * const identity = new AttributesIdentity({
39
+ * inner,
40
+ * attributes: { data: new Uint8Array([...]), signature: new Uint8Array([...]) },
41
+ * signer: { canisterId: Principal.fromText('aaaaa-aa') },
42
+ * });
43
+ * const agent = HttpAgent.create({ identity });
44
+ * ```
45
+ */
46
+ export declare class AttributesIdentity implements Identity {
47
+ #private;
48
+ /**
49
+ * @param options - Configuration for the identity.
50
+ * @param options.inner - The inner identity to delegate signing to.
51
+ * @param options.attributes - The signed attributes to include in the request.
52
+ * @param options.signer - The canister that signed the attributes.
53
+ */
54
+ constructor(options: AttributesIdentityOptions);
55
+ getPrincipal(): Principal;
56
+ transformRequest(request: HttpAgentRequest): Promise<unknown>;
57
+ }
58
+ //# sourceMappingURL=attributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../../../src/identity/identity/attributes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,UAAU,CAAC;IACjB,SAAS,EAAE,UAAU,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,UAAU,EAAE,SAAS,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,iDAAiD;IACjD,KAAK,EAAE,QAAQ,CAAC;IAChB,uDAAuD;IACvD,UAAU,EAAE,gBAAgB,CAAC;IAC7B,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,kBAAmB,YAAW,QAAQ;;IAKjD;;;;;OAKG;gBACS,OAAO,EAAE,yBAAyB;IAM9C,YAAY,IAAI,SAAS;IAIzB,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CAa9D"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * An Identity decorator that injects `sender_info` into the request body
3
+ * before delegating to an inner identity for signing.
4
+ *
5
+ * Because `sender_info` is part of the request content, it is included in the
6
+ * representation-independent hash (`requestIdOf`) and covered by the sender's
7
+ * signature.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const inner = DelegationIdentity.fromDelegation(key, chain);
12
+ * const identity = new AttributesIdentity({
13
+ * inner,
14
+ * attributes: { data: new Uint8Array([...]), signature: new Uint8Array([...]) },
15
+ * signer: { canisterId: Principal.fromText('aaaaa-aa') },
16
+ * });
17
+ * const agent = HttpAgent.create({ identity });
18
+ * ```
19
+ */
20
+ export class AttributesIdentity {
21
+ #inner;
22
+ #attributes;
23
+ #signer;
24
+ /**
25
+ * @param options - Configuration for the identity.
26
+ * @param options.inner - The inner identity to delegate signing to.
27
+ * @param options.attributes - The signed attributes to include in the request.
28
+ * @param options.signer - The canister that signed the attributes.
29
+ */
30
+ constructor(options) {
31
+ this.#inner = options.inner;
32
+ this.#attributes = options.attributes;
33
+ this.#signer = options.signer;
34
+ }
35
+ getPrincipal() {
36
+ return this.#inner.getPrincipal();
37
+ }
38
+ transformRequest(request) {
39
+ return this.#inner.transformRequest({
40
+ ...request,
41
+ body: {
42
+ ...request.body,
43
+ sender_info: {
44
+ signer: this.#signer.canisterId.toUint8Array(),
45
+ info: this.#attributes.data,
46
+ sig: this.#attributes.signature,
47
+ },
48
+ },
49
+ });
50
+ }
51
+ }
52
+ //# sourceMappingURL=attributes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.js","sourceRoot":"","sources":["../../../../src/identity/identity/attributes.ts"],"names":[],"mappings":"AA8BA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,kBAAkB;IACpB,MAAM,CAAW;IACjB,WAAW,CAAmB;IAC9B,OAAO,CAAS;IAEzB;;;;;OAKG;IACH,YAAY,OAAkC;QAC5C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;QACtC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAChC,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;IACpC,CAAC;IAED,gBAAgB,CAAC,OAAyB;QACxC,OAAO,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC;YAClC,GAAG,OAAO;YACV,IAAI,EAAE;gBACJ,GAAG,OAAO,CAAC,IAAI;gBACf,WAAW,EAAE;oBACX,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,YAAY,EAAE;oBAC9C,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;oBAC3B,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,SAAS;iBAChC;aACF;SACkB,CAAC,CAAC;IACzB,CAAC;CACF"}
@@ -19,6 +19,10 @@
19
19
  *
20
20
  * The `PartialIdentity` is not typically used directly, but is used by the `DelegationIdentity` and `WebAuthnIdentity` classes.
21
21
  *
22
+ * ### AttributesIdentity
23
+ *
24
+ * The `AttributesIdentity` is an Identity decorator that injects `sender_info` into the request content. It wraps any other identity and adds signed attributes before the inner identity signs the request.
25
+ *
22
26
  * ### Secp256k1KeyIdentity
23
27
  *
24
28
  * See [@icp-sdk/core/identity/secp256k1](https://js.icp.build/core/latest/libs/identity-secp256k1/api/) for more information.
@@ -34,6 +38,7 @@ export * from './identity/ed25519.ts';
34
38
  export * from './identity/ecdsa.ts';
35
39
  export * from './identity/delegation.ts';
36
40
  export * from './identity/partial.ts';
41
+ export * from './identity/attributes.ts';
37
42
  export { WebAuthnIdentity } from './identity/webauthn.ts';
38
43
  export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from '../agent/index.js';
39
44
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC"}
@@ -19,6 +19,10 @@
19
19
  *
20
20
  * The `PartialIdentity` is not typically used directly, but is used by the `DelegationIdentity` and `WebAuthnIdentity` classes.
21
21
  *
22
+ * ### AttributesIdentity
23
+ *
24
+ * The `AttributesIdentity` is an Identity decorator that injects `sender_info` into the request content. It wraps any other identity and adds signed attributes before the inner identity signs the request.
25
+ *
22
26
  * ### Secp256k1KeyIdentity
23
27
  *
24
28
  * See [@icp-sdk/core/identity/secp256k1](https://js.icp.build/core/latest/libs/identity-secp256k1/api/) for more information.
@@ -34,6 +38,7 @@ export * from "./identity/ed25519.js";
34
38
  export * from "./identity/ecdsa.js";
35
39
  export * from "./identity/delegation.js";
36
40
  export * from "./identity/partial.js";
41
+ export * from "./identity/attributes.js";
37
42
  export { WebAuthnIdentity } from "./identity/webauthn.js";
38
43
  export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from '../agent/index.js';
39
44
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icp-sdk/core",
3
- "version": "5.2.1",
3
+ "version": "5.3.1",
4
4
  "author": "DFINITY Stiftung <sdk@dfinity.org>",
5
5
  "license": "Apache-2.0",
6
6
  "description": "JavaScript and TypeScript library to interact with the Internet Computer",
@@ -92,7 +92,7 @@
92
92
  }
93
93
  },
94
94
  "dependencies": {
95
- "@dfinity/cbor": "^0.2.2",
95
+ "@dfinity/cbor": "^0.2.3",
96
96
  "@noble/curves": "^1.9.7",
97
97
  "@noble/hashes": "^1.8.0",
98
98
  "@scure/bip32": "^1.7.0",
@@ -103,4 +103,4 @@
103
103
  "fake-indexeddb": "^6.2.5",
104
104
  "tsc-alias": "^1.8.16"
105
105
  }
106
- }
106
+ }
@@ -0,0 +1,84 @@
1
+ import type { Identity, HttpAgentRequest } from '#agent';
2
+ import type { Principal } from '#principal';
3
+
4
+ /**
5
+ * Signed attributes to be included as `sender_info` in the request content.
6
+ */
7
+ export interface SignedAttributes {
8
+ data: Uint8Array;
9
+ signature: Uint8Array;
10
+ }
11
+
12
+ /**
13
+ * The canister that signed the attributes.
14
+ */
15
+ export interface Signer {
16
+ canisterId: Principal;
17
+ }
18
+
19
+ /**
20
+ * Options for creating an {@link AttributesIdentity}.
21
+ */
22
+ export interface AttributesIdentityOptions {
23
+ /** The inner identity to delegate signing to. */
24
+ inner: Identity;
25
+ /** The signed attributes to include in the request. */
26
+ attributes: SignedAttributes;
27
+ /** The canister that signed the attributes. */
28
+ signer: Signer;
29
+ }
30
+
31
+ /**
32
+ * An Identity decorator that injects `sender_info` into the request body
33
+ * before delegating to an inner identity for signing.
34
+ *
35
+ * Because `sender_info` is part of the request content, it is included in the
36
+ * representation-independent hash (`requestIdOf`) and covered by the sender's
37
+ * signature.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * const inner = DelegationIdentity.fromDelegation(key, chain);
42
+ * const identity = new AttributesIdentity({
43
+ * inner,
44
+ * attributes: { data: new Uint8Array([...]), signature: new Uint8Array([...]) },
45
+ * signer: { canisterId: Principal.fromText('aaaaa-aa') },
46
+ * });
47
+ * const agent = HttpAgent.create({ identity });
48
+ * ```
49
+ */
50
+ export class AttributesIdentity implements Identity {
51
+ readonly #inner: Identity;
52
+ readonly #attributes: SignedAttributes;
53
+ readonly #signer: Signer;
54
+
55
+ /**
56
+ * @param options - Configuration for the identity.
57
+ * @param options.inner - The inner identity to delegate signing to.
58
+ * @param options.attributes - The signed attributes to include in the request.
59
+ * @param options.signer - The canister that signed the attributes.
60
+ */
61
+ constructor(options: AttributesIdentityOptions) {
62
+ this.#inner = options.inner;
63
+ this.#attributes = options.attributes;
64
+ this.#signer = options.signer;
65
+ }
66
+
67
+ getPrincipal(): Principal {
68
+ return this.#inner.getPrincipal();
69
+ }
70
+
71
+ transformRequest(request: HttpAgentRequest): Promise<unknown> {
72
+ return this.#inner.transformRequest({
73
+ ...request,
74
+ body: {
75
+ ...request.body,
76
+ sender_info: {
77
+ signer: this.#signer.canisterId.toUint8Array(),
78
+ info: this.#attributes.data,
79
+ sig: this.#attributes.signature,
80
+ },
81
+ },
82
+ } as HttpAgentRequest);
83
+ }
84
+ }
@@ -19,6 +19,10 @@
19
19
  *
20
20
  * The `PartialIdentity` is not typically used directly, but is used by the `DelegationIdentity` and `WebAuthnIdentity` classes.
21
21
  *
22
+ * ### AttributesIdentity
23
+ *
24
+ * The `AttributesIdentity` is an Identity decorator that injects `sender_info` into the request content. It wraps any other identity and adds signed attributes before the inner identity signs the request.
25
+ *
22
26
  * ### Secp256k1KeyIdentity
23
27
  *
24
28
  * See [@icp-sdk/core/identity/secp256k1](https://js.icp.build/core/latest/libs/identity-secp256k1/api/) for more information.
@@ -35,5 +39,6 @@ export * from './identity/ed25519.ts';
35
39
  export * from './identity/ecdsa.ts';
36
40
  export * from './identity/delegation.ts';
37
41
  export * from './identity/partial.ts';
42
+ export * from './identity/attributes.ts';
38
43
  export { WebAuthnIdentity } from './identity/webauthn.ts';
39
44
  export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from '#agent';