fabric-chaincode-node icon indicating copy to clipboard operation
fabric-chaincode-node copied to clipboard

getCreator and ProposedCreator documentation looks to be incorrect

Open davidkel opened this issue 4 years ago • 1 comments

Looking at the docs for getCreator you see

getCreator()
Returns the identity object of the chaincode invocation's submitter
Returns:
Type
ProposalCreator

But the type of ProposalCreator doesn't match the typescript definition which shows

getCreator(): SerializedIdentity;

Looking at the docs about ProposalCreator gives

new ProposalCreator()
This object contains the essential identity information of the chaincode invocation's submitter, including its organizational affiliation (mspid) and certificate (id_bytes)
Properties:
Name	Type	Description
mspid	string	The unique ID of the Membership Service Provider instance that is associated to the identity's organization and is able to perform digital signing and signature verification

not sure you would ever want to create one of these in your code but also the description on what this object is is not correct as it doesn't list the certificate bytes in the properties but does refer to it incorrectly in the description as id_bytes. Looking at the typescript definition for SerializedIdentity it shows

 interface SerializedIdentity {
        mspid: string;
        idBytes: Uint8Array;
    }

which describes it correctly

davidkel avatar Dec 14 '21 22:12 davidkel

Signature (TypeScript):

getCreator(): SerializedIdentity;

Description: Returns the identity object of the chaincode invocation's submitter. This object contains the submitter's MSP ID and the raw certificate bytes used to identify/sign the proposal.

Returns: SerializedIdentity — an object with the submitter's identity information.

SerializedIdentity (aka ProposalCreator in older/outdated docs)

Note: Some docs refer to this as ProposalCreator and/or show it as constructible via new ProposalCreator() — that is incorrect. This object is returned by getCreator() and should not normally be constructed by user code.

Type (TypeScript):

interface SerializedIdentity { /** The MSP ID of the submitter's organization */ mspid: string;

/** The raw identity bytes (certificate) as a Uint8Array. Often contains an X.509 certificate in PEM form. */ idBytes: Uint8Array; }

Properties:

mspid — string The Membership Service Provider identifier for the submitter's organization.

idBytes — Uint8Array The raw certificate bytes for the identity. In most environments this is the submitter's X.509 certificate in PEM format (i.e. ASCII PEM block). (Note: some older docs incorrectly call this id_bytes; the canonical property name in the TypeScript API is idBytes.)**

Example (TypeScript) — reading the creator:

const creator: SerializedIdentity = stub.getCreator(); // or ctx.clientIdentity.getCreator()

console.log('mspid:', creator.mspid);

// Convert idBytes to a string (PEM) const pem = Buffer.from(creator.idBytes).toString('utf8'); console.log('certificate PEM:\n', pem);

// If you need to parse the certificate further, use a proper X.509 parser library.

Example (browser / typed array decoding):

const creator = ctx.stub.getCreator(); const decoder = new TextDecoder('utf-8'); const pem = decoder.decode(creator.idBytes); console.log('certificate PEM:\n', pem);

JSDoc you can drop into the docs/site /**

  • getCreator()
  • Returns the identity of the chaincode invocation's submitter.
  • @returns {SerializedIdentity} An object containing:
    • mspid {string}: MSP identifier for the submitter's organization.
    • idBytes {Uint8Array}: The submitter's certificate bytes (typically an X.509 certificate in PEM format). */

Quick guidance / clarifications

Use idBytes (camelCase) — this matches the TypeScript interface. If you see id_bytes in docs, treat it as an outdated name and update to idBytes.

ProposalCreator appearing as new ProposalCreator() in docs is misleading. The identity is supplied by the Fabric runtime (via getCreator()); application or chaincode authors normally do not instantiate it.

idBytes contains certificate bytes — decode to UTF-8 to get the PEM string, and then use an X.509 parsing library if you need fields from the certificate (subject, SANs, serial number, etc.).

If you want to expose both the raw bytes and a parsed cert in docs, show the raw idBytes type and include a small code snippet demonstrating decoding/parsing (as above).

Jatkingmodern avatar Oct 04 '25 09:10 Jatkingmodern