iExec RLC 백서

iExec RLC

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 12쪽 중 9쪽

es Intel TDX to process protected data. Connect to the TDX SMS and use the TDX workerpool to configure the SDK: Browser ts import { IExecDataProtectorCore } from '@iexec/dataprotector' ; const web3Provider = window . ethereum ; // Instantiate dataProtector connected to the TDX SMS const dataProtectorCore = new IExecDataProtectorCore ( web3Provider , { iexecOptions : { smsURL : 'https://sms.labs.iex.ec' , }, }); // create a protected data const protectedData = await dataProtectorCore . protectData ({ data : { email : 'example@gmail.com' , SMTPserver : { port : 5000 , smtp_server : 'smtp.gmail.com' , }, }, }); Parameters ​ ts import { type ProtectDataParams } from '@iexec/dataprotector' ; data Required * ​ Type: DataObject This is the actual data the user is protecting, provided as a JSON object with any number of custom keys. The data is encrypted and stored as an NFT. ts const protectedData = await dataProtectorCore . protectData ({ data : { email : 'example@gmail.com' , }, }); TIP If you'd like to protect a file , you first need to convert it to a buffer. You can use createArrayBufferFromFile to do this. ts import { createArrayBufferFromFile } from '@iexec/dataprotector' ; const fileAsArrayBuffer = await createArrayBufferFromFile ( file ); TIP If you want to protect an Array , you must represent it as a Record<string, any> . To do so, you can use the reduceArray method implemented in this example. ts const reduceArray = ( array : Array < any >) : Record < string , any > => array . reduce (( accumulator , current , i ) => { accumulator [ i ] = current ; return accumulator ; }, {}); const emailsArray = [ 'example@gmail.com' , 'example@my-company.com' , 'example@example.com' , ]; const protectedData = await dataProtectorCore . protectData ({ data : { emails : reduceArray ( emailsArray ), }, }); /** * protectedData.schema: * { * emails: { * 0: 'string', * 1: 'string', * 2: 'string' * } * } */ name Optional ​ Type: string Default: '' Allows providing a descriptive name for the protected data. This is considered public metadata, describing the protected data. ts const protectedData = await dataProtectorCore . protectData ({ name : 'myEmail' , data : { email : 'example@gmail.com' , }, }); TIP The name is public and not encrypted. uploadMode Optional ​ Type: "ipfs" | "arweave" Default: "ipfs" Specify the storage platform to use for the protected data encrypted payload hosting. ts const protectedData = await dataProtectorCore . protectData ({ name : 'myEmail' , data : { email : 'example@gmail.com' , }, uploadMode : 'arweave' , }); onStatusUpdate Optional ​ Type: OnStatusUpdateFn<ProtectDataStatuses> Callback function to be notified at intermediate steps. ts const protectedData = await dataProtectorCore . protectData ({ name : 'myEmail' , data : { email : 'example@gmail.com' , }, onStatusUpdate : ({ title , isDone }) => { console . log ( title , isDone ); }, }); You can expect this callback function to be called with the following titles: ts 'EXTRACT_DATA_SCHEMA' ; 'CREATE_ZIP_FILE' ; 'CREATE_ENCRYPTION_KEY' ; 'ENCRYPT_FILE' ; 'UPLOAD_ENCRYPTED_FILE' ; 'DEPLOY_PROTECTED_DATA' ; 'PUSH_SECRET_TO_SMS' ; Once with isDone: false , and then with isDone: true Return Value ​ ts import type { ProtectedDataWithSecretProps , ProtectedData , } from '@iexec/dataprotector' ; The protectData method returns the following fields, as a JSON object. name ​ string The optional name provided during invocation of the method. If no name is specified this value defaults to Untitled . address ​ Address The ETH address of the newly created protectedData . owner ​ Address The ETH address of the creator and owner of this protectedData . schema ​ DataSchema Metadata describing the fields provided in the data parameter. The data types are automatically detected and listed in the schema. TIP The following data types are automatically detected: Scalars bool f64 (JavaScript number ) i128 (JavaScript bigint up to 128 bits) string Binary: application/octet-stream application/pdf application/xml application/zip audio/midi audio/mpeg audio/x-wav image/bmp image/gif image/jpeg image/png image/webp video/mp4 video/mpeg video/x-msvideo Any undetected binary data type is categorized as application/octet-stream creationTimestamp ​ number A unix-style timestamp indicating the creation time of this protectedData . transactionHash ​ string The ID of the transaction that happened on iExec's side chain. You may view details on the transaction using the iExec explorer . zipFile ​ Uint8Array Under the hood, your protected data will be compressed as a zip file . In this zip file, you'll find back all of your protected fields, each field being serialized with a tool called Borsh . You can find more details here: deserializer . This is mainly returned for debug purpose. encryptionKey ​ Uint8Array The encryption key generated by the client to encrypt the data. This key is for your own usage. You will not have to share it in the context of the iExec protocol or developer tools. Under the hood, it is a symmetric AES-256 key. TIP The zip file generated is a Uint8Array , so if you want to handle the binary data or download it consider adding a zip extension to it. multiaddr ​ string | undefined The multiaddr field is the IPFS path of your encrypted data. TIP You can access your encrypted IPFS data with the link: https://ipfs-gateway.arbitrum-mainnet.iex.ec/ipfs/abc123... abc123... is the second part of the returned string /p2p/abc123... ## /references/dataProtector/methods/getProtectedData getProtectedData ​ This method allows the user to retrieve all protected data for a given owner, data schema, or both. Results are ordered by creationTimestamp desc. TIP A data schema is the metadata describing the contents of the protected data object. The schema is returned as part of the protectData method invocation. Usage ​ ts const listProtectedData = await dataProtectorCore . getProtectedData ({ owner : '0xa0c15e...' , requiredSchema : { email : 'string' , }, }); Parameters ​ ts import { type GetProtectedDataParams } from '@iexec/dataprotector' ; protectedDataAddress Optional ​ Type: Address Returns the protected data associated with this address. Returns an empty array if the protected data is not found. ts const oneProtectedData = await dataProtectorCore . getProtectedData ({ protectedDataAddress : '0x123abc...' , }); requiredSchema Optional ​ Type: SearchableDataSchema Provides a list of protected data objects matching this schema. ts const listProtectedData = await dataProtectorCore . getProtectedData ({ requiredSchema : { email : 'string' , }, }); It's also possible to provide a list of accepted types for one schema field: ts const listProtectedData = await dataProtectorCore . getProtectedData ({ requiredSchema : { picture : [ 'image/png' , 'image/jpeg' ], }, }); Available types are listed here . owner Optional ​ Type: Address Provides a list of protected data objects owned by the user with this ETH address. ts const listProtectedData = await dataProtectorCore . getProtectedData ({ owner : '0xa0c15e...' , }); createdAfterTimestamp Optional ​ Type: number Provides a list of protected data objects created after this timestamp value. The provided value should be in seconds. ts const listProtectedData = await dataProtectorCore . getProtectedData ({ owner : '0xa0c15e...' , createdAfterTimestamp : 1710257612 , // March 12, 2024 15:33:32 GMT }); page Optional ​ Type: number Default: 0 Specifies the results page to return. Pages are indexed starting at page 0. If using this field you may also specify a pageSize to control the size of the results. ts const listProtectedData = await dataProtectorCore . getProtectedData ({ owner : '0xa0c15e...' , createdAfterTimestamp : 1710257612 , // March 12, 2024 15:33:32 GMT page : 1 , }); pageSize Optional ​ Type: number Default: 1000 Range: [10...1000] Specifies the number of records in each page of the result set. This is used in conjunction with the optional page parameter to constrain the size of the result. ts const listProtectedData = await dataProtectorCore . getProtectedData ({ owner : '0xa0c15e...' , createdAfterTimestamp : 1710257612 , // March 12, 2024 15:33:32 GMT page : 1 , pageSize : 100 , }); Return Value ​ ts import { type ProtectedData } from '@iexec/dataprotector' ; See ProtectedData ## /references/dataProtector/methods/transferOwnership transferOwnership ​ Allows transferring ownership of a protectedData entity to a new owner, identified by their ETH address. The return value provides a transaction hash and confirmation of the new owner of the protectedData . Only the current owner of the protectedData may invoke this method. When transferring the protectedData , the grantedAccess created by the previous owner are revoked automatically. Ownership of the protectedData can be renounced by transferring it to the burn address 0x000000000000000000000000000000000000dEaD . Usage ​ ts const transferResponse = await dataProtectorCore . transferOwnership ({ protectedData : '0x123abc...' , newOwner : '0xc5e9f4...' , }); Parameters ​ ts import { type TransferParams } from '@iexec/dataprotector' ; protectedData Required * ​ Type: Address ETH address of the protectedData owned by you which is to be transferred to a new owner. ts const transferResponse = await dataProtectorCore . transferOwnership ({ protectedData : '0x123abc...' , newOwner : '0xc5e9f4...' , }); newOwner Required * ​ Type: Address ETH address for the new owner for the protectedData . ts const transferResponse = await dataProtectorCore . transferOwnership ({ protectedData : '0x123abc...' , newOwner : '0xc5e9f4...' , }); Return Value ​ ts import { type TransferResponse } from '@iexec/dataprotector' ; The result of this method is an array of objects identifying the new owner. The objects contain the three fields: address ​ Address The ETH address of the protectedData you transferred. to ​ Address The ETH address of the new owner of the protectedData . txHash ​ string The ID of the transaction that happened on iExec's side chain. You may view details on the transaction using the iExec explorer . ## /references/dataProtector/methods/grantAccess grantAccess ​ Data encrypted through the Data Protector tool requires explicit authorization for runtime access. A newly created protectedData object has no inherent authorizations. This method grants permission to securely access the specified protectedData for processing using the processProtectedData method. Authorization to use the protectedData is given to a user in the context of an application (or a designated list of applications). Usage ​ ts const grantedAccess = await dataProtectorCore . grantAccess ({ protectedData : '0x123abc...' , authorizedApp : '0x456def...' , authorizedUser : '0x789cba...' , pricePerAccess : 3 , numberOfAccess : 10 , onStatusUpdate : ({ title , isDone }) => { console . log ( title , isDone ); }, }); Parameters ​ ts import { type GrantAccessParams } from '@iexec/dataprotector' ; protectedData Required * ​ Type: Address The ethereum address of the protected data supplied by the user (returned when you created it). You must own this data to grant access. ts const grantedAccess = await dataProtectorCore . grantAccess ({ protectedData : '0x123abc...' , authorizedApp : '0x456def...' , authorizedUser : '0x789cba...' , }); authorizedApp Required * ​ Type: Address The address of the application you wish to authorize to process the protectedData within a secure execution environment. You may specify either a single application or an application whitelist. To specify a whitelist, you provide the ETH address of an iExec Whitelist Smart Contract . This smart contract should aggregates multiple application versions. This allows you to introduce new versions of your application without needing to grant access for the protectedData each time you do so. ts const grantedAccess = await dataProtectorCore . grantAccess ({ protectedData : '0x123abc...' , authorizedApp : '0x456def...' , authorizedUser : '0x789cba...' , }); TIP You may authorize a specific app or a whitelist of apps to use the protected data. The latest version of the iExec Web3Mail decentralized application is 0xe7945ddc8241A877c6e59F50a61e91eBb57AfD84 . iExec also maintains a whitelist for current and past versions of Web3Mail iApp. Granting access to this whitelist allows use of an email protectedData with all versions of the Web3Mail application, ensuring you only have to grant this access once. The ETH address for this whitelist is 0xfa9cceff9431ee0e2a3fe58911073f1357f24e31 . authorizedUser Required * ​ Type: Address The address of the user you wish to authorize to use the protectedData . Note that these users may not view or manipulate the data. This only grants permission for the user to submit the data to an iExec application. ts const grantedAccess = await dataProtectorCore . grantAccess ({ protectedData : '0x123abc...' , authorizedApp : '0x456def...' , authorizedUser : '0x789cba...' , }); TIP You may authorize all users to use the protected data by setting this to 0x0000000000000000000000000000000000000000 . pricePerAccess Optional ​ Type: number Default: 0 Specifies the usage fee in nano RLC (nRLC) associated with each access of the data. It represents the cost incurred for each individual interaction with application. By invoking the grantAccess method with a specific pricePerAccess you define the fee that the specified user ( authorizedUser parameter) must pay for each access to the data when used with the specified application ( authorizedApp parameter). The fee is paid to the owner of the protected data. ts const grantedAccess = await dataProtectorCore . grantAccess ({ protectedData : '0x123abc...' , authorizedApp : '0x456def...' , authorizedUser : '0x789cba...' , pricePerAccess : 3 , numberOfAccess : 10 , }); TIP pricePerAccess is expressed in nano RLC (nRLC). nRLC is the smallest subdivision of the RLC token, 1 RLC equals to 10^9 nRLC. When provided, pricePerAccess must be a non-negative integer value. numberOfAccess Optional ​ Type: number Default: 1 Allows restricting the number of times the protected data may be processed and used. It is not technically possible to set an unlimited number of accesses, but you can set numberOfAccess to 10000 for example. INFO If you attempt to process the protected data more times than specified in numberOfAccess , you will encounter a "no dataset orders" error. To prevent this error, ensure the numberOfAccess is properly set when calling the grantAccess method. ts const grantedAccess = await dataProtectorCore . grantAccess ({ protectedData : '0x123abc...' , authorizedApp : '0x456def...' , authorizedUser : '0x789cba...' , pricePerAccess : 3 , numberOfAccess : 10 , }); allowBulk Optional ​ Type: boolean Default: false When set to true , enables bulk processing for this access grant. This allows multiple protected data items to be processed together. When allowBulk: true is set, the price per access is automatically set to 0 and the number of accesses is unlimited. ts const grantedAccess = await dataProtectorCore . grantAccess ({ protectedData : '0x123abc...' , authorizedApp : '0x456def...' , authorizedUser : '0x789cba...' , allowBulk : true , // Enable bulk processing }); onStatusUpdate Optional ​ Type: OnStatusUpdateFn<GrantAccessStatuses> Callback function to be notified at intermediate steps. ts const grantedAccess = await dataProtectorCore . grantAccess ({ protectedData : '0x123abc...' , authorizedApp : '0x456def...' , authorizedUser : '0x789cba...' , onStatusUpdate : ({ title , isDone }) => { console . log ( title , isDone ); }, }); You can expect this callback function to be called with the following titles: ts 'CREATE_DATASET_ORDER' ; 'PUBLISH_DATASET_ORDER' ; Once with isDone: false , and then with isDone: true Return Value ​ ts import { type GrantedAccess } from '@iexec/dataprotector' ; The result of this method confirms the new access grant. It consists of a JSON grantedAccess object. GrantedAccess ## /references/dataProtector/methods/getGrantedAccess getGrantedAccess ​ This method provides a listing of all access grants given for the specified protected data object. Options for filtering include specifying an authorized user, an authorized app, or both. Usage ​ The request object is a JSON GetGrantedAccessParams object. Each address in the object is a string representation of an ethereum address. ts const listGrantedAccess = await dataProtectorCore . getGrantedAccess ({ protectedData : '0x123abc...' , authorizedApp : '0x456def...' , authorizedUser : '0x789cba...' , page : 1 , pageSize : 100 , }); Parameters ​ ts import { type GetGrantedAccessParams } from '@iexec/dataprotector' ; protectedData Optional ​ Type: Address Address of the protected data object for which you are querying access authorization grants. It's a string representation of an ethereum address. If no address is specified, it will return all granted access for any protected data. Usage example: ts const listGrantedAccess = await dataProtectorCore . getGrantedAccess ({ protectedData : '0x123abc...' , }); authorizedApp Optional ​ Type: Address Optional filter to restrict the results to include only authorizations for the specified application. It's a string representation of an ethereum address. If no address is specified, it will return all granted access for any application. Usage example: ts const listGrantedAccess = await dataProtectorCore . getGrantedAccess ({ authorizedApp : '0x456def...' , }); TIP If you specified an application whitelist when using grantAccess , you must specify that same whitelist address when using this filtering option. The getGrantedAccess method does not check against whitelist smart contracts when aggregating results. If you granted authorization to a whitelist but specify an application address for the authorizedApp parameter, you will not receive any results unless you also explicitly granted access to that application address. authorizedUser Optional ​ Type: Address Optional filter to restrict the results to include only authorizations for the specified user. It's a string representation of an ethereum address. If no address is specified, it will return all granted access for any user. Usage example: ts const listGrantedAccess = await dataProtectorCore . getGrantedAccess ({ authorizedUser : '0x789cba...' , }); isUserStrict Optional ​ Type: boolean Default: false Optional filter to restrict the results to include only authorizations for the specified user. Authorizations made for any user are not returned. ts const listGrantedAccess = await dataProtectorCore . getGrantedAccess ({ protectedData : '0x123abc...' , authorizedApp : '0x456def...' , authorizedUser : '0x789cba...' , isUserStrict : true , }); page Optional ​ Type: number Default: 0 Specifies the page number of the result set to return. Pages are zero-based indexed, with the default value being 0 , indicating the first page. If used, you can also specify the pageSize parameter to control the number of records per page. By default, when no page number is specified, the system returns the first page (page 0) containing 20 elements. Usage example: ts const listGrantedAccess = awa
프로젝트로 돌아가기