UNPKG

@iden3/js-iden3-core

Version:

Low level API to create and manipulate iden3 Claims.

123 lines (122 loc) 5.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DidMethodNetwork = exports.DidMethodByte = exports.ChainIds = exports.DidMethod = exports.NetworkId = exports.Blockchain = exports.Constants = void 0; exports.Constants = Object.freeze({ ERRORS: { // ErrDataOverflow means that given *big.Int value does not fit in Field Q // e.g. greater than Q constant: // Q constant: 21888242871839275222246405745257275088548364400416034343698204186575808495617 DATA_OVERFLOW: new Error('data does not fits SNARK size'), // ErrIncorrectIDPosition means that passed position is not one of predefined: // IDPositionIndex or IDPositionValue INCORRECT_ID_POSITION: new Error('incorrect ID position'), // throws when ID not found in the Claim. NO_ID: new Error('ID is not set'), // throws when subject position flags sets in invalid value. INVALID_SUBJECT_POSITION: new Error('invalid subject position'), // ErrIncorrectMerklizePosition means that passed position is not one of predefined: // MerklizePositionIndex or MerklizePositionValue INCORRECT_MERKLIZED_POSITION: new Error('incorrect Merklize position'), // ErrNoMerklizedRoot returns when Merklized Root is not found in the Claim. NO_MERKLIZED_ROOT: new Error('Merklized root is not set'), NETWORK_NOT_SUPPORTED_FOR_DID: new Error('network in not supported for did'), UNSUPPORTED_BLOCKCHAIN_FOR_DID: new Error('not supported blockchain for did'), UNSUPPORTED_DID_METHOD: new Error('not supported DID method'), UNKNOWN_DID_METHOD: new Error('unknown DID method'), INCORRECT_DID: new Error('incorrect DID'), UNSUPPORTED_ID: new Error('unsupported Id') }, SCHEMA: { HASH_LENGTH: 16 }, ETH_ADDRESS_LENGTH: 20, BYTES_LENGTH: 32, ELEM_BYTES_LENGTH: 4, NONCE_BYTES_LENGTH: 8, Q: BigInt('21888242871839275222246405745257275088548364400416034343698204186575808495617'), ID: { TYPE_DEFAULT: Uint8Array.from([0x00, 0x00]), TYPE_READONLY: Uint8Array.from([0b00000000, 0b00000001]), ID_LENGTH: 31 }, DID: { DID_SCHEMA: 'did' }, GENESIS_LENGTH: 27 }); exports.Blockchain = { Ethereum: 'eth', Polygon: 'polygon', Privado: 'privado', Linea: 'linea', Unknown: 'unknown', NoChain: '', ReadOnly: 'readonly' }; exports.NetworkId = { Main: 'main', Mumbai: 'mumbai', Amoy: 'amoy', Goerli: 'goerli', Sepolia: 'sepolia', Zkevm: 'zkevm', Cardona: 'cardona', Test: 'test', Unknown: 'unknown', NoNetwork: '' }; exports.DidMethod = { Iden3: 'iden3', PolygonId: 'polygonid', Other: '' }; /** * Object containing chain IDs for various blockchains and networks. * @type { [key: string]: number } */ exports.ChainIds = { [`${exports.Blockchain.Ethereum}:${exports.NetworkId.Main}`]: 1, [`${exports.Blockchain.Ethereum}:${exports.NetworkId.Goerli}`]: 5, [`${exports.Blockchain.Ethereum}:${exports.NetworkId.Sepolia}`]: 11155111, [`${exports.Blockchain.Polygon}:${exports.NetworkId.Main}`]: 137, [`${exports.Blockchain.Polygon}:${exports.NetworkId.Mumbai}`]: 80001, [`${exports.Blockchain.Polygon}:${exports.NetworkId.Amoy}`]: 80002, [`${exports.Blockchain.Polygon}:${exports.NetworkId.Zkevm}`]: 1101, [`${exports.Blockchain.Polygon}:${exports.NetworkId.Cardona}`]: 2442, [`${exports.Blockchain.Privado}:${exports.NetworkId.Main}`]: 21000, [`${exports.Blockchain.Privado}:${exports.NetworkId.Test}`]: 21001, [`${exports.Blockchain.Linea}:${exports.NetworkId.Main}`]: 59144, [`${exports.Blockchain.Linea}:${exports.NetworkId.Sepolia}`]: 59141 }; exports.DidMethodByte = { [exports.DidMethod.Iden3]: 0b00000001, [exports.DidMethod.PolygonId]: 0b00000010, [exports.DidMethod.Other]: 0b11111111 }; const blockchainNetworkMap = { [`${exports.Blockchain.ReadOnly}:${exports.NetworkId.NoNetwork}`]: 0b00000000, [`${exports.Blockchain.Polygon}:${exports.NetworkId.Main}`]: 16 | 1, [`${exports.Blockchain.Polygon}:${exports.NetworkId.Mumbai}`]: 16 | 2, [`${exports.Blockchain.Polygon}:${exports.NetworkId.Amoy}`]: 16 | 3, [`${exports.Blockchain.Polygon}:${exports.NetworkId.Zkevm}`]: 16 | 4, [`${exports.Blockchain.Polygon}:${exports.NetworkId.Cardona}`]: 16 | 5, [`${exports.Blockchain.Ethereum}:${exports.NetworkId.Main}`]: 32 | 1, [`${exports.Blockchain.Ethereum}:${exports.NetworkId.Goerli}`]: 32 | 2, [`${exports.Blockchain.Ethereum}:${exports.NetworkId.Sepolia}`]: 32 | 3, [`${exports.Blockchain.Privado}:${exports.NetworkId.Main}`]: 160 | 1, [`${exports.Blockchain.Privado}:${exports.NetworkId.Test}`]: 160 | 2, [`${exports.Blockchain.Linea}:${exports.NetworkId.Main}`]: 64 | 9, [`${exports.Blockchain.Linea}:${exports.NetworkId.Sepolia}`]: 64 | 8 }; // DIDMethodNetwork is map for did methods and their blockchain networks exports.DidMethodNetwork = { [exports.DidMethod.Iden3]: { ...blockchainNetworkMap }, [exports.DidMethod.PolygonId]: { ...blockchainNetworkMap }, [exports.DidMethod.Other]: { [`${exports.Blockchain.Unknown}:${exports.NetworkId.Unknown}`]: 255 } };