mirror of
https://github.com/selfxyz/self.git
synced 2026-01-10 15:18:18 -05:00
Self sdk and playground (#210)
Co-authored-by: nicoshark <i.am.nicoshark@gmail.com>
This commit is contained in:
@@ -266,6 +266,7 @@ export const n_dsc_ecdsa = 64;
|
||||
export const k_dsc_ecdsa = 4;
|
||||
export const max_dsc_bytes = 1792;
|
||||
export const max_csca_bytes = 1792;
|
||||
|
||||
export const countryCodes = {
|
||||
AFG: 'Afghanistan',
|
||||
ALA: 'Aland Islands',
|
||||
@@ -527,259 +528,6 @@ export function getCountryCode(countryName: string): string | string {
|
||||
return found ? found[0] : 'undefined';
|
||||
}
|
||||
|
||||
export const countryNames = [
|
||||
'Any',
|
||||
'Afghanistan',
|
||||
'Aland Islands',
|
||||
'Albania',
|
||||
'Algeria',
|
||||
'American Samoa',
|
||||
'Andorra',
|
||||
'Angola',
|
||||
'Anguilla',
|
||||
'Antarctica',
|
||||
'Antigua and Barbuda',
|
||||
'Argentina',
|
||||
'Armenia',
|
||||
'Aruba',
|
||||
'Australia',
|
||||
'Austria',
|
||||
'Azerbaijan',
|
||||
'Bahamas',
|
||||
'Bahrain',
|
||||
'Bangladesh',
|
||||
'Barbados',
|
||||
'Belarus',
|
||||
'Belgium',
|
||||
'Belize',
|
||||
'Benin',
|
||||
'Bermuda',
|
||||
'Bhutan',
|
||||
'Bolivia (Plurinational State of)',
|
||||
'Bonaire, Sint Eustatius and Saba',
|
||||
'Bosnia and Herzegovina',
|
||||
'Botswana',
|
||||
'Bouvet Island',
|
||||
'Brazil',
|
||||
'British Indian Ocean Territory',
|
||||
'Brunei Darussalam',
|
||||
'Bulgaria',
|
||||
'Burkina Faso',
|
||||
'Burundi',
|
||||
'Cabo Verde',
|
||||
'Cambodia',
|
||||
'Cameroon',
|
||||
'Canada',
|
||||
'Cayman Islands',
|
||||
'Central African Republic',
|
||||
'Chad',
|
||||
'Chile',
|
||||
'China',
|
||||
'Christmas Island',
|
||||
'Cocos (Keeling) Islands',
|
||||
'Colombia',
|
||||
'Comoros',
|
||||
'Congo',
|
||||
'Congo, Democratic Republic of the',
|
||||
'Cook Islands',
|
||||
'Costa Rica',
|
||||
"Cote d'Ivoire",
|
||||
'Croatia',
|
||||
'Cuba',
|
||||
'Curacao',
|
||||
'Cyprus',
|
||||
'Czechia',
|
||||
'Denmark',
|
||||
'Djibouti',
|
||||
'Dominica',
|
||||
'Dominican Republic',
|
||||
'Ecuador',
|
||||
'Egypt',
|
||||
'El Salvador',
|
||||
'Equatorial Guinea',
|
||||
'Eritrea',
|
||||
'Estonia',
|
||||
'Eswatini',
|
||||
'Ethiopia',
|
||||
'Falkland Islands (Malvinas)',
|
||||
'Faroe Islands',
|
||||
'Fiji',
|
||||
'Finland',
|
||||
'France',
|
||||
'French Guiana',
|
||||
'French Polynesia',
|
||||
'French Southern Territories',
|
||||
'Gabon',
|
||||
'Gambia',
|
||||
'Georgia',
|
||||
'Germany',
|
||||
'Ghana',
|
||||
'Gibraltar',
|
||||
'Greece',
|
||||
'Greenland',
|
||||
'Grenada',
|
||||
'Guadeloupe',
|
||||
'Guam',
|
||||
'Guatemala',
|
||||
'Guernsey',
|
||||
'Guinea',
|
||||
'Guinea-Bissau',
|
||||
'Guyana',
|
||||
'Haiti',
|
||||
'Heard Island and McDonald Islands',
|
||||
'Holy See',
|
||||
'Honduras',
|
||||
'Hong Kong',
|
||||
'Hungary',
|
||||
'Iceland',
|
||||
'India',
|
||||
'Indonesia',
|
||||
'Iran (Islamic Republic of)',
|
||||
'Iraq',
|
||||
'Ireland',
|
||||
'Isle of Man',
|
||||
'Israel',
|
||||
'Italy',
|
||||
'Jamaica',
|
||||
'Japan',
|
||||
'Jersey',
|
||||
'Jordan',
|
||||
'Kazakhstan',
|
||||
'Kenya',
|
||||
'Kiribati',
|
||||
"Korea (Democratic People's Republic of)",
|
||||
'Korea, Republic of',
|
||||
'Kuwait',
|
||||
'Kyrgyzstan',
|
||||
"Lao People's Democratic Republic",
|
||||
'Latvia',
|
||||
'Lebanon',
|
||||
'Lesotho',
|
||||
'Liberia',
|
||||
'Libya',
|
||||
'Liechtenstein',
|
||||
'Lithuania',
|
||||
'Luxembourg',
|
||||
'Macao',
|
||||
'Madagascar',
|
||||
'Malawi',
|
||||
'Malaysia',
|
||||
'Maldives',
|
||||
'Mali',
|
||||
'Malta',
|
||||
'Marshall Islands',
|
||||
'Martinique',
|
||||
'Mauritania',
|
||||
'Mauritius',
|
||||
'Mayotte',
|
||||
'Mexico',
|
||||
'Micronesia (Federated States of)',
|
||||
'Moldova, Republic of',
|
||||
'Monaco',
|
||||
'Mongolia',
|
||||
'Montenegro',
|
||||
'Montserrat',
|
||||
'Morocco',
|
||||
'Mozambique',
|
||||
'Myanmar',
|
||||
'Namibia',
|
||||
'Nauru',
|
||||
'Nepal',
|
||||
'Netherlands',
|
||||
'New Caledonia',
|
||||
'New Zealand',
|
||||
'Nicaragua',
|
||||
'Niger',
|
||||
'Nigeria',
|
||||
'Niue',
|
||||
'Norfolk Island',
|
||||
'North Macedonia',
|
||||
'Northern Mariana Islands',
|
||||
'Norway',
|
||||
'Oman',
|
||||
'Pakistan',
|
||||
'Palau',
|
||||
'Palestine, State of',
|
||||
'Panama',
|
||||
'Papua New Guinea',
|
||||
'Paraguay',
|
||||
'Peru',
|
||||
'Philippines',
|
||||
'Pitcairn',
|
||||
'Poland',
|
||||
'Portugal',
|
||||
'Puerto Rico',
|
||||
'Qatar',
|
||||
'Reunion',
|
||||
'Romania',
|
||||
'Russian Federation',
|
||||
'Rwanda',
|
||||
'Saint Barthelemy',
|
||||
'Saint Helena, Ascension and Tristan da Cunha',
|
||||
'Saint Kitts and Nevis',
|
||||
'Saint Lucia',
|
||||
'Saint Martin (French part)',
|
||||
'Saint Pierre and Miquelon',
|
||||
'Saint Vincent and the Grenadines',
|
||||
'Samoa',
|
||||
'San Marino',
|
||||
'Sao Tome and Principe',
|
||||
'Saudi Arabia',
|
||||
'Senegal',
|
||||
'Serbia',
|
||||
'Seychelles',
|
||||
'Sierra Leone',
|
||||
'Singapore',
|
||||
'Sint Maarten (Dutch part)',
|
||||
'Slovakia',
|
||||
'Slovenia',
|
||||
'Solomon Islands',
|
||||
'Somalia',
|
||||
'South Africa',
|
||||
'South Georgia and the South Sandwich Islands',
|
||||
'South Sudan',
|
||||
'Spain',
|
||||
'Sri Lanka',
|
||||
'Sudan',
|
||||
'Suriname',
|
||||
'Svalbard and Jan Mayen',
|
||||
'Sweden',
|
||||
'Switzerland',
|
||||
'Syrian Arab Republic',
|
||||
'Taiwan, Province of China',
|
||||
'Tajikistan',
|
||||
'Tanzania, United Republic of',
|
||||
'Thailand',
|
||||
'Timor-Leste',
|
||||
'Togo',
|
||||
'Tokelau',
|
||||
'Tonga',
|
||||
'Trinidad and Tobago',
|
||||
'Tunisia',
|
||||
'Turkey',
|
||||
'Turkmenistan',
|
||||
'Turks and Caicos Islands',
|
||||
'Tuvalu',
|
||||
'Uganda',
|
||||
'Ukraine',
|
||||
'United Arab Emirates',
|
||||
'United Kingdom of Great Britain and Northern Ireland',
|
||||
'United States of America',
|
||||
'United States Minor Outlying Islands',
|
||||
'Uruguay',
|
||||
'Uzbekistan',
|
||||
'Vanuatu',
|
||||
'Venezuela (Bolivarian Republic of)',
|
||||
'Viet Nam',
|
||||
'Virgin Islands (British)',
|
||||
'Virgin Islands (U.S.)',
|
||||
'Wallis and Futuna',
|
||||
'Western Sahara',
|
||||
'Yemen',
|
||||
'Zambia',
|
||||
'Zimbabwe',
|
||||
] as const;
|
||||
|
||||
export const contribute_publicKey = `-----BEGIN RSA PUBLIC KEY-----
|
||||
MIICCgKCAgEAv/hm7FZZ2KBmaeDHmLoRwuWmCcNKT561RqbsW8ZuYSyPWJUldE9U
|
||||
Cf0lW3K1H5lsSDkl0Cq84cooL9f6X59Mffb/N24ZKTdL0xdcPwjk4LbcrVm8qubL
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { UserIdType } from "./circuits/uuid";
|
||||
import { UserIdType, validateUserId } from "./circuits/uuid";
|
||||
|
||||
export type Mode = 'register' | 'dsc' | 'vc_and_disclose';
|
||||
export type EndpointType = 'https' | 'celo';
|
||||
@@ -48,17 +48,28 @@ export class SelfAppBuilder {
|
||||
if (!config.endpoint) {
|
||||
throw new Error('endpoint is required');
|
||||
}
|
||||
if (!config.userId) {
|
||||
throw new Error('userId is required');
|
||||
}
|
||||
if (config.endpointType === 'https' && !config.endpoint.startsWith('https://')) {
|
||||
throw new Error('endpoint must start with https://');
|
||||
}
|
||||
if (config.endpointType === 'celo' && !config.endpoint.startsWith('0x')) {
|
||||
throw new Error('endpoint must be a valid address');
|
||||
}
|
||||
|
||||
if (config.userIdType === 'hex') {
|
||||
if (!config.userId.startsWith('0x')) {
|
||||
throw new Error('userId as hex must start with 0x');
|
||||
}
|
||||
config.userId = config.userId.slice(2);
|
||||
}
|
||||
if (!validateUserId(config.userId, config.userIdType ?? "uuid")) {
|
||||
throw new Error('userId must be a valid UUID or address');
|
||||
}
|
||||
|
||||
this.config = {
|
||||
sessionId : v4(),
|
||||
userIdType : 'uuid',
|
||||
userId: "",
|
||||
devMode : false,
|
||||
endpointType : 'https',
|
||||
header: "",
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
export type UserIdType = 'hex' | 'uuid';
|
||||
|
||||
/// UUID
|
||||
function hexToBigInt(hex: string): bigint {
|
||||
return BigInt(`0x${hex}`);
|
||||
@@ -35,6 +37,19 @@ export function castToUUID(bigInt: bigint): string {
|
||||
return hexToUUID(hex);
|
||||
}
|
||||
|
||||
export function castToUserIdentifier(bigInt: bigint, user_identifier_type: UserIdType): string {
|
||||
switch (user_identifier_type) {
|
||||
case 'hex':
|
||||
return castToAddress(bigInt);
|
||||
case 'uuid':
|
||||
return castToUUID(bigInt);
|
||||
}
|
||||
}
|
||||
|
||||
export function castToAddress(bigInt: bigint): string {
|
||||
return `0x${bigInt.toString(16).padStart(40, '0')}`;
|
||||
}
|
||||
|
||||
/// scope
|
||||
function checkStringLength(str: string) {
|
||||
if (str.length > 25) {
|
||||
@@ -70,14 +85,8 @@ export function stringToAsciiBigIntArray(str: string): bigint[] {
|
||||
return asciiBigIntArray;
|
||||
}
|
||||
|
||||
|
||||
// custom user_identifier type validation
|
||||
export type UserIdType = 'ascii' | 'hex' | 'uuid';
|
||||
|
||||
const validateUserId = (userId: string, type: UserIdType): boolean => {
|
||||
export function validateUserId(userId: string, type: UserIdType): boolean {
|
||||
switch (type) {
|
||||
case 'ascii':
|
||||
return /^[\x00-\xFF]+$/.test(userId);
|
||||
case 'hex':
|
||||
return /^[0-9A-Fa-f]+$/.test(userId);
|
||||
case 'uuid':
|
||||
@@ -88,37 +97,3 @@ const validateUserId = (userId: string, type: UserIdType): boolean => {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const getMaxLenght = (idType: UserIdType) => {
|
||||
switch (idType) {
|
||||
case 'ascii':
|
||||
return 25;
|
||||
default:
|
||||
return 63;
|
||||
}
|
||||
};
|
||||
|
||||
export const parseUIDToBigInt = (
|
||||
user_identifier: string,
|
||||
user_identifier_type: UserIdType
|
||||
): string => {
|
||||
if (!validateUserId(user_identifier, user_identifier_type)) {
|
||||
throw new Error(`User identifier of type ${user_identifier_type} is not valid`);
|
||||
}
|
||||
|
||||
const maxLength = getMaxLenght(user_identifier_type);
|
||||
if (user_identifier.length > maxLength) {
|
||||
throw new Error(
|
||||
`User identifier of type ${user_identifier_type} exceeds maximum length of ${maxLength} characters`
|
||||
);
|
||||
}
|
||||
|
||||
switch (user_identifier_type) {
|
||||
case 'ascii':
|
||||
return stringToBigInt(user_identifier).toString();
|
||||
case 'hex':
|
||||
return hexToBigInt(user_identifier).toString();
|
||||
case 'uuid':
|
||||
return uuidToBigInt(user_identifier).toString();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import { bigIntToHex, castToScope, castToUUID, UserIdType } from './circuits/uuid';
|
||||
import { formatForbiddenCountriesListFromCircuitOutput, getAttributeFromUnpackedReveal } from './circuits/formatOutputs';
|
||||
import { unpackReveal } from './circuits/formatOutputs';
|
||||
import { Groth16Proof, PublicSignals } from 'snarkjs';
|
||||
|
||||
export interface SelfVerificationResult {
|
||||
@@ -26,9 +23,9 @@ export interface SelfVerificationResult {
|
||||
gender?: string;
|
||||
expiry_date?: string;
|
||||
older_than?: string;
|
||||
passport_no_ofac?: string;
|
||||
name_and_dob_ofac?: string;
|
||||
name_and_yob_ofac?: string;
|
||||
passport_no_ofac?: boolean;
|
||||
name_and_dob_ofac?: boolean;
|
||||
name_and_yob_ofac?: boolean;
|
||||
};
|
||||
proof: {
|
||||
value: {
|
||||
|
||||
Reference in New Issue
Block a user