OperationService

public class OperationService

Several classes need to use pieces of the forge-sign-parse-preapply-inject flow. This class abstracts those functions away so that it can be shared throughout the library.

  • Errors that the OperationService is capable of returning

    See more

    Declaration

    Swift

    public enum OperationServiceError : Error
  • Used to return a bunch of formatted data, to make interacting with ledger sign operation easier

    See more

    Declaration

    Swift

    public struct LedgerPayloadPrepResponse

Public Properties

Init

Top level functions

Helpers / wrappers

  • Ledger can only parse operations under certain conditions. These conditions are not documented well. This function will attempt to determine whether the payload can be parsed or not, and returnt he appropriate string for the LedgerWallet sign function It seems to be able to parse the payload if it contains 1 operation, of the below types. Combining types (like Reveal + Transation) causes a parse error If the payload structure passes the conditions we are aware of, allow parsing to take place. If not, sign blake2b hash instead

    Declaration

    Swift

    public func ledgerStringToSign(forgedHash: String, operationPayload: OperationPayload) -> String
  • Preapply and Inject wrapped up as one function, for situations like Ledger Wallets, where signing is a complately different process, and must be done elsewhere

    Declaration

    Swift

    public func preapplyAndInject(forgedOperation: String, signature: [UInt8], signatureCurve: EllipticalCurve, operationPayload: OperationPayload, operationMetadata: OperationMetadata, completion: @escaping ((Result<String, KukaiError>) -> Void))

    Parameters

    forgedOperation

    The forged operation hex without a watermark.

    signature

    Binary representation of the signed operation forge.

    signatureCurve

    The curve used to sign the forge.

    operationPayload

    The payload to be sent.

    operationMetadata

    The metadata required to send the payload.

    completion

    callback with a forged hash or an error.

  • Forge an OperationPayload remotely, so it can be sent to the RPC.

    Declaration

    Swift

    public func remoteForge(operationPayload: OperationPayload, completion: @escaping ((Result<String, KukaiError>) -> Void))

    Parameters

    operationPayload

    created from OperationFactory.operationPayload().

    wallet

    The Wallet object that will sign the operations.

    completion

    callback with a forged hash or an error.

  • Parse a forged OperationPayload on a different server to ensure nobody maliciously tampared with the request.

    Declaration

    Swift

    public func remoteParse(forgeResult: Result<String, KukaiError>, operationMetadata: OperationMetadata, operationPayload: OperationPayload, completion: @escaping ((Result<String, KukaiError>) -> Void))

    Parameters

    forgeResult

    The Result object from the forge(...) function.

    operationMetadata

    fetched from getOperationMetadata(...).

    operationPayload

    the OperationPayload to compare against to ensure it matches.

    completion

    callback which just returns success or failure with an error.

  • Preapply a signed OperationPayload to check for any errors.

    Declaration

    Swift

    public func preapply(operationPayload: OperationPayload, completion: @escaping ((Result<[OperationResponse], KukaiError>) -> Void))

    Parameters

    operationMetadata

    Fetched from getOperationMetadata(...).

    operationPayload

    An OperationPayloadthat has had a signature and a protcol added to it.

    completion

    Callback which just returns success or failure with an error.

  • Inject a signed bytes to become part of the next block on the blockchain

    Declaration

    Swift

    public func inject(signedBytes: String, handlePreapplyResult: Result<[OperationResponse], KukaiError>?, completion: @escaping ((Result<String, KukaiError>) -> Void))

    Parameters

    signedBytes

    The result of the forge operation (as a string) with the signature (as a hex string) appended on.

    handlePreapplyResult

    Optionally pass in the result of the preapply function to reduce the indentation required to perform the full set of operations. Any error will be returned via the injection Result object.