WebEferen / flutter_wallet_card

Flutter Wallet Card plugin (iOS & Android)
MIT License
12 stars 23 forks source link

Generate from scratch #9

Closed Salam-pc closed 1 year ago

Salam-pc commented 1 year ago

can you pls add an example for Generate from scratch method . i'm getting false for FlutterWalletCard.addPassKit(samplefile) and don't know where is the issue

WebEferen commented 1 year ago

Steps to generate signatures/keys/certificates from scratch:

  1. Create Signer class For that you will need to have two files which can be created and exported using Apple's KeyChain or OpenSSL.
  final signer = Signer(
    wwdrPem: wwdrPem, // this is File class that represents wwdrPem key
    certificateP12: certP12, // this is File class representing .p12 key
    directory: certificates, // output directory where signer should create signature in the future
  );
  1. Generate required certificates (cert + key) For that you need to call two signer methods:
await Future.wait([
    signer.generateKey(),
     signer.generateCertificate(), // there is also a possibility to specify password key (argument)
]);
  1. Generate signature Generate signature that will sign all the generated files

Example manifest file (it is containing sha1 hashes of the files to verify integrity) https://github.com/WebEferen/flutter_wallet_card/blob/master/test/fixtures/example_passkit/manifest.json

For manifest generation you can also use Creators helper (and it's create manifest method): https://github.com/WebEferen/flutter_wallet_card/blob/0b65916ba0d22844bd6cee7ea5e0b825384b6673/lib/core/creators.dart#L21

final manifest = File(....);
await signer.generateSignature(manifest: manifest);
  1. With generated signature, instantiate Passkit class:
final outputDirectory = Directory(...);
final passkit = Passkit(directoryName: outputDirectory.path);

final generated = await passkit.generate(
          id: 'some_id',
          pkpass: pkpass, // You should also have pkpass file already generated
          directory: outputDirectory,
          signature: signaturePath, // Path to the previously generated signature
          manifest: manifestPath, // Path to the previously generated manifest
          passkitPass: passkitPath, // Path to the passkit file
        );

For reference you can follow the test suite (to see how it works under the hood):

Best, Mike.

Salam-pc commented 1 year ago

Thank you for your assistance when I had a question. Your help was greatly appreciated!